2013-10-16 4 views
1

저는 JSP에 익숙하지 않고 내보내기 기능을위한 표시 태그에 관심이 있습니다. 말, 나는이 간단한 구조를 가지고 :jsp의 표시 태그로 객체 목록 반복하기

public class MyActionBean implements ActionBean{ 
     List<Country> countries; 
     // getters and setters and some other un-related logic 
} 


public class Country { 
    List<String> countryName; 
    List<Accounts> accounts; 
    // getters and setters and some other un-related logic 
} 


public class Accounts { 
    private FinancialEntity entity; 
    // getters and setters and some other un-related logic 
} 

public class FinancialEntity { 
    String entityName; 
    // getters and setters and some other un-related logic 
} 

지금, 나는 두 개의 열이있을 것이다 테이블을 만들고 싶어 - 국가 이름과 엔티티 이름 (FinancialEntity)

 <display:table id="row" name="${myActionBean.countries}" class="dataTable" pagesize="30" sort="list" defaultsort="8" export="true" requestURI=""> 
     <display:column title="Country" sortable="true" group="1" property="countryName" /> 
     <display:column title="Financial Entity"> somehow get all of the entity names associated with the country? </display:column> 
    </display:table> 

그래서를, 기본적으로 내가 원하는 계정을 반복하고 모든 금융 기관을 확보하십시오. displaytag를 사용하여 JSP에서이를 수행하는 방법을 알지 못합니다. c : forEach 및 display : setProperty 태그를 사용하려고했지만이 태그가 이러한 용도로 사용되지 않는 것 같습니다. 나는 치명적인 붙어 :(

사전 : 당신은 JSP에서 작업을 할 필요가 없습니다

답변

1

에 감사드립니다. 모델 객체와 컨트롤러에서이 작업을 수행 할 수 있습니다.

public class CountryFinancialEntity { 
    private Country country; 
    public CountryFinancialEntity(Country country) { 
     this.country = country; 
    } 
    public String getCountryName() { 
     return this.country.getName(); 
    } 
    public List<String> getFinancialEntityNames() { 
     List<String> financialEntityNames = new ArrayList<String> 
     for (Account account : this.country.getAccounts() { 
      financialEntityNames.add(account.getFinancialEntity().getName(); 
     } 
    } 
} 

모든 국가의 개체 목록을 만들고이 개체를보기 (jsp)에 전달하십시오.

이 태그를 사용하면 표시 태그를 단순화하고 c : forEach 태그를 사용할 수 있습니다.

편집

당신이 JSP에서이 작업을 수행해야합니다.

국가 목록을 전달하는 것이 좋습니다. MyActionBean은 실제로 도움이되지 않으며 혼동을 일으킬 수 있습니다.

귀하의 JSP처럼 보일 것이다 다음

<display:table id="country" name="countries"> 
    <display:column title="Country Name" property="name" /> 
    <display:column title="Financial Name" > 
     <ul> 
     <c:forEach var="account" items="${country.accounts}"> 
      <li>${account.financialEntity.name}</> 
     <c:forEach> 
     </ul> 
    </display:column> 
</display:table> 

BTW, 이것은 CountryFinancialEntity뿐만 아니라 오는 그것을 생각하는 어떻게 보일지 가능성이 높습니다,하지만 당신은 다른 열이 거라면 CountryFinancialEntity 객체와 같은 것을 사용하지만 대신 TableRowModel을 호출합니다.

+0

안녕하세요. 회신 해 주셔서 대단히 감사합니다. 그러나 이것은 작동하지 않습니다. 이유는, 여러 개의 열이있을 것입니다 (두 개만 언급했지만 그 이상이 있습니다). 그리고 JSP를 통해이를 수행해야합니다. – user1039063