You need to sign in to do that
Don't have an account?

Send variable from Visualforce to Apex and change page
Hello,
I'm having some trouble with my VisualForce page. What I'm trying to do is create a table that shows relevant objects and a button next to each object. When the user clicks the button, it should change to the next page and pass the Id of the object along.
Here's what I have so far...
Relevant Apex code from ReceiveInventory class:
I've got the page displaying the objects and the buttons fine, however, it doesn't do what expected. When I click a button, nothing seems to happen; however, looking at the debug log, I see the debug line from above ("Chosen Lot: xxxxxx"). When I click the button again, I get an error page saying "The page you submitted was invalid for your session. Please click Save again to confirm your change.".
I was trying to model my code a little bit after this link (http://bobbuzzard.blogspot.com/2011/07/passing-parameters-to-apex-method-from.html).
If anyone could chip in and suggest how I can fix this issue, it would be much appreciated.
Thanks in advance!
I'm having some trouble with my VisualForce page. What I'm trying to do is create a table that shows relevant objects and a button next to each object. When the user clicks the button, it should change to the next page and pass the Id of the object along.
Here's what I have so far...
<apex:page Controller="ReceiveInventory" showHeader="false" sidebar="false" title="Select Lot"> <div style="zoom:300%;"> <script> function confirmCancel() { var isCancel = confirm("Are you sure you wish to cancel?"); if (isCancel) return true; return false; } </script> <apex:form id="all"> <apex:outputText >Please select the lot you have scanned.<br /><br /></apex:outputText> <apex:pageBlock > <apex:pageBlockSection title="Lots" id="LotsTable" columns="1"> <apex:pageBlockTable value="{!lots}" var="lot"> <apex:column > <apex:commandButton action="{!step3}" value="Choose Lot" rerender="all"> <apex:param name="chosenLotParam" value="{!lot.Id}" assignTo="{!chosenLot}" /> </apex:commandButton> </apex:column> <apex:column value="{!lot.Name}" /> <apex:column value="{!lot.Quantity__c}" /> <apex:column value="{!lot.Date_Ordered__c}" /> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true" /> </apex:form> </div> </apex:page>
Relevant Apex code from ReceiveInventory class:
public with sharing class ReceiveInventory { public String chosenLot {get;set;} public PageReference step3 () { system.debug('Chosen Lot: ' + chosenLot); PageReference pageref3 = Page.ReceiveInventory3; pageref3.getParameters().put('chosenLot',chosenLot); return pageref3; } }
I've got the page displaying the objects and the buttons fine, however, it doesn't do what expected. When I click a button, nothing seems to happen; however, looking at the debug log, I see the debug line from above ("Chosen Lot: xxxxxx"). When I click the button again, I get an error page saying "The page you submitted was invalid for your session. Please click Save again to confirm your change.".
I was trying to model my code a little bit after this link (http://bobbuzzard.blogspot.com/2011/07/passing-parameters-to-apex-method-from.html).
If anyone could chip in and suggest how I can fix this issue, it would be much appreciated.
Thanks in advance!
I was researching sending information to a custom controller from Visualforce and saw that for some reason it needed to re-render a component on the page for the variable to actually pass through. I tried it both ways, and neither does what I want.
If I don't re-render anything, the page changes fine but the ID of the Lot does not go through.
If I do re-render an outputText panel, or the whole table as shown in my original code, I get my original problem - I get the variable assigned correctly, but the page does not change.
I'm hoping these provided logs may be able to clear something up.. I'm still at a loss as to why mine is not working like your example that you so kindly recorded.
Thank you again for your help and any further assistance.