I would like to reRender a Div based on some logic. Initially the div will be set as display:none as per the logic (Checking whether the variable is null or not).
But after passing value to controller through apex:actionFunction, I am setting up the variable with proper value. During this time, I am expecting the previous div will be set as display:block. But unfortunately it is not happening.
Here is the code –
Apex:actionFunction:
<apex:actionFunction name="verifyJavaScript" action="{!verify}" rerender="displayPreference"/>
Div:
<div class="row" style="{!IF(selectedPreference != null, 'display:block', 'display:none')}" id="displayPreference">
<div class="col-lg-12 form-group form-group-lg">
<input id="promoOptIn" rendered="{!IF(selectedPreference != null , true , false)}" name="promoOptIn" type="checkbox" value="1" /> Register for Promo Opt In?
<apex:inputhidden id="promoOptIns" value="{!promoOptIns}" />
</div>
</div>
Controller:
public PageReference verify(){
PageReference ProductRefresh = ApexPages.currentPage();
//Setting up the variable selectedPreference here based on logic
return ProductRefresh;
}
Could you please help me to understand what is wrong here?
Best Answer
Rather than using
<div>
use<apex:outputPanel>
and it will render asdiv
in HTML.Otherwise, wrap entire
<div>
block inside an<apex:outputPanel>
and rerender that outputPanel as follows:Side note: don't use
if(,true,false)
in rendered condition, userendered="{!selectedPreference != null}"
as it displays only attrue
condition.Refer apex:outputPanel