how can i sort teh computed column value in data table
thiagu.m Aug 25, 2008 9:35 AMHai everyone,
In a page with details for many products, I display the product name with its price information by using the data Table components.
The columns used for the details of any product are sortable by design. Then I have one more dynamic column “EMIâ€Â� – Equated Monthly Installment. It is not from entity bean but it is computed in session bean and by default the EMI is for 1 year.
In this page the user can also select payment period by using a drop down and when the EMI period is changed like this, I compute the new EMI value and then display it in the data table.
And by design, EMI column should also be sortable. I wish to know if this is possible through any Richface component.
This is my sample xhtml code:
<h:selectOneMenu value="#{store.emiPerid}" >
<f:selectItems value="#{emiPeridItems}"/>
<a4j:support event="onchange" actionListener="#{store.updateEmi}" />
</h:selectOneMenu >
<rich:dataTable value="#{StoreList}" var="cap" >
<rich:column sortBy="#{cap.productName}">
<f:facet name="header">
<h:outputText value="Product Name"/>
</f:facet>
<h:outputText value="#{cap.productName }"/>
</rich:column>
<rich:column sortBy="#{cap.price}">
<f:facet name="header">
<h:outputText value="Price"/>
</f:facet>
<h:outputText value="#{cap.price}"/>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="EMI"/>
</f:facet>
<h:outputText value="#{StoreEmiMap[cap]}"/>
</rich:column>
</rich:dataTable>
This is my session bean code
@Name("store")
public class StoreAction implements Store, Serializable
{
@Out(required=false)
List<TblStore> StoreList;
double emiPerid;
@Out(required=false)
List<SelectItem> emiPeridItems
@Out(required=false)
Map<TblStore, double> StoreEmiMap;
@Begin(join=true)
public String beginAction() {
emiPeridItems=new List<SelectItem>();
for(int 1=1;i<10;i++)
emiPeridItems.add(new SelectItem(i+"Years",i));
StoreList= =em.createQuery("select t from TblStore t ").getResultList();
StoreEmiMap =new HashMap<TblStore, double>();
For(TblStore a: StoreList)
StoreEmiMap.put(a, emi for one year by default);
}
public void updateEmi(ActionEvent event)
{
//Compute the new EMI.
//Update the computed new EMI values to the HashMap
}
}
If the EMI is brought from the entity bean then there is no issue and the column can also be sorted.
But it is a computed value. So I wish to know how it can be made sortable.
Any one can help me out on this, Please?
by
Thiagu.m