Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem using rendered attribute in Command Button

 
Nitin Tonk
Greenhorn
Posts: 14
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using rendered attribute to hide a command button

<t:commandButton styleClass="btn" id="createGrp"
immediate="true"
action="createGroup2"
value="Create Group"
rendered="#{folderBean.canManageGroups}">
</t:commandButton>


Rendering does works fine in this case.
But when the command button is clicked.it goes back to the root page.
Help...!!!
 
Bhaskar GR
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remove immediate attribute,can ypu send me jsp page i will check
 
Nitin Tonk
Greenhorn
Posts: 14
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already tried by removing the immediate attribute.
But it doesnt works.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Nitin,

You need to have a look at your action attribute. It should be an EL expression, that should point to some method on your managed bean. It it returns nothing or null, you will be redirected back to the page the call came from.

If you have a navigation case defined in your faces config xml file, and this method returns a String that matches this navigation case, then you will be redirected to the page defined in your navigation case.
 
Nitin Tonk
Greenhorn
Posts: 14
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Darryl,

I have used this code in my JSP.
createGroup2 is under the navigation rule in faces-config

<t:commandButton styleClass="btn" id="createGrp"
action="createGroup2" value="Create Group"
rendered="#{folderBean.canManageGroups}" >
<t:updateActionListener property="#{group.folderId}" value="#{folderBean.folderFullPath}"/>
</t:commandButton>

The problem is that i do get the value of rendered as "true" but the action is not called.
[ June 27, 2008: Message edited by: Nitin Tonk ]
 
Venkat Sadasivam
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
During the restore view your managed bean might return false for the EL expression "#{folderBean.canManageGroups}", so JSF cannot create <h:commandButton> component and bind the action.

Instead of rendered attribute you can use <c:if>.

For example:
<c:if test="#{folderBean.canManageGroups}">
<h:commandButton .../>
</c:if>
 
Christopher Watts
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just came across the same problem. I personally reckon its a bug in the spec and/or implementation as it should decode all components that were displayed originally not ones based on the state of the model at the decode phase time.

My solution was to use Tomahawk's saveState. It restores the previous value to the model so you can use it in the rendered attribute. I've got more detail here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic