File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Problem after rendering a commandButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Problem after rendering a commandButton" Watch "Problem after rendering a commandButton" New topic

Problem after rendering a commandButton

varun prakash

Joined: Oct 12, 2006
Posts: 17
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:commandButton id="test" value="first" action="#{demo.showFlag}" />

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

public void showFlag(){

Thanks in Advance,

SCJP - 98%<br />SCWCD - 89%
Darryl Nortje
Ranch Hand

Joined: Jun 11, 2002
Posts: 140
Howzit Varun,

Do you have the doAction method defined in your bean??
varun prakash

Joined: Oct 12, 2006
Posts: 17
Ya, I have the doAction() method declared properly.
Darryl Nortje
Ranch Hand

Joined: Jun 11, 2002
Posts: 140
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

Joined: May 10, 2008
Posts: 139
Instead of rendered attribute in <h:commandButton> use <c:if test="#{demo.flag}">

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand. ”<br>
-Martin Fowler
Ted Raymond

Joined: Jun 17, 2008
Posts: 1
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.
I agree. Here's the link:
subject: Problem after rendering a commandButton
It's not a secret anymore!