+ Start a Discussion
waylonatcimwaylonatcim 

repeats and rerenders not playing nice together

I'm running into a strange error that can be better explained through code:

 

 

<apex:page controller="fakeController">

<apex:form >
<apex:actionFunction rerender="repanel" name="changeDrop" />

<apex:outputPanel id="repanel">
<apex:pageBlock >
<apex:repeat value="{!mtfo}" var="m">
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="{!m.name} stage" />
<apex:selectList value="{!m.stage}" multiselect="false" size="1" onchange="changeDrop()">
<apex:selectOptions value="{!stageOptions}" />
</apex:selectList>
</apex:pageBlockSectionItem>


<apex:pageBlockSectionItem rendered="{!m.show}">
<apex:inputText value="{!m.val}"/>
</apex:pageBlockSectionItem>


</apex:pageBlockSection>
</apex:repeat>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>

 

public with sharing class fakeController {


public List<SelectOption> stageOptions{get{
if(stageOptions==null){
stageOptions = new List<SelectOption>{new SelectOption('one','one'), new SelectOption('two','two'), new SelectOption('three','three')};
}
return stageOptions;
}set;
}

public List<myTempFakeObj> mtfo{get{
if(mtfo==null){
mtfo = new List<myTempFakeObj>{};
mtfo.add(new myTempFakeObj(true,'first','one'));
mtfo.add(new myTempFakeObj(false,'second','two'));
mtfo.add(new myTempFakeObj(false,'third','three'));
}
return mtfo;
}set;
}
public class myTempFakeObj{
public Boolean show{get;set;}
public String name{get;set;}
public String stage{get;set;}
public String val{get;set;}

public myTempFakeObj(Boolean show, String name, String stage){
this.show = show;
this.name = name;
this.stage = stage;
}
}


}

 

 

This generates a simple page with 3 drop down menus and text fields.  The text fields are only shown if the 'show' variable in myTempFakeObj is set to true.  When the drop down option selected is changed, the page is re-rendered.  There are a few different scenarios that occur, depending on what text-fields are shown:

  1. all 3 MyTempFakeObj's show attributes are true --- everything works as expected
  2. the 'first' TempFakeObj is set to true and the other two (second, third) are false  -- when changing the drop down option selected in any of the drop down lists, any text that was typed into the 'first' val box dissapears. 
  3. The 'first' and 'third' obj's show is set to true and the 'second' is set to false -- the third val text box does not show.  For some reason each object seems dependent on the ones before it.

I'm sure that I'm doing a horrible job explaining this, but you can get a better idea of what's going on by creating this simple page and controller and playing with the page and values a bit. 

 

Just simply using the code I have above, typing any value into the text box that is displayed and then changing the drop down menu should show some of the behavior I'm talking about.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

It seems to be the pageblocksectionitem that's the problem.  If you change the page to:

 

 

       <apex:pageBlockSectionItem >
            <apex:inputText value="{!m.val}" rendered="{!m.show}"/>
        </apex:pageBlockSectionItem>

 

Then things seem to behave as they should.

 

All Answers

bob_buzzardbob_buzzard

This looks very much like an issue I've seen before, although that was repeats, rerenders and attempting to use parameters with command links.

 

I've changed the get/set on val to be an explicit method with debugging and that shows me that the setters are not being invoked if items 2/3 are false.  It seems like the view state isn't being updated in that case.

 

I'm sure I've seen something similar to this on another thread, which SF acknowledged as a known bug.

bob_buzzardbob_buzzard

It seems to be the pageblocksectionitem that's the problem.  If you change the page to:

 

 

       <apex:pageBlockSectionItem >
            <apex:inputText value="{!m.val}" rendered="{!m.show}"/>
        </apex:pageBlockSectionItem>

 

Then things seem to behave as they should.

 

This was selected as the best answer
waylonatcimwaylonatcim

Thank you, that certainly solved the issue.  The only issue now (which is not that big of a deal for me) is that it shows the empty space for the pageBlockSections.  I tried playing around with output panels but it messes up the formatting as far as the font style and alignment are concerned.

 

Thanks again!