You can't set preserveDataModel to "true" in t:dataList component in order for this method to work.
Cosma
2006/5/17, Cosma Colanicchia <
[EMAIL PROTECTED]>:
I reply to myself. I've tried to implement the suggested solution, but doesn't work.. please help me figure out what's wrong.
I have a jsp page with a t:dataList, which loads a DataModel from a backing bean and that need to display an "Edit" link:
<t:dataTable id="peopleList" var="person" value="#{peopleListBacker.list}" rows="8" preserveDataModel="true">
<t:column>
<f:facet name="header">
<h:outputText value="Surname" />
</f:facet>
<h:outputText value="#{person.surname}" />
</t:column>
<t:column>
<f:facet name="header">
<h:outputText value="Actions"/>
</f:facet>
<h:commandLink action="" value="Edit"/>
</t:column>
</t:dataTable>
peopleListBacker is a session-scoped managed bean with a getList() method, which returns a custom DataModel subclass. peopleListAction is a request-scoped managed bean with an editPerson method, implemented like this:
public String editPerson() {
DynaBean person = (DynaBean) peopleListBackerBean.getList().getRowData();
System.out.println(person.get("surname") + ": " + person.get("personId"));
return "success";
}
peopleListBacker class also exposes a setter method for a peopleListBackerBean attribute, and a managed property is declared as this:
<managed-bean>
<managed-bean-name>peopleListAction</managed-bean-name>
<managed-bean-class>com.websiteitalia.jsftest.view.controllers.people.list.PeopleListAction</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>peopleListBackerBean</property-name>
<value>#{peopleListBacker}</value>
</managed-property>
</managed-bean>
So I have access to the peopleListBacker instance in my editPerson method simply using the peopleListBackerBean instance field.
Now, when I click any "Edit" link on my page, the name and identifier of last person of the current page are always printed. Probably because this is the last row for which setRowIndex() has been called..
I must be missing something, how could this work as explained in the wiki entry? Pls help.
Cosma
2006/5/17, Cosma Colanicchia < [EMAIL PROTECTED] >:
> I am looking with interest at the wiki entry [1].
>
> The third solution explained suggests that, when using a dataList with
> a DataModel source, you can simply put a commandLink, for example an
> "Edit" one, without have to worry about passing in some way the
> identifier of that row. It is not very clear to me how can this work.
>
> Having just writed a custom DataModel for paging on a large table, I
> understood that the setRowIndex and getRowData methods are repeatedly
> invoked as needed before the rendering of the table output. Anyone can
> explain me how can a call to getRowData() in the action handler for
> the "Edit" commandLink find the clicked row in the current DataModel
> rowIndex? Who is going to set it?
>
> Thanks in advance
> Cosma
>
>
> [1] http://wiki.apache.org/myfaces/ExecutingMethodsFromLinkButtonParameters
>

