I have an APEX page with a few fields and some buttons. Initially, the first field (a lookup field) is the only one that is shown. I would like to be able to show the other fields once the user has selected a value from the lookup window.

Currently, I am using rendered={!isFieldSet == true} in the fields I want to hide until later, but I am unable to update this value and get the fields to appear. I am currently using a javascript onchange method to call the controller method to set the isFieldSet value. But when I examine the property from javascript, it does not see the change to the isFieldSet, I guess because the page has not been reloaded? I am wondering what the standard way to get this sort of thing to work is. Currently I am trying to reload the page using url arguments, but the lookup field value is not coming through to the backend.

Here is some code for reference.

    <apex:inputField value="{!objectReference.propertyName}" required="true" onchange="actionpropertyValueChanged();">

Here is the code for hiding a section:

    <apex:pageBlockSectionItem rendered="{!isFieldSet == true}" id="daySelectorBlock">
  • There a two things that you might have missed 1)In your Action function or Action Support use Rerender attribute to rerender the Pageblock 2)The boolean must be a getter and setter and you must set the boolean in the controller method . – Mohith Shrivastava Dec 3 '12 at 2:48

apex:actionSupport can be used to rerender a component via AJAX when a change is made to the inputField.

<apex:actionStatus startText="Wait." stopText="" id="inputFieldActionStatus"/>
<apex:inputField value="{!objectReference.propertyName}" required="true" >
     <apex:actionSupport action="{!someControllerMethod}" status="inputFieldActionStatus" 
         event="onclick" rerender="daySelectorBlock">
         // You might want an apex:Param here to pass the inputField value back via ajax

<apex:pageBlockSectionItem rendered="{!isFieldSet}" id="daySelectorBlock">

After the AJAX call to the server the pageBlockSectionItem should render if isFieldSet is set to true via the method someControllerMethod.

  • Super. That has done the trick. I had actually tried to add something like that, but I used actionFunction instead of actionSupport... Thanks! – lindon fox Dec 3 '12 at 2:52
  • 3
    Just to caveat one thing - if the daySelectorBlock wasn't rendered when the page was originally displayed, then a rerender of it will have no effect. You need to wrap this inside a component that is always rendered and then rerender that. This is explained better at: bobbuzzard.blogspot.co.uk/2011/02/… – Bob Buzzard Dec 3 '12 at 9:13

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.