0
votes

i created a visualforce page in which there is a code segment

<apex:column ><apex:commandButton value="{!if(item.i == size-1,'Add','Delete')}" action="{!if(size == 1,addElement(),removeElement())}"></apex:commandButton></apex:column>

i created a custom controller containing function

public PageReference addElement(){

return null;

}
public PageReference removeElement(){

return null;

}

but when i try to save the visualforce page it is giving me error

Error: Unknown function addElement. Check spelling  

can any one please tell me how to use if structure in action attribute so that it will properly work

1
Are you trying to call the addElement()/removeElement() method present in the controller? If yes then you dont need to specify the round brackets in the action attribute. It should simply be action="{!IF(size == 1, addElement, removeElement}" - Shailesh Deshpande
i tried that also but it will give me error unknown property addElement after that i tried addElement() .please check it by yourself - Ritesh Mehandiratta

1 Answers

2
votes

Change it to

<apex:commandButton value="{!if(item.i == size-1,'Add','Delete')}" action="{!addElement}" rendered="{!size == 1}"/>
<apex:commandButton value="{!if(item.i == size-1,'Add','Delete')}" action="{!removeElement}" rendered="{!NOT(size == 1)}"/>