You need to sign in to do that
Don't have an account?
AC Slater
CommandButton + param
I'd like to be able to dynamically generate buttons on my Visualforce page. Once the user has clicked on one of the buttons, I'd like to redirect the user to a second page and display different information on that page depending on which button the user clicked on. I've poked through a number of posts on these boards and can't quite figure out how to accomplish this. These these posts seem close, but the solutions described require a 'reRender', which I don't want to deal with for reasons irrelevant to this discussion:
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=1000 http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=1000
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=810
Here's my VF page:
Here's my controller:
Here's my second VF page:
Unfortunately, the results are always:
Selected User: ""
Is there a better way to accomplish what I'm trying to do?
Thanks in advance!
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=1000 http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=1000
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=810
Here's a picture of what I'm trying to accomplish:
Here's my VF page:
Code:
<apex:page controller="SimpleRepeatController"> <apex:form > <apex:pageBlock mode="edit" > Lorem Ipsum <apex:pageBlockButtons > <apex:repeat value="{!Users}" var="user" id="repeat"> <apex:commandButton action="{!NextPage}" id="cmdBtn" value="Select '{!user.Name}'"> <apex:param value="{!user.Id}" name="UserId"/> </apex:commandButton> </apex:repeat> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
Here's my controller:
Code:
public class SimpleRepeatController { public List<User> Users { get { return [SELECT Id, Name FROM User WHERE Name != 'License Manager' AND IsActive = true ORDER BY LastName]; } } public PageReference NextPage() { PageReference selectedUserResults = Page.SelectedUserResults; selectedUserResults.setRedirect(true); return selectedUserResults; } }
Here's my second VF page:
Code:
<apex:page controller="SimpleRepeatController"> Selected User: "{!$CurrentPage.parameters.UserId}" </apex:page>
Unfortunately, the results are always:
Selected User: ""
Thanks in advance!
Pretty much there, but bear in mind that $CurrentPage.parameters for the new page won't contain the query parameter. (It's a query parameter for the first page that is posted back to, not the second page that you've redirected to).
To fix, change the NextPage() method to:
Sometimes I've also had issues getting through the parameter from a commandButton - changing this to a commandLink often seemed to resolve this.
I'm having the same issue with commandButton. The param does not come through. It comes through with commandLink.
Can someone from SalesForce speak to this limitation with commandButton? Is there another trick? This is kind of a big deal - passing parameters to action methods is fundamental.
Use this page and notice the value is returned in the partial page update:
Now remove the rerender attributes from the commandButton tags and notice that when clicking on the button to display the param value that the page refreshes but the value is not displayed as before.
I was also running in to that (very frustrating) commandButton bug that dchasman referred to, because once I switched to commandLink everything worked great.
VF page:
Controller code:
Second VF page:
Thank you again!