There's also a very similar approach here:
http://www-128.ibm.com/developerworks/library/j-jsf2/#IDABXDXG
Enrique Medina.
On 4/13/05, Aaron Bartell <[EMAIL PROTECTED]> wrote:
> Here is what I have done. Basically there is a method for each column that
> sets some class variables so when the call to get the list is made those
> variables are passed into my DAO's (Data Access Objects).
>
> HTH,
> Aaron Bartell
>
> <x:dataTable id="data"
> styleClass="table" headerClass="table_header"
> var="user" value="#{UserCtl.userList}"
> preserveDataModel="true" rows="10">
> <h:column>
> <f:facet name="header">
> <h:commandLink action="#{UserCtl.orderByName}">
> <h:outputText id="orderbyname" value="User Id"/>
> </h:commandLink>
> </f:facet>
> <h:outputText value="#{user.name}" styleClass="copy"/>
> </h:column>
> <h:column>
> <f:facet name="header">
> <h:commandLink action="#{UserCtl.orderByFirstName}">
> <h:outputText id="orderbyfirstname" value="First
> Name"/>
> </h:commandLink>
> </f:facet>
> <h:outputText value="#{user.firstname}" styleClass="copy"/>
>
> </h:column>
> <h:column>
> <f:facet name="header">
> <h:commandLink action="#{UserCtl.orderByLastName}">
> <h:outputText id="orderbylastname" value="Last
> Name"/>
> </h:commandLink>
> </f:facet>
> <h:outputText value="#{user.lastname}" styleClass="copy"/>
>
> </h:column>
> <h:column>
> <f:facet name="header">
> <h:commandLink action="#{UserCtl.orderByEmail}">
> <h:outputText id="orderbyemail" value="Email"/>
> </h:commandLink>
> </f:facet>
> <h:outputText value="#{user.email}" styleClass="copy"/>
> </h:column>
>
> <h:column>
> <f:facet name="header">
> <h:outputText value="Action"/>
> </f:facet>
> <h:commandLink id="edit" action="#{UserCtl.updateUserPage}"
> value="edit" styleClass="copy"/>
> <h:outputText value=" | " styleClass="copy"/>
> <h:commandLink id="delete"
> action="#{UserCtl.deleteUserPage}" value="delete" styleClass="copy"/>
> </h:column>
> </x:dataTable>
>
> public class UserController {
>
> User curUsr;
> String orderBy = "created";
> String orderDirection = Const.DESC;
>
> public UserController() {
>
> }
> public List getUserList() throws HibernateException {
> return User.getList(orderBy, orderDirection);
> }
>
> public String orderByStatus() {
> this.orderBy = "status";
> this.orderDirection = this.orderDirection.equals(Const.ASC) ?
> Const.DESC : Const.ASC;
> return null;
> }
>
> public String orderByName() {
> this.orderBy = "name";
> this.orderDirection = this.orderDirection.equals(Const.ASC) ?
> Const.DESC : Const.ASC;
> return null;
> }
>
> public String orderByCreated() {
> this.orderBy = "created";
> this.orderDirection = this.orderDirection.equals(Const.ASC) ?
> Const.DESC : Const.ASC;
> return null;
> }
>
> public String orderByFirstName() {
> this.orderBy = "firstname";
> this.orderDirection = this.orderDirection.equals(Const.ASC) ?
> Const.DESC : Const.ASC;
> return null;
> }
>
> public String orderByLastName() {
> this.orderBy = "lastname";
> this.orderDirection = this.orderDirection.equals(Const.ASC) ?
> Const.DESC : Const.ASC;
> return null;
> }
>
> public String orderByEmail() {
> this.orderBy = "email";
> this.orderDirection = this.orderDirection.equals(Const.ASC) ?
> Const.DESC : Const.ASC;
> return null;
> }
> }
>
> -----Original Message-----
> From: Mark and Mary Beth [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, April 12, 2005 9:10 PM
> To: [email protected]
> Subject: question about dataModel
>
> I have a Sybase database table that I pulling data from and displaying
> in a JSF dataTable.
> The data is being returned as a JSF ResultDataModel. I would like to
> make each column
> sortable. I believe the best way would be to click on a column header,
> and the method called
> will pass the right parameter(s) to the calling stored procedure. The
> problem I am having is implementing
> this idea. Does myfaces have a component already written that I can
> plug in to my webapp? If not, is
> there an example anywhere? I have seen examples of datatables being
> created from Lists and Arrays,
> but none with Results.
>
> Mark W.
>
>