function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DrawloopSupportDrawloopSupport 

Problem changing Rendered attribute due to order of execution

Visualforce:

 

<apex:pageBlockSectionItem rendered="{!boolVal}">
<apex:outputLabel value="Test1" />
<apex:inputText value="{!t.value1}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem rendered="{!NOT(boolVal)}">
<apex:outputLabel value="Test2" />
<apex:inputText value="{!t.value2}"/>
</apex:pageBlockSectionItem>

 

 Apex:

 

public object temp;
public object getT() {
if (temp == null && ApexPages.currentPage().getParameters().get('id') != null)
temp = [SELECT value1, value2 FROM object WHERE Id = :ApexPages.currentPage().getParameters().get('id') LIMIT 1];
if (temp.value2 == 'sampleval')
setBool(true);
else
setBool(false);
return temp;
}

public boolean bool;
public boolean getBoolVal() {
if (bool == null)
bool = True;
if (temp != null && temp.value2 != 'sampleval')
bool = False;
return bool;
}
public void setBoolVal(boolean b) {
bool = b;
}

 

 I am trying to dynamically show/hide the pageBlockSectionItems shown in the vf code above. It seems that the rendering of these pageBlockSectionItems happens before the apex code gets to the getT function. Is there a way to prioritize the order of apex calls or rerender the pageBlockSectionItems if the boolean value changes?

 

 

 

Message Edited by DrawloopSupport on 04-15-2009 04:35 PM
Best Answer chosen by Admin (Salesforce Developers) 
Walter@AdicioWalter@Adicio
To add functionality before the page loads doesnt your code need to be triggered by the action="" for the <apex:page>? I currently have some pages that show hide sections based on things like which user profile for the current user and I call a pagereference from the action="" in the <apex:page>.

All Answers

Walter@AdicioWalter@Adicio
To add functionality before the page loads doesnt your code need to be triggered by the action="" for the <apex:page>? I currently have some pages that show hide sections based on things like which user profile for the current user and I call a pagereference from the action="" in the <apex:page>.
This was selected as the best answer
Walter@AdicioWalter@Adicio

This runs before the page loads.

 

 

 

public pageReference setConditionsToTrue() {

// if the query returns results show the section if(oneTimeSetupFeeQuery.size()>0){oneTimeSetupFeeSection = true;}

if(monthlyFeeQuery.size()>0){monthlyFeeSection = true;} return null;}

 

 

 

<apex:page action="{!setConditionsToTrue}></apex:page>