1

I'm trying to use onclick and VF actionFunction to show a portion of a page.pageblocksection is not rendering.showdetail is false on vf page

I've set up an onclick like this:

<apex:commandLink value="Previous" 
                  action="{!setController.previous}"
                  onclick="hideDetail();"
                  rendered="{!setController.hasPrevious}"/>

<apex:actionFunction name="hideDetail"
                     action="{!hideDetail}"
                     rerender="detailBlock"/>

And I've set up a method like this in the controller:

//Called by actionFunction for Javascript onclick.
  public PageReference hideDetail() {
    showDetail = true;
    returnnull;
  }

And the detail pageBlock is like this:

<apex:pageBlockid="detailBlock">
<apex:pageBlockSection title="Position Detail"
                       collapsible="false"
                       rendered="{!showDetail}">
3
  • What's the problem you are faced with this code? Try to add return false; to the onclick: onclick="hideDetail(); return false;" Commented Nov 18, 2013 at 19:37
  • Pageblocksection section is not rendering..showDetail is false on vf page.
    – sfdc
    Commented Nov 18, 2013 at 19:59
  • dev, Were you able to find the answer for this? I am facing the same issue, actionFunction is getting called and the boolean variable is set to TRUE however PageBlockSection is not getting rendered . Please help.
    – KSK
    Commented Dec 17, 2014 at 23:24

1 Answer 1

1

The commandLink needs to have a reRender attribute in order to call the actionFunction, otherwise it submits the form causing a postback. You can't cancel the postback, either, because that would also negate the effects on the controller. Worse, you're trying to submit the view state twice, so only one action would win in either case. Try the following modifications:

<apex:commandLink value="Previous" 
                  action="{!setController.previous}"
                  oncomplete="hideDetail();"
                  rendered="{!setController.hasPrevious}"
                  reRender="form"/> <!-- must have a reRender, at minimum -->
     <!-- also, we use "oncomplete" so that we don't have two conflicting view states -->

<apex:actionFunction name="hideDetail"
                     action="{!hideDetail}"
                     rerender="detailBlock"/>
2
  • actionfunction is getting called ..but the hidedetail is false on visualforce
    – sfdc
    Commented Nov 18, 2013 at 20:25
  • If you're referring to the view state, as I stated here, you need to call it "after" (oncomplete) and not "before" (onclick), otherwise you'll clobber your view state.
    – sfdcfox
    Commented Nov 18, 2013 at 20:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .