0

I'm newbie in Salesforce, and I am having a problem that I cant fix. I am using Twilio for making/receiving calls. I would like to put a conditional on my VFP depending on a variable that is set on the controller, to respond one thing or another.

The situation is the next one: The VisualForcePage:

    <!--(condition if the variable {!Number} == '1')-->  
    <Response>
        <Say>Hello</Say>                
    </Response>
    <-- end of the condition-->

    <!--(condition if the variable {!Number} == '2')-->
    <Response>
        <Say>GoodBye</Say>                
    </Response>     
    <-- end of the condition-->

And this is the controller:

public class myController{

    public String getNumber() {
        String Number = ApexPages.currentPage().getParameters().get('From');
        return Number;
    }
}
1

You need apex:outputpanel and rendered condition to make it work.

<apex:outputpanel layout="none" rendered="{!Number == '1'}">
     <Response>
        <Say>Hello</Say>                
    </Response>
</apex:outputpanel>
<apex:outputpanel layout="none" rendered="{!Number == '2'}">
     <Response>
        <Say>GoodBye</Say>                
    </Response>
</apex:outputpanel>
| improve this answer | |
0

You need to be using one or more page divisions, such as <apex:outputPanel>, with a rendered attribute, which controls conditional rendering. Populate the rendered attribute with a Visualforce expression that evaluates to a boolean (and can reference controller properties) to determine on the server side whether or not it renders.

Note that any regions that have rendered evaluate to false are never sent to the client, so you can't dynamically rerender them. If you need that functionality, wrap them in an outer outputPanel that can be the target of the rerender.

| improve this answer | |
  • thanks for the response David, I have thought to do that, but if my variable is a number, and there are more than 2 options? Is not a property like rendered as? cheers – jmarco Feb 13 '18 at 12:48
  • You can use as many conditionally rendered sections as necessary to render the correct view for each possible option, although with a large number of options this will quickly become unwieldy and may recommend a change in page architecture. There isn't really a Visualforce equivalent of a case statement. – David Reed Feb 13 '18 at 14:13
  • Please edit your question with what you've tried and any error messages rather than using comment threads. Thanks. – David Reed Feb 13 '18 at 16:11

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.