My recommendation would be to use action instead of action +
actionListener. I'm not sure -- is it even legal to be calling both?
Why would you want to?
I'd also recommend that you create both an editable and save button
rather than reusing the same button for both.
<h:commandLink action="setEditable" id="edit" rendered="#{not
user.editable}">
<h:graphicImage value="/graphics/edit.png" alt="edit" style="border:0"/>
</h:commandLink>
<h:commandLink action="save" id="save" rendered="#{user.saveable}">
<h:graphicImage value="/graphics/save.png" alt="edit" style="border:0"/>
</h:commandLink>
Note that, in any case, the value of "#{not user.editable}" and
"#{user.saveable}" should remain constant between requests (maybe
that's why you chose to use a single button, but that seems like a
hack to me). Ie, the value can't change between the time the button
is rendered and the next response when the button action is executed
on click.
On 1/27/06, Boeckli, Dominique <[EMAIL PROTECTED]> wrote:
>
>
> Hi all,
>
> I have a datatable with a edit column which contains a delete and a
> edit button. The delete button works fine (when pressed the row is
> deleted). When the edit button is pressed all items in this row gets
> editable. Works perfect as well. The edit button is replaced by a save
> button. Now i can edit something in the row. When i finished editing
> the save button can be pressed to save the new values, but they get
> lost and the old value are displayed again (the actionlistener method
> was called, but in tracing i saw the the actionlistener gets the old
> value as well instead of the old value. So in fact the old value is
> Saved).
>
> Following the code:
>
> <t:dataTable id="users"
> value="#{userListBean.users}"
> var="user"
> border="0"
> cellspacing="1"
> cellpadding= "10"
> sortColumn="#{userListBean.sort}"
> sortAscending="#{userListBean.ascending}"
> preserveDataModel="true"
> preserveSort="true"
> renderedIfEmpty="false"
> styleClass="users"
> headerClass="usersHeader"
> rowClasses="evenRow,oddRow">
>
> <t:column>
> <f:facet name="header">
> <h:outputText value="Select"/>
> </f:facet>
> <t:selectBooleanCheckbox id="select"
> value="#{user.selected}"
>
> valueChangeListener="#{userListBean.setSelected}"/>
> </t:column>
>
> <t:column>
> <f:facet name="header" >
> <t:commandSortHeader columnName="userid" arrow="true"
> styleClass="usersHeader">
> <t:outputText value="userid"/>
> </t:commandSortHeader>
> </f:facet>
> <t:outputText value="#{user.userid}"/>
> </t:column>
>
> <t:column>
> <f:facet name="header">
> <t:commandSortHeader columnName="firstname" arrow="true"
> styleClass="usersHeader">
> <h:outputText value="Firstname"/>
> </t:commandSortHeader>
> </f:facet>
> <t:outputText value="#{user.firstname}" rendered="#{not
> user.editable}"/>
> <t:inputText value="#{user.firstname}" rendered="#{user.editable}"/>
> </t:column>
>
> <t:column>
> <f:facet name="header">
> <t:commandSortHeader columnName="lastname" arrow="true"
> styleClass="usersHeader">
> <t:outputText value="Lastname"/>
> </t:commandSortHeader>
> </f:facet>
> <t:outputText value="#{user.lastname}" rendered="#{not user.editable}"/>
> <t:inputText value="#{user.lastname}" rendered="#{user.editable}"
> required="true" />
> </t:column>
>
> <t:column>
> <f:facet name="header">
> <t:commandSortHeader columnName="password" arrow="true"
> styleClass="usersHeader">
> <t:outputText value="Password"/>
> </t:commandSortHeader>
> </f:facet>
> <t:outputText value="#{user.password}" rendered="#{not user.editable}"/>
> <t:inputText value="#{user.password}" rendered="#{user.editable}"/>
> </t:column>
>
> <t:column>
> <f:facet name="header">
> <t:commandSortHeader columnName="contact" arrow="true"
> styleClass="usersHeader">
> <t:outputText value="Contact"/>
> </t:commandSortHeader>
> </f:facet>
> <t:outputText value="#{user.contact}" rendered="#{not user.editable}"/>
> <t:inputText value="#{user.contact}" rendered="#{user.editable}"/>
> </t:column>
>
> <t:column>
> <f:facet name="header">
> <t:outputText value="Roles"/>
> </f:facet>
> <t:dataTable id="roles"
> value="#{user.roles}"
> var="roles"
> border="0">
> <t:column>
> <t:outputText value="#{roles.role}"/>
> </t:column>
> </t:dataTable>
> </t:column>
>
> <t:column>
> <f:facet name="header">
> <t:outputText value=""/>
> </f:facet>
> <h:commandLink action="delete" id="delete"
> actionListener="#{userListBean.deleteUserFromDB}">
> <h:graphicImage value="/graphics/delete.png" alt="delete"
> style="border:0"/>
> </h:commandLink>
> <f:verbatim><br /></f:verbatim>
> <h:commandLink action="setEditable" id="edit"
> actionListener="#{userListBean.setEditable}">
> <h:graphicImage value="/graphics/edit.png" alt="edit" style="border:0"
> rendered="#{not user.editable}"/>
> <h:graphicImage value="/graphics/save.png" alt="edit" style="border:0"
> rendered="#{user.editable}"/>
> </h:commandLink>
> </t:column>
> </t:dataTable>
>
> Many thanks for your help
>
> Kind regards
>
> Dominique