function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
adreameradreamer 

query string to commandButton action

Hi there,

I would like to add a query string to the action attribute of a command button. The idea is that I pass in parameters to the controller's method for that action. The Visual Force reference manual say: " To add query string parameters to a commandButton, specify them in the associated action method". My question is: how is the sintax for that ?.

Something like this does not work :
<apex:commandButton action="{!save}?q={!myObject.id}" value="Save" id="theButton"/>
Thank you very much in advance.
Fernando
tonitonitonetonitonitone
Try this --


<apex:commandButton action="{!save}" value="Save" id="theButton">
<apex:param name="q" value="{!myObject.id}">
</apex:param>
</apex:commandButton>

Then in your controller, do this --
String q= ApexPages.currentPage().getParameters().get('q');

Message Edited by tonitonitone on 07-31-2008 10:52 AM
adreameradreamer
Thank you for your response.

It did not work, and it was expected because the Visual Force reference says for the param component that : "The param component can only be a child of an outputLink, outputText, or a actionFunction component".
I have solved the problem in a different way because I realized I was trying to send as a parameter of a query string something that came from the controller in the first place. So I had what I needed in the controller state, and a change in the logic did the trick.

Having said that, I am stil intrigued by the fact that the Visual Force reference says that it is possible to add a query string to the commandButton, it says that it should go in the action attribute, but it does not say what the syntax should be. Is it a trial error thing ? :)
jwetzlerjwetzler
apex: param should work with commandButton -- however there's currently a known issue that it doesn't work properly when used with a commandButton that is performing a partial page update.  The doc for the param component needs to be updated and will be once we get the bugs worked out of it.

I agree though that this is logic you should leave to your controller.