1

I want to show some text when I click on the button partially updating page.

Why reRender option doesn't work? Here is my code

controller:

public class CustomAccountController {    
    public Boolean contactCreation {get; set;}

    public CustomAccountController() {         
            contactCreation = false;             
    }

    public PageReference show() {        
        contactCreation = true;
        return null;
    }    
}

VF Page :

<apex:page controller="CustomAccountController">
  <apex:form >
    <apex:commandButton value="New" reRender="viewNew" action="{!show}"/>    

    <apex:outputPanel id="viewNew" rendered="{!contactCreation}"> 
      <apex:outputText value="Hello"/>
    </apex:outputPanel>
  </apex:form>
</apex:page>

4 Answers 4

0

I just wrapped your output panel into another panel and gave the viewNew to the outermost panel it is working.

4
  • Thanks, it really work now. What is the rule of using reRender in this case? Why it doesn't work with one outputPanel component? Apr 14, 2015 at 15:17
  • The rule here is that you need to rerender a container so that whatever inside gets rerendered. If this answers your question make this as a solution.
    – Suresh
    Apr 14, 2015 at 15:20
  • Could you point this case in some reference, is it a lack of documentation that i haven't found this in reference guide? May be I will get a vision how it works. Apr 14, 2015 at 15:57
  • @ Iaroslav Petriv I didn't came across any documentation, I learned about this situation while practise.
    – Suresh
    Apr 14, 2015 at 17:41
3

The problem is your contactCreation property. If you check your controller's constructor, a default 'false' value is set for it and consequently your Visualforce page will not render your 'viewNew' panel; this is because of rendered="{!contactCreation}", so in other words, Visualforce will not generate an HTML node for 'viewNew' panel. When you try to rerender, it will not work since the panel was not rendered in the page (HTML was not generated for the panel).

@Suri 's solution works because if you wrap the panel inside of another panel that is always rendered, then you will be able to rerender the always-displayed parent panel and their child components will be updated.

2
  • This is an old question you are replying to, but this answer explains the reasoning better.
    – CyberJus
    Apr 23, 2015 at 21:56
  • Yeah, I thought it might be useful information if somebody comes around here. :D
    – Joca
    Apr 23, 2015 at 22:04
-1

Place the outputpanel in form tag as well.

4
  • I tried to place outputpanel in form tag but it didn't help. Apr 14, 2015 at 13:42
  • Can you try using void datatype instead of pageReference in controller method? Apr 14, 2015 at 13:43
  • I've just tried it. It didn't help. Apr 14, 2015 at 13:58
  • Are you sure that your panel replaced to apex:form? Update your question
    – misha_m
    Apr 14, 2015 at 14:09
-1

Try to add layout attribute

<apex:outputPanel layout="block" id="viewNew" rendered="{!contactCreation}"> 
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.