Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem after rendering a commandButton

 
varun prakash
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
I'm facing a strange problem in jsf.
First time only one commandButton is shown in my page. When i click that commandButton, one flag is set and it shows another commandButton(second). But after that, when i click the second commandButton even decode method is not getting called and the action method defined below(doAction) is not getting invoked.
Is it a problem in JSF framework itself?


Code Snippet


My Xhtml looks like this:

<h:form>
<h:commandButton id="test" value="first" action="#{demo.showFlag}" />

<h:panelGrid id="grid">
<h:commandButton id="bt1" value="second" action="#{demo.doAction}" rendered="#{demo.flag}"/>
</h:panelGrid>

</h:form>


Demo.java
public void showFlag(){
flag=true;
}

Thanks in Advance,
VarunJ
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howzit Varun,

Do you have the doAction method defined in your Demo.java bean??
 
varun prakash
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Ya, I have the doAction() method declared properly.
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's odd because I just got it working perfectly here. Can you please then post your entire jsp file as well as your entire bean. Also make sure that the bean is declared in the jsf config xml file, and that that xml config file is referenced in your web.xml.

If that is all good, then this works just fine.
 
Venkat Sadasivam
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of rendered attribute in <h:commandButton> use <c:if test="#{demo.flag}">
 
Ted Raymond
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the <c:if> statement will not work either. I'm going to assume that your backing bean is Request scoped. If you want this to work, you need to change the scope to Session. If the scope is request, when you use the rendered action button, JSF rebuilds the model and does not know that demo.flag should be true, so the action button is not created in the model and hence is not fired. If you change the scope to session, it will work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic