0

Let's say I want to conditional rendering of outputPanel markup

<apex:page controller="SOQLBC">  

<apex:outputPanel id="sobj" rendered="{!LEN(sObj)>0}">
    <span>  --- {!sObj} --- </span>
</apex:outputPanel> 
<apex:form>
         -- {!LEN(sObj)>0} --
    <apex:selectList value="{!sObj}" size="1">
        <apex:selectOptions value="{!sObjList}"/>
        <apex:actionSupport event="onchange" reRender="sobj"/>
    </apex:selectList>
</apex:form>

controller

public with sharing class SOQLBC {

public SOQLBC() {
    sObj = '';
}
public string sObj {get; set;}
public List<System.SelectOption> getsObjList() {
    List<System.SelectOption> options = new List<System.SelectOption>();
    options.add(new SelectOption('', '-- Select SObject --'));
     for(Schema.EntityDefinition entity : SchAccess.getsObjectsLite()) {
        options.add(new SelectOption(entity.qualifiedapiname, entity.label));
     }
     return options;
}

}

I want to show updatePanel only if sObj does not equal '' but I can't reach my goal - updatePanel is always hided

   <apex:outputPanel id="sobj">
    <apex:outputPanel rendered="{!LEN(sObj)>0}">
        <span >  --- {!sObj} --- </span>
    </apex:outputPanel>         
</apex:outputPanel> 

helped me

  • I can't see any part in the code that changes your Apex-variable "sObj". So it will always be an empty String. – Florian Heer Nov 25 '19 at 13:50
  • can U please suggest some? – pincet Nov 25 '19 at 13:57
  • by the way, <apex:selectList value="{!sObj}" size="1"> does not enough? – pincet Nov 25 '19 at 13:58
  • <apex:outputPanel id="sobj"> <apex:outputPanel rendered="{!LEN(sObj)>0}"> <span > --- {!sObj} --- </span> </apex:outputPanel> </apex:outputPanel> helped me – pincet Nov 25 '19 at 14:06
0

By Default value of sObj is blank hence outputPanel with sobj id does not exist on page load. So actionSupport was not working.

Update your code like below and it should work

  <apex:page controller="SOQLBC">  
       <apex:form>
<!-- Add parent outputPanel which will always render-->
           <apex:outputPanel id="parentPanel">
               <apex:outputPanel id="sobj" rendered="{!LEN(sObj)>0}">
                   <span>  --- {!sObj} --- </span>
               </apex:outputPanel> 
           </apex:outputPanel>
            <apex:selectList value="{!sObj}" size="1">
                <apex:selectOptions value="{!sObjList}"/>
                <apex:actionSupport event="onchange" reRender="parentPanel"/>
            </apex:selectList>
        </apex:form>
    </apex:page>

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.