voyent
get sort and filter from an ace:DataTable with dynamic columns  XML
Forum Index -> Components
Author Message
lvqnm

Joined: 04/Dec/2009 00:00:00
Messages: 22
Offline


Hi,
I have an ace:dataTable with dynamic columns (not predefined) and lazy loading. In the method LazyDataModel.load() i need to get the columns sorted and filtered but i can't get it from SortCriteria and filters parameters because the expressions dataTable.sortBy and dataTable.filterBy are not evaluated. For example, if dataTable.sortBy=#{fieldBean.columnName} then i get "columnName" instead of "ID", "NAME" or whatever.

I can achieve this if ....

I add the following ace events in the dataTable...
Code:
<ace:ajax event="sort" execute="@this" render="@this" listener="#{testPortalViewAction.sortListener}"/>
 <ace:ajax event="filter" execute="@this" render="@this" listener="#{testPortalViewAction.filterListener}"/>
 


... and the following methods in te bean..
Code:
public void filterListener(AjaxBehaviorEvent event){
 	debug("filterListener::");
 	DataTable dt = (DataTable) event.getComponent();
 		
         for (Column column : dt.getColumns()) {
             if (!UtilidadesString.isEmpty(column.getFilterValue())) {
         		debug("filterListener::field=" + column.getId() + ", filter=" + column.getFilterValue());
             }
         }
 }
 
 public void sortListener(AjaxBehaviorEvent event) {
 		FacesContext context = FacesContext.getCurrentInstance();
 		DataTable dt = (DataTable) event.getComponent();
 		
         Map<String,String> params = context.getExternalContext().getRequestParameterMap();
         String clientId = dt.getClientId(context);
         String sortDir = params.get(clientId + "_sortDirs");
         String orden = "DESC";
         if("true".equalsIgnoreCase(sortDir)){
         	orden = "ASC";
         }
         String sortKey = params.get(clientId + "_sortKeys");
         Column sortColumn = null;
         for (Column column : dt.getColumns()) {
             if (column.getClientId(context).equals(sortKey)) {
                 sortColumn = column;
                 break;
             }
         }
         if(sortColumn != null){
     		debug("sortListener::field=" + sortColumn.getId() + ", order=" + orden);
         	
         }
 }
 


I think maybe is a more easy and standard way to do this (accessing to the SortState of the dataTable, etc) but i have read the documentation and i did not find the way.

Please. could anyone help me with this?

Thanks.

arran.mccullough


Joined: 02/Jan/2007 00:00:00
Messages: 426
Offline


Hello,

Are you looking to have sorted and filtered data returned when loading the LazyDataModel?

If so, can you post the code you have for the load method? It should be possible to send in the sorting and filtering values in this method.

Regards,
Arran

Arran McCullough
Technical Support Engineer
ICEsoft Technologies Inc.
lvqnm

Joined: 04/Dec/2009 00:00:00
Messages: 22
Offline


Hi Arran, thank you for your response.

The xhtml is the following

Code:
<ace:dataTable id="tickets" value="#{testPortalManagedBean.incidentLazyModel}" var="incident" paginator="true" rows="5" paginatorPosition="bottom" rowsPerPageTemplate="5,10,15,20" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" lazy="true" filterEvent="enter">
        <ace:ajax event="sort" execute="@this" render="@this" listener="#{testPortalViewAction.sortListener}"/>
        <ace:ajax event="filter" execute="@this" render="@this" listener="#{testPortalViewAction.filterListener}"/>
        <c:forEach items="#{testPortalManagedBean.columns}" var="fb">
               <ace:column id="#{fb.fieldName}" headerText="#{fb.translate}" sortBy="#{fb.fieldName}" filterBy="#{fb.fieldName}" filterMatchMode="contains">
                      <h:outputText value="#{incident.campos[fb.fieldName].txtValue}"/>
               </ace:column>
        </c:forEach>
        .....


The sortBy attribute of my columns are sortBy="#{fb.fieldName}". fb.fieldName contains the name of the column in the database: ID, STAUS, CREATION_DATE... or whatever.

The load code in LazyDataModel is the following:

Code:
@Override
 public List<TestIncidentBean> load(int first, int pageSize, SortCriteria[] criteria, Map<String, String> filters) {
 	log.debug("load::");
 	if(criteria.length > 0){
 		SortCriteria cr = criteria[0];
 		log.debug("load::Criteria property name=" + cr.getPropertyName());
 	}
 ...
 


And the result is:

DEBUG TestLazyIncidentListBean:52 - load::Criteria property name=fieldName

My problem is the SortCriteria.getPropertyName() method is returning "fieldName" instead of "ID", "STAUS", "CREATION_DATE". So i can´t know by which column i have to order.

I hope I explained well. I need to identify the sortedBy column.

Any help would be appreciated.

Thanks.
lvqnm

Joined: 04/Dec/2009 00:00:00
Messages: 22
Offline


Any suggestions, please?
artzambrano

Joined: 21/Mar/2007 00:00:00
Messages: 175
Offline


I think you could use sortCriteria.getExpression() and evaluate it to get the field name. This is supposed to happen automatically when creating the SortCriteria object, and the result is stored in propertyName, but if this isn't working for you, maybe there's an issue in your environment evaluating EL expressions. So, just try to get the expression object and evaluate it yourself to see if you can get the actual property name.

Art Zambrano
ICEsoft Technologies Inc.
lvqnm

Joined: 04/Dec/2009 00:00:00
Messages: 22
Offline


Hi artzambrano, thank you for your response. I tried your suggestion without success.

I wrote this code...

Code:
SortCriteria cr = criteria[0];
 log.debug("load::Criteria property name=" + cr.getPropertyName());
 log.debug("load::Criteria expression=" + cr.getExpression().getExpressionString());
 FacesContext facesContext = FacesContext.getCurrentInstance();
 Object value = facesContext.getApplication().evaluateExpressionGet(facesContext, cr.getExpression().getExpressionString(), Object.class);
 log.debug("load::Criteria value=" + value);
 


... and get this output

Code:
load::Criteria property name=fieldName
 load::Criteria expression=#{fb.fieldName}
 load::Criteria value=null
 


So i can´t get the fieldName which is sortering. I don't know if i'm getting the value expression properly.

philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


The problem is that the Ace DataTable simply doesn't support immediate JSTL expressions in the sort or filter code, as that code evaluates the current ValueExpression at a later stage than the immediate <c:forEach> evaluation when the page is first processed. This will only work if you use a deferred JSF expression, which evaluates an existing JSF bean or var variable.

If you like, you can create an enhancement request in our issue tracker for the DataTable to attempt to use Java class introspection to derive the property names instead of using deferred ValueExpressions.

Thanks,
Philip

.
 
Forum Index -> Components
Go to:   
Powered by JForum 2.1.7ice © JForum Team