Monday, June 18, 2007

ADF Tables. Setting an alternative sort property


Suppose you have an ADF table somewhere inside a JSF page and you wish it to be sortable.
This is fine as long as you define two things.




  • The sortproperty property of the adf:column tag which has to be one of the column names of the table binding and tell the system how to change the order by clause of the underlying view.

  • The sortbale which has to be set to true or false and determines whether to allow sorting by clicking on the column header or not




So this is a perfectly good column definition for an attribute called Matnr athat corresponds to the notorious SAP material number.




<af:column sortProperty="Matnr" sortable="true"
headerText="#{bindings['PF_ForSale'].labels.Matnr}">
<af:outputText value="#{row.Matnr}"/>
</af:column>



If you now happen to have a transient attribute and you wish to sort the table based on this attribute, then you just can't do it. The way I see it, sorting means changing the order by clause and re executing the entire query. ADF complains that there is simply no attribute by that name and throws an SQLException that comes straight from the JDBC driver.



My suggestion for a workaround that works most of the times is this : Since 90% pf transient attributes usually serve as simple lexical transformations of real database attributes, changing the sortProperty of the adf:column tag to the value of the real column might solve the problem



Let's suppose that the ViewObject of the previous example has a transient attribute called DisplayMatnr that simply removes the leading zeros of the SAP oriented material number stored in column Matnr. It goes without saying that if Matnr is sorted then so is DisplayMatnr. Therefore writing something like ...



<af:column sortProperty="Matnr" sortable="true"
headerText="#{bindings['PF_ForSale'].labels.DisplayMatnr}">
<af:outputText value="#{row.DisplayMatnr}"/>
</af:column>


... might bring the desired effect. There is one last warning though the attribute that you wish to sort by must be a part of the table definition in the bindings page

0 comments:

Post a Comment