+ Start a Discussion
Jyothsna ReddyJyothsna Reddy 

if condition in Visualforce page

I had written the IF Condition in VF page  as below
<apex:column value="{! If(m.Name=='sai' ,true,false) }"/>

But I am getting the " Error is in expression '{!If(m}' "evenI had given Correct syntax.

How can i solve this?
Virendra ChouhanVirendra Chouhan
Hi Jyothsna,

The syntax of If statment is correct .
but i didn't understand what you want to do, I mean you are using if statment in value  attribute insted of rendered.

Jyothsna ReddyJyothsna Reddy
Actually I  want to hide  /show
I am showing the List  of values regarding to one object .Here I have used <apex:datatable > to view the list.
one of my FieldName is Name having the value as 'sai'
suppose <apex:column value="{!obj.Name}"/>
  Here If obj.Name='sai' I want to show  some <apex:compoonent> here?

did u got this?
srlawr uksrlawr uk
I think Virendra is right with her speculation... though I don't fully understand your use case either.

In your datatable, if the current row (for the field "Name") is 'sai' you want to nest another apex:component in the cell?

You need to put the boolean logic into the rendered attribute, so if I had a datatable with a column for "Name" and I didn't want it to show for a value of "Dickenson plc" I could define the column like this:

<apex:dataTable value="{!accounts}" var="a">
    <apex:column value="{!a.Id}"/>
    <apex:column value="{!a.Name}" rendered="{!a.Name != 'Dickenson plc'}"/>

My table then would have two columns, full of information, except the one cell (in my case) where Dickenson plc is not rendered.

no name

IF you want to render something ELSE, you have to get more tricky, and define a simple column with more complicated contents, like this:

<apex:dataTable value="{!accounts}" var="a">
    <apex:column value="{!a.Id}"/>
        <apex:outputText value="{!a.Name}" rendered="{!a.Name != 'Dickenson plc'}" />
        <apex:outputText value="my name insead" rendered="{!a.Name == 'Dickenson plc'}" />

as you can see here, if my cell was to show Dickenson, it would now show "my name instead" - otherwise the account name is displayed. You are slightly limitted as to what you can nest in a tablecell, so you will have to play about with what you want.

new value

Hopefully this answers your question?
Virendra ChouhanVirendra Chouhan
Thank you srlawr uk!

Jyothsna, srlawr uk is give you a correct code.And if you want to to show some component if they have name = "sai" then you have to use rendered attribute in dataTable like this :

<apex:dataTable value="{!Candidate__c}" var="c" rendered="{! If(candidate__C.Name =='Viru' ,true,false) }">
                <apex:column value="{!Candidate__c.name}" />
or without using IF

<apex:dataTable value="{!Candidate__c}" var="c" rendered="{!Candidate__c.Name =='Veer'}">
            <apex:column value="{!Candidate__c.name}" />

Jyothsna ReddyJyothsna Reddy
Okay thanq srlawr ,virendra..

My Issue solved
mohit kumar 195mohit kumar 195
The following syntax is also working
<apex:outputLabel value="{!IF(input=='A','AAAA','Others')}" /> 

where input is variable