Seam과 Java를 사용하여 객체로 채워진 ArrayList의 정보가 들어있는 h : dataTable을 만들고 있습니다. 내 질문은, 거기에 헤더 중 하나를 클릭하여 테이블을 정렬 할 수있는 방법입니다. 나는 지금 당장 코드를 가지고 있으며, 테이블과 동일한 방식으로 테이블을 다시로드합니다.Sorting h : dataTable
내 코드는 다음과 같습니다. 당신이 더 필요하면 알려주세요 : 테이블 :
<h:dataTable value="#{deliveryPort.getWholeDeliveryList()}" var="delivery" rules="rows">
<h:column>
<div class="setWidth">
<div class="white">
<f:facet name="header">
<h:outputLink style="color:#FFFFFF" action="#{deliveryPort.sortByAddress()}">
Address
</h:outputLink>
</f:facet>
</div>
<h:outputText value="#{delivery.address}" />
</div>
</h:column>
정렬 :
public String sortByAddress(){
for(int i = 0; i < wholeDeliveryList.size(); i++){
for(int j= i+1; j<wholeDeliveryList.size(); j++){
if(wholeDeliveryList.get(i).getAddress().compareTo(wholeDeliveryList.get(j).getAddress())<1){
FlowerStoreDelivery temp = wholeDeliveryList.get(i);
wholeDeliveryList.set(i, wholeDeliveryList.get(j));
wholeDeliveryList.set(j, temp);
}
}
}
return "deliveryList.seam";
}
getWholeDeliveryList() :
예 부자public List<FlowerStoreDelivery> getWholeDeliveryList(){
wholeDeliveryList = new ArrayList<FlowerStoreDelivery>();
wholeDeliveryList.addAll(entityManager.createQuery("SELECT e FROM FlowerStoreDelivery e").getResultList());
return wholeDeliveryList;
}