You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Chan, Jim" <jc...@incognito.com> on 2005/08/24 23:52:45 UTC

[JSF] / [Shale] - Buttons dont work if rendered attribute is use d

I have two buttons for create and update and they are shown depending on
whether the userBean is new or not.  The function userBean.isNew() depends
on whether the id is empty.  UserBean is in request scope.  Here is the JSF
code snippet.

<h:inputHidden value="#{userBean.id}" id="userBeanId" />
<h:commandButton value="Update" action="#{userBean.update}" rendered="#{!
userBean.new}"/>
<h:commandButton value="Create" action="#{userBean.create}"
rendered="#{userBean.new}"/>

The buttons are rendered properly, but when I click on update, the
corresponding bean action is not invoked.  It seems that when the page is
submitted the JSF framework does (but not limited to) the following steps:

1. create new UserBean()
2. call userBean.isNew() - returns false because id has not been set yet
3. call userBean.setId(userBeanId)

Becuse isNew is called before the ID is set, it always returns false.
Consequently, the JSF framework does not call userBean.update().  When I
remove the rendered attrubutes from the commandButton, everything works
fine, but obviously this is not acceptable, I want hide certain buttons
depending on the bean state.  I do not want to use standard tags as a
workaround for obvious reasons.

Can anyone explain what I am doing wrong?  I assume that if the button is
rendered, then its action should be invoked.