• dennis.mohan1.3964528316647961E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 1
    Replies

I see this question come up often and after having to fight with it again today, I thought I would post a quick quick with tips and tricks:

 

 

What you think should work

 

<apex:commandButton action="{!someAtion}" value="Click Me">
     <apex:param assignTo="{!conVariable}" name="con" id="con" value="123"/>
</apex:commandButton>

 Well, let me tell you, this DOES NOT work.

 

  - Why - A little bug with the command button and param. Commandlink works, but the command button requires something more to get it to set the value of the controller variable.

 

How to fix it

 

 1. Create a hidden output panel on the page, and simply rerender it. This will cause the command button to set the controller vairable as expected.

 

<apex:outputPanel id="hidden" rendered="false"/>

<apex:commandButton action="{!someAtion}" value="Click Me" reRender="hidden">
     <apex:param assignTo="{!conVariable}" name="con" id="con" value="123"/>
</apex:commandButton>

 

Calling Javascript with the button and setting the variable, what you think would work

 

<apex:commandButton onclick="someFunction();" value="Click Me" rerender="hidden">
     <apex:param assignTo="{!conVariable}" name="con" id="con" value="123" />
</apex:commandButton>

 

     Well this does not work either - You need BOTH the action and rerender to be present. Well shucks, I do not want to call the controller, I want to call a jave method....

 

How to make it work

 

1. Add a method to your extenstion / controller

 

public void doNothing(){

   //Do absolutely nothing

}

 2. Modify the button as follows:

 

<apex:commandButton action="{!doNothing}" onclick="someFunction();" value="Click Me" rerender="hidden">
     <apex:param assignTo="{!conVariable}" name="con" id="con" value="123"/>
</apex:commandButton>

 

Bam. The controller variable is set as expected.

 

Why would you use this? Well here was my flow:

 

1. On click of a button I needed to set the value of a controller variable which will be used in a query

2. Before the actual method in the controller ran, I needed to run some java to manipulate the DOM

3. After the method ran, I needed to check the results

 

1: Button -> doNothing -> call Java Function

2. Java Function DOM Stuff -> ActionFunction

3. ActionFunction -> Run Controller method -> onComplete -> Java Function passin in result variable from controller

4. Java Function More DOM Manipulation or Action Function stuff based on result.

 

Hope this helps someone


I see this question come up often and after having to fight with it again today, I thought I would post a quick quick with tips and tricks:

 

 

What you think should work

 

<apex:commandButton action="{!someAtion}" value="Click Me">
     <apex:param assignTo="{!conVariable}" name="con" id="con" value="123"/>
</apex:commandButton>

 Well, let me tell you, this DOES NOT work.

 

  - Why - A little bug with the command button and param. Commandlink works, but the command button requires something more to get it to set the value of the controller variable.

 

How to fix it

 

 1. Create a hidden output panel on the page, and simply rerender it. This will cause the command button to set the controller vairable as expected.

 

<apex:outputPanel id="hidden" rendered="false"/>

<apex:commandButton action="{!someAtion}" value="Click Me" reRender="hidden">
     <apex:param assignTo="{!conVariable}" name="con" id="con" value="123"/>
</apex:commandButton>

 

Calling Javascript with the button and setting the variable, what you think would work

 

<apex:commandButton onclick="someFunction();" value="Click Me" rerender="hidden">
     <apex:param assignTo="{!conVariable}" name="con" id="con" value="123" />
</apex:commandButton>

 

     Well this does not work either - You need BOTH the action and rerender to be present. Well shucks, I do not want to call the controller, I want to call a jave method....

 

How to make it work

 

1. Add a method to your extenstion / controller

 

public void doNothing(){

   //Do absolutely nothing

}

 2. Modify the button as follows:

 

<apex:commandButton action="{!doNothing}" onclick="someFunction();" value="Click Me" rerender="hidden">
     <apex:param assignTo="{!conVariable}" name="con" id="con" value="123"/>
</apex:commandButton>

 

Bam. The controller variable is set as expected.

 

Why would you use this? Well here was my flow:

 

1. On click of a button I needed to set the value of a controller variable which will be used in a query

2. Before the actual method in the controller ran, I needed to run some java to manipulate the DOM

3. After the method ran, I needed to check the results

 

1: Button -> doNothing -> call Java Function

2. Java Function DOM Stuff -> ActionFunction

3. ActionFunction -> Run Controller method -> onComplete -> Java Function passin in result variable from controller

4. Java Function More DOM Manipulation or Action Function stuff based on result.

 

Hope this helps someone