0

I want to be able to populate the Rendered attribute of an apex:variable tag with the results of a function for different components i have, which are being displayed using <input> tags.

So let's say I am using Action Function like so:

<apex:variable value="x" var="y" rendered="{!myFunctionResult}"/>
<a>Input 1: </a>
<input name="input1"/>
<apex:actionFunction name="" immediate="true" action="{!function}">
<apex:param value="input1" name="fieldName"/>

I am able to pass the input that I want to validate back to the controller function and I have a true/false returned, which I can then use to render the input.

How can I do this, so that when a page loads, this will occur automatically?

[[ Updated ]] Still not working even when rerendering component...

<apex:component controller="FormExtensionController" > 
<apex:attribute type="String" description="test" name="fieldName" assignTo="{!fieldApiName}" />

<apex:outPutPanel id="mycomponent">
<apex:outPutPanel rendered="{!isRendered}">
<a>Input 1: </a>
</apex:outPutPanel>
</apex:outPutPanel>

<apex:form>
 <apex:actionFunction immediate="true" name="doCallout"  action="{!loadComponent}" rerender="mycomponent" />

</apex:form>
<script type="text/javascript">
(function() {
window.addEventListener("load", function() { doCallout(); });
})();
  </script>
  </apex:component>
1

The value would not be passed back to your page unless you rerender component

ie.

<apex:outPutPanel id="mypanel">
<apex:outPutPanel rendered="{!myFunctionResult}">
<a>Input 1: </a>
<input name="input1"/>
</apex:outPutPanel>
<apex:outPutPanel>

<apex:actionFunction name="" immediate="true" action="{!function}" rerender="my panel">

You need the two output panels if you have not other parent elements. You could also serenader the page. You cannot rerender the element with the conditional rendering directly in this case.

| improve this answer | |
  • I can't get this working even with rerendering the component itself. Posting update code.. – user3979986 Aug 3 '16 at 16:14
  • What if you remove immediate=true – Eric Aug 3 '16 at 16:23
  • Doesn't help, still not rendering – user3979986 Aug 3 '16 at 16:26
  • Then your value using to determine if the part should be rendered may not be as expected. try removing the rendered part and place the value of {!isRendered} in the <a> text to see if it changes or not. There is more going on here than what you posted as this is a fairly basic example and should work sans additional blocking issues/code – Eric Aug 3 '16 at 16:29
  • What seems to be the issue is that the rerendering step is not occuring. If I set the value to true before loading the page, then it renders. If I set it to true in the function from the VF page itself, it won't render. – user3979986 Aug 3 '16 at 16:47

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.