Ben
Ben

Reputation: 10288

JSF - Unhide jsf component when clicking another component

I'm trying to have a button that brings up an upload dialog. The way i'm trying to achieve this is similar to this:

<h:outputText value="Click Me" id="testit">
  <a4j:support reRender="hideme" event="onclick" action="#{actions.switchTestRendered}"/>
</h:outputText>
<h:outputText id="hideme" value="back" rendered="#{actions.testRendered}"/>

With code in the backing bean:

private boolean testRendered = false;
public String switchTestRendered(){
 setTestRendered(!isTestRendered());
 System.out.println("Current Status:"+isTestRendered());
 return "success";
}

public void setTestRendered(boolean testRendered) {
  this.testRendered = testRendered;
}

public boolean isTestRendered() {
  return testRendered;
}

When I press the 'click me' label I can see that the switchTestRendered is run but the 'hideme' component does not reveal.

Any suggestions? Thanks!

Upvotes: 1

Views: 450

Answers (2)

GustyWind
GustyWind

Reputation: 3036

From the code it can only be seen that after 'Click me' the 'hide' component renderer is not updating. You have to find out why

Upvotes: 0

Ben
Ben

Reputation: 10288

Got it. I should have reRendered the parent of the element which I'm trying to hide/show. In other words:

<a4j:support reRender="hideme" event="onclick" action="#{actions.switchTestRendered}"/>

should be:

<a4j:support reRender="father_of_hideme" event="onclick" action="#{actions.switchTestRendered}"/>

Thanks! Ben.

Upvotes: 1

Related Questions