You need to sign in to do that
Don't have an account?
Function call in rendered attribute possible?
Hi all,
I am working on a VF page with a lot of different modussus. Depending on the modus certain information should be shown. So I was thinking, and I thought I found a cool way how I could accomplish this. I created a function with a string as argument, and returns back if the element should be rendered or not.Using this function, the VF code should stay clean.
But when I try to use this function in my rendered attribute, it's not working :smileysad:. When I try to save (in eclipse) it says "Unknown function renderMe. Check spelling.".
Does anybody has any ideas, before I have to go and put everything in the rendered attribute itself over and over... Bleh that's gonna look dirty, I don't like to go that way :(
VF code:
<apex:page standardController="Account" extensions="AccountExtension" > <apex:commandButton value="Gegevens bewerken" action="{!enterEditMode}" rendered="{!renderMe('1')}"/> <apex:outputLabel value="" rendered="{!renderMe('1234')}"/> </apex:page>
Controller code
public class AccountExtension { private static final String MODUS_1 = '1'; private static final String MODUS_2 = '2'; public String currentModus {get;set;} /** This method is used by the visual force components to determine if these can be rendered or not. */ public boolean renderMe(String modusses) { if (modusses.contains(currentModus)) { return true; } return false; } }
JD,
I am sorry that I overlooked the code. As per the limitations of vf, we cannot pass the arguments from visualforce to apex. we have to use apex:param tag to pass the parameters if we have to. you have to either user param tag for passing the parameters and for rendering you can use rendered = "{!renderMe}". or if you want to check the condition in the vf page rendered = "{! IF(renderMe == '1', TRUE, FALSE"} (your method in the controller should return string type)
another thing is that, in your visual force page, you will have to include the apex:form tag inorder to include you command button tag.
All Answers
Hi schreurs_jd,
In your vf page code, you are calling renderME with arguments while that is not defined in your extension. try the below code
I am not sure on how you are getting the current Modus. If that is being calculated correctly, the above code shud hide/unhide ur command button and output label based on renderMe property.
Hi,
Thanks for your answer, but I don't understand your answer completely about that I don't have defined it in my extension. I have defined a function which returns a boolean. Then I would like to use the function rather than setting and reading a variable (the standard way). I would like to use that function in my VF page..
I was just curious if it is possible to use a function, and hoped that somebody could answer this. But time to search the internet a bit more and try some other things now.
Greetings and thanks, JD
JD,
I am sorry that I overlooked the code. As per the limitations of vf, we cannot pass the arguments from visualforce to apex. we have to use apex:param tag to pass the parameters if we have to. you have to either user param tag for passing the parameters and for rendering you can use rendered = "{!renderMe}". or if you want to check the condition in the vf page rendered = "{! IF(renderMe == '1', TRUE, FALSE"} (your method in the controller should return string type)
another thing is that, in your visual force page, you will have to include the apex:form tag inorder to include you command button tag.
Hi N V Prudhvi kamal K,
Thanks for your answer, I wasn't really aware of that limitation. Have to read a little bit more about it :).
Going now fo the complex if statements in my visual force page now.
Thanks!