+ Start a Discussion
GoForceGoGoForceGo 

Does re-render NOT work on an inputField component?

1. The scoring_pick_list__c field is not displayed when I pick the 'Picklist' value in the question type.

2. I tried replacing it with a pageBlockSectionItem with outputLabel and inputLabel and re-rendering the child components, it still does not work.

3. If I wrap inputField or the pageBlockSectionItem (from #2) in an outputPanel, it works, but them the styling is all messed up, since it is not a direct child of pageBlockSection.

 

 

<apex:page standardController="Survey_Question__c" >
<apex:form >
<apex:pageBlock mode="edit">
<apex:pageBlockSection title="Question" id="question" >
<apex:pageBlockSectionItem >
<apex:outputLabel value="{!$ObjectType.Survey_Question__c.fields.Question_Type__c.label}" for="qtype"/>
<apex:inputField value="{!Survey_Question__c.Question_Type__c}" required="true" id="qtype">
<apex:actionSupport event="onchange" rerender="spicklist"/>
</apex:inputField>
</apex:pageBlockSectionItem>
<apex:inputField value="{!Survey_Question__c.Scoring_Pick_List__c}" rendered="{!Survey_Question__c.Question_Type__c = 'Picklist'}" id="spicklist"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

AhmedPotAhmedPot

Even I have experienced similar behaviour while re-rendering, I tries using main page blocks and having few sub pageblocks or panels. I'm not sure about reason behind it.

sylar20sylar20

No. I guess there is a bug/conflict into the configuration. Try using Javascript to hide your blocks or put the inputfield section into iframe.

GoForceGoGoForceGo

It appears that  anything that has a rendered attribute cannot be a direct target of rerender.

 

 

Damien_Damien_

Try rerendering the <apex:pageBlockSection> instead

bob_buzzardbob_buzzard

Is your inputfield rendered the first time that you access the page? If not, then you won't be able to make it appear through rerendering, as you can't rerender something that isn't present.  You have to wrap the conditionally rendered item in a container (e.g. outputPanel) that is rendered in all cases.

 

I wrote a blog post explaining this in more detail at:

 

http://bobbuzzard.blogspot.com/2011/02/visualforce-re-rendering-woes.html

GoForceGoGoForceGo

Thanks Bob. As you correctly pointed out, you cannot re-render something that does  not exist.

The problem with using  outputPanel is that it messes up the styling of the pageBlockSectionItem.

I think I might try using a pageBlockSectionItem and using outputPanel wrapped around outputLabel and inputField.

 

bob_buzzardbob_buzzard

Yes, the outputpanel will mess up the styling, as it introduces extra div/span tags to allow the grouped content to be available via javascript.    I usually end up re-rendering a large chunk of the page to ensure my styling is retained, even if I really only want to rerender one or two elements.

GoForceGoGoForceGo

The following works. Essentially I am wrapping the label and inputfield in an output panel and I re-render scorelabel and scorevalue.

 

In my original post, I had removed some elements to make the example smaller. Here is the updated example with essential elements which now works.

 

Why I cannot re-render a large section (pageBlockSection or pageBlock):

 

This atttribute logicallly belongs within  this pageBlockSection. This pageBlockSection has a few required fields (e.g question name)  As a result, I had to wrap the questionType in actionRegion. I cannot re-render the entire pageBlockSection, because I would loose any values entered in other parts of this section (e.g the question name) on the actionSupport event, since actionRegion only sends value of question type.

 

 

 

 

 

<apex:page standardController="Survey_Question__c" >
<apex:form >
<apex:pageBlock mode="edit">
<apex:pageBlockSection title="Question" id="question" >
<apex:pageBlockSectionItem>
<apex:inputField value="{!Survey_Question__c.Name}" required="true" />
<apex:outputLabel value="{!$ObjectType.Survey_Question__c.fields.Question_Type__c.label}" for="qtype"/>
<apex:actionRegion >
<apex:inputField value="{!Survey_Question__c.Question_Type__c}" required="true" id="qtype">
<apex:actionSupport event="onchange" rerender="scorelabel,scorevalue"/>
</apex:inputField>
</apex:actionRegion>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputPanel id="scorelabel">
<apex:outputLabel value="{!$ObjectType.Survey_Question__c.fields.Scoring_Pick_List__c.label}" rendered="{!isScoringPickList}" for="spicklist"/>
</apex:outputPanel>
<apex:outputPanel id="scorevalue">
<apex:inputField value="{!Survey_Question__c.Scoring_Pick_List__c}" rendered="{!isScoringPickList}" required="true" id="spicklist"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>