0

I am facing problem in putting if else condition in VF Page.There is a page which is not taking <apex:panelGroup rendered="{!taxa=='GST'}"/> condition.

When I am putting <apex:panelGroup rendered="{!taxa!='GST'}"/> value I am getting. But it is not based on the condition. It is taking random value. I have applied all the options like outputpanel or style:display:{if } condition.

<apex:outputPanel rendered="{!taxa=='Service Tax'}"> Tesing 1</apex:outputpanel>
<apex:outputPanel rendered="{!taxa=='GST'}" >Tesing 2</apex:outputPanel>

2 Answers 2

1

if you want to render block of page based on condition you can use rendered attribute of apex:outputPanel. For example

<apex:outputPanel rendered="{!yourBooleanExpression}">
    Block text
</apex:outputPanel>
2
  • <apex:outputPanel rendered="{!taxa=='Service Tax'}"> Tesing 1</apex:outputpanel> <apex:outputPanel rendered="{!taxa=='GST'}" >Tesing 2</apex:outputPanel> I have tried this but i am not getting any value. when i am putting <apex:outputPanel rendered="{!taxa!='Service Tax'}"> Tesing 1</apex:outputpanel> <apex:outputPanel rendered="{!taxa!='GST'}" >Tesing 2</apex:outputPanel> i am getting both values. I have checked the class where taxa i am getting only GST
    – geek_sfdc
    Jul 15, 2017 at 19:56
  • @geek_sfdc can you provide related code of VF page and controller/extension ? Jul 15, 2017 at 20:01
0
<apex:outputPanel rendered="{!taxa == 'GST'}">
    GST!
</apex:outputPanel>
<apex:outputPanel rendered="{!taxa == 'Service Tax'}">
    Service Tax!
</apex:outputPanel>

Not much mistery here. If the condition is true, then the panel gets rendered. If your panels are not being rendered, then your variable simply isn't matching the text used on the conditionals.

Example: if your taxa variable equals null or a string other than "GST" or "Service Tax" then the panels won't get rendered.

Tip: outputPanel renders a container (a div, if I remember correctly), but you can specify for it not to render a container tag using layout="none".

3
  • no dude <apex:outputPanel rendered="{!taxa != 'GST'}"> GST! </apex:outputPanel> <apex:outputPanel rendered="{!taxa != 'Service Tax'}"> Service Tax! </apex:outputPanel> for this condition both the values are getting rendered. but in class i am getting only one value i.e taxa='GST'
    – geek_sfdc
    Jul 15, 2017 at 20:09
  • The code you posted uses != (different than) instead of == (equals), so my guess is that your variable is either null or it contains a value that doesn't match GST or Service Tax. Can you post your apex code to your question? Jul 15, 2017 at 21:02
  • thanks there was a problem in declaring variable in the page.Thanks
    – geek_sfdc
    Jul 17, 2017 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .