You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by gr...@intellicare.com on 2005/10/18 22:34:13 UTC

Problem with
I just started working with myFaces (and tomahawk) for the past couple of 
days and so I apologize if this question is really basic.

Here's what I have:

A (Shale) backing bean called "worklist" with:
private DataModel assignmentsModel = new ListDataModel();
..etc..
private List _assignments;
..etc..
public String getWorkList() {
        //do some work to populate_assignments ..then..
        assignmentsModel.setWrappedData(_assignments);
}
finally,
public DataModel getAssignments() {
        return assignmentsModel;
}

I display my worklist in worklist.jsp and everything works great.

Now I want to introduce sorting into my table and therefore looked into <
t:commandSortHeader  working within a <t:dataTable. I think I'm supposed 
to have something like this in my worklist.jsp:

<t:dataTable id="items" value="#{worklist.assignments}"
                var="assignment" sortColumn="#{worklist.sort}"
                sortAscending="#{worklist.ascending}" preserveDataModel=
"true"
                preserveSort="true">

                <h:column>
                        <f:facet name="header">
                                <t:commandSortHeader columnName="name" 
arrow="true">
                                        <h:outputText value="Assignment" 
/>
                                </t:commandSortHeader>
                        </f:facet>
etc..

So I added methods getSort(), isAscending(), sort (final String column, 
final boolean ascending) etc. to my worklist backingbean (using sample 
code from MyFaces' "listexample" as a guide). My worklist.jsp page does 
display with the little arrow but clicking on it returns me to the same 
page (though the arrow faces the opposite way upon click - yeah!!), 
however, no sorting happens, which is no major surprise since my bean's 
sorting method isn't even hit..(:(

So my questions are:
0. Is my approach all wrong and should Ibe doing everything differently?
1. Does anybody see what i'm doing wrong?
2. Where should I add breakpoints to see what I'm messing up? (My code 
doesn't even hit the sort method in my backing bean.)

Thanks very much in advance!
Geeta

Re: Problem with Posted by "paul.tran" <Pa...@emergis.com>.
Hi, 

I have the same problem here. Can you give me more details on the java code
you made to do the sort?

Thanks!


GRamani wrote:
> 
> Simon Kitching <sk...@obsidium.com> wrote on 10/18/2005 05:25:13 PM:
> 
>> 
>> The "sortColumn" attribute should point to a backing bean property that 
>> is of type String. That property gets set (ie its setter gets called) 
>> with the columnName value of whatever column the user chose to sort on.
>> 
>> The "sortAscending" attribute should point to a backing bean property 
>> that is of type boolean. That property gets set to true/false when the 
>> user clicks repeatedly on the same column header (ie sorts 
>> asc/desc/asc/desc).
>> 
>> Your worklist.assignments method (ie the one referred to by the table's 
>> "value" attribute) is then required to look at the backing bean's 
>> properties that are the target of sortColumn and sortAscending and 
>> return its list in the order specified by those (String, boolean) 
>> properties.
>> 
>> I hope that's the info you were looking for.
> 
> Thanks very much, Simon! This is exactly the information I was looking for 
> - my sorting works now..:)
> 
>> 
>> Regards,
>> 
>> Simon
>> 
> 
> Geeta
> 
> 

-- 
View this message in context: http://www.nabble.com/Problem-with-%3Ct%3AcommandSortHeader-within-%3Ct%3AdataTable-tf421743.html#a7621552
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Problem with Posted by gr...@intellicare.com.
Simon Kitching <sk...@obsidium.com> wrote on 10/18/2005 05:25:13 PM:

> 
> The "sortColumn" attribute should point to a backing bean property that 
> is of type String. That property gets set (ie its setter gets called) 
> with the columnName value of whatever column the user chose to sort on.
> 
> The "sortAscending" attribute should point to a backing bean property 
> that is of type boolean. That property gets set to true/false when the 
> user clicks repeatedly on the same column header (ie sorts 
> asc/desc/asc/desc).
> 
> Your worklist.assignments method (ie the one referred to by the table's 
> "value" attribute) is then required to look at the backing bean's 
> properties that are the target of sortColumn and sortAscending and 
> return its list in the order specified by those (String, boolean) 
> properties.
> 
> I hope that's the info you were looking for.

Thanks very much, Simon! This is exactly the information I was looking for 
- my sorting works now..:)

> 
> Regards,
> 
> Simon
> 

Geeta

Re: Problem with Posted by Simon Kitching <sk...@obsidium.com>.
gramani@intellicare.com wrote:
> 
> I just started working with myFaces (and tomahawk) for the past couple 
> of days and so I apologize if this question is really basic.
> 
> Here's what I have:
> 
> A (Shale) backing bean called "worklist" with:
> private DataModel assignmentsModel = new ListDataModel();
> ..etc..
> private List _assignments;
> ..etc..
> public String getWorkList() {
>         //do some work to populate_assignments ..then..
>         assignmentsModel.setWrappedData(_assignments);
> }
> finally,
> public DataModel getAssignments() {
>         return assignmentsModel;
> }
> 
> I display my worklist in worklist.jsp and everything works great.
> 
> Now I want to introduce sorting into my table and therefore looked into 
> <t:commandSortHeader  working within a <t:dataTable. I think I'm 
> supposed to have something like this in my worklist.jsp:
> 
> <t:dataTable id="items" value="#{worklist.assignments}"
>                 var="assignment" sortColumn="#{worklist.sort}"
>                 sortAscending="#{worklist.ascending}" 
> preserveDataModel="true"
>                 preserveSort="true">
> 
>                 <h:column>
>                         <f:facet name="header">
>                                 <t:commandSortHeader columnName="name" 
> arrow="true">
>                                         <h:outputText value="Assignment" />
>                                 </t:commandSortHeader>
>                         </f:facet>
> etc..
> 
> So I added methods getSort(), isAscending(), sort (final String column, 
> final boolean ascending) etc. to my worklist backingbean (using sample 
> code from MyFaces' "listexample" as a guide). My worklist.jsp page does 
> display with the little arrow but clicking on it returns me to the same 
> page (though the arrow faces the opposite way upon click - yeah!!), 
> however, no sorting happens, which is no major surprise since my bean's 
> sorting method isn't even hit..(:(
> 
> So my questions are:
> 0. Is my approach all wrong and should Ibe doing everything differently?
> 1. Does anybody see what i'm doing wrong?
> 2. Where should I add breakpoints to see what I'm messing up? (My code 
> doesn't even hit the sort method in my backing bean.)

The "sortColumn" attribute should point to a backing bean property that 
is of type String. That property gets set (ie its setter gets called) 
with the columnName value of whatever column the user chose to sort on.

The "sortAscending" attribute should point to a backing bean property 
that is of type boolean. That property gets set to true/false when the 
user clicks repeatedly on the same column header (ie sorts 
asc/desc/asc/desc).

Your worklist.assignments method (ie the one referred to by the table's 
"value" attribute) is then required to look at the backing bean's 
properties that are the target of sortColumn and sortAscending and 
return its list in the order specified by those (String, boolean) 
properties.

I hope that's the info you were looking for.

Regards,

Simon