You need to sign in to do that
Don't have an account?

Rerender doesn't work on CommandButton
This is a sample. When I click 'hide it', it supposed to hide the text, but nothing happened. Could some one help?
/***************Page**********************/
<apex:page sidebar="false" showChat="false" showHeader="false" controller="TestRenderCtrl">
<apex:form >
<apex:outputPanel id="panel1" rendered="{!isRendered}">
Panel: it is used for testing render.
</apex:outputPanel>
<apex:outputPanel >
<apex:commandButton value="hide it" action="{!hidePanel}" reRender="panel1" />
<apex:commandButton value="show it" action="{!showPanel}" reRender="panel1" />
</apex:outputPanel>
</apex:form>
</apex:page>
/***************Controller*****************/
public class TestRenderCtrl{
public Boolean isRendered {get; set;}
public TestRenderCtrl(){
isRendered = true;
}
public PageReference hidePanel(){
isRendered = false;
return null;
}
public PageReference showPanel(){
isRendered = true;
return null;
}
}
/***************Page**********************/
<apex:page sidebar="false" showChat="false" showHeader="false" controller="TestRenderCtrl">
<apex:form >
<apex:outputPanel id="panel1" rendered="{!isRendered}">
Panel: it is used for testing render.
</apex:outputPanel>
<apex:outputPanel >
<apex:commandButton value="hide it" action="{!hidePanel}" reRender="panel1" />
<apex:commandButton value="show it" action="{!showPanel}" reRender="panel1" />
</apex:outputPanel>
</apex:form>
</apex:page>
/***************Controller*****************/
public class TestRenderCtrl{
public Boolean isRendered {get; set;}
public TestRenderCtrl(){
isRendered = true;
}
public PageReference hidePanel(){
isRendered = false;
return null;
}
public PageReference showPanel(){
isRendered = true;
return null;
}
}
<apex:page sidebar="false" showChat="false" showHeader="false" controller="TestRenderCtrl">
<apex:form >
<apex:outputPanel id="panel1" >
<apex:outputPanel rendered="{!isRendered}">
Panel: it is used for testing render.
</apex:outputPanel>
</apex:outputPanel>
<apex:outputPanel >
<apex:commandButton value="hide it" action="{!hidePanel}" reRender="panel1" />
<apex:commandButton value="show it" action="{!showPanel}" reRender="panel1" />
</apex:outputPanel>
</apex:form>
</apex:page>
All Answers
<apex:page sidebar="false" showChat="false" showHeader="false" controller="TestRenderCtrl">
<apex:form >
<apex:outputPanel id="panel1" >
<apex:outputPanel rendered="{!isRendered}">
Panel: it is used for testing render.
</apex:outputPanel>
</apex:outputPanel>
<apex:outputPanel >
<apex:commandButton value="hide it" action="{!hidePanel}" reRender="panel1" />
<apex:commandButton value="show it" action="{!showPanel}" reRender="panel1" />
</apex:outputPanel>
</apex:form>
</apex:page>
<apex:form >
<apex:outputPanel id="panel1" rendered="{!isRendered}">
Panel: it is used for testing render.
</apex:outputPanel>
<apex:outputPanel >
<apex:commandButton title="hide it" value="hide it" action="{!hidePanel}"/>
<apex:commandButton title="show it" value="show it" action="{!showPanel}"/>
</apex:outputPanel>
</apex:form>
</apex:page>
// For the same function (show or hide the text via rendered), just coding like this. It's no need to use rerender.