3

I am new to salesforce, apex and vf so please bear with me. Below is my code:

<script type="text/javascript">
function updateSplash(){
  UpdateUser();
}        
</script>
<apex:actionFunction name="UpdateUser" action="{!updateDSMTracker}" rerender="" >
  <apex:param assignTo="{!UserId}" name="UserId" value="{!$User.Id}"/>
</apex:actionFunction>

but I only want to include this piece of code in my page conditionally. For example:

if (showColorbox == true){
  <script type="text/javascript">
    function updateSplash(){
      UpdateUser();
    }
  </script>
  <apex:actionFunction name="UpdateUser" action="{!updateDSMTracker}" rerender="" >
    <apex:param assignTo="{!UserId}" name="UserId" value="{!$User.Id}"/>
  </apex:actionFunction>
}

where showColorbox is an apex boolean variable and if it is true then only it should include this javascript function and vf piece otherwise not. But I am unable to find any help on this. Thanks in advance.

2

You can do it by using rendered option. Example of how to do it:

<apex:panelGroup rendered="{!myCondition}">
  <!-- the rest of the code that should only be rendered(visible) if "myCondition" is true -->
</apex:panelGroup>

myCondition must be a boolean, but not necessarily a boolean variable. It could be a simple comparison, for example:

<apex:panelGroup rendered="{!myInteger == 3}">
  <!-- then I will only see this if value of "myInteger" variable is 3 -->
</apex:panelGroup>
| improve this answer | |
  • I would suggest you put your content in an outputPanel instead. That way you have the lightest possible DOM. Or, if this is something you want to use in multiple pages, create a Visualforce Component. – Andrew Monshizadeh Dec 23 '14 at 12:34

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.