You need to sign in to do that
Don't have an account?
eriktown
Form button not executing its action
Hello all!
I have a visualforce page that has a user pick something from a selectList, then calls an Apex method called doSelect when the user hits the button on a form. However, for some reason the method isn't getting called when the user presses the button. I'm guessing I've made a mistake in the visualforce code somewhere, but I can't spot it. I'm a little suprised as I've done this many times before.
Here's the code:
<apex:page controller="PickerCon" action="{!autoRun}"> <apex:sectionHeader title="Purchase"/> <apex:outputPanel id="msg"> This item will be sent to: <apex:outputText value="{!email}"/> <apex:form > <apex:pageBlock mode="edit"> <apex:pageblockSection title="Select an Item"> <apex:selectList value="{!selecteditem}"> <apex:selectOptions value="{!items}"/> </apex:selectList> </apex:pageblockSection> <apex:pageBlockButtons > <apex:commandButton value="Purchase" action="{!doSelect}" rerender="msg"/> <apex:commandButton value="Cancel"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:outputPanel> </apex:page>
Perhaps try:
I noted that the Controller you named in the page was PickerCon, and your actual controller class was: TCCardPickerCon
So, I'm surprised you were even able to save your class without errors. the obvious thought is you have another class called PickerCon out there, and it doesn't have a debug statement in it? :-)
Best, Steve
All Answers
Hi,
Do you suppose to pass the selected value from the pick list to the controller method?
If it is Yes, You need to use the <apex:param> and pass the parameter.
What is the functionality of doSelect method?
If you can post your controller. Then it will be easy to understand the issue.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
It looks pretty basic, and pretty correct to me at first read through.
I'd add layout="block" to the outputPanel (just to be cleaner), and you have no Cancel action defined. You might also add a <apex:pageMessages /> to the page.
And, if you're reRendering msg, do you really want msg to cover the entire page, or just that top outputpanel?
But putting those aside, I can't see any reason doSelect wouldn't even be invoked. I presume you're reading that from the debug log? Clearly we have no idea what it's supposed to be doing, but not even called here seems wierd.
Best, Steve.
So something like this?
I tried that, but it did not fix the problem. The problem is that doSelected is not being executed at all - I can see from the debug output that the method is never being called.
Here is the controller code:
As you can see I have a debug message at the entrance to the doSelect method. Since that debug message doesn't appear in the logs I am forced to conclude that the method simply isn't being run for some reason.
Thanks for your help!
Steve - I don't want to rerender anything at all; actually what I want to do is go to another page, passing some information from this one in the query string. However, I remember reading somewhere that params don't get sent if you don't have a rerender tag in there. That's the only reason it's there.
Perhaps try:
I noted that the Controller you named in the page was PickerCon, and your actual controller class was: TCCardPickerCon
So, I'm surprised you were even able to save your class without errors. the obvious thought is you have another class called PickerCon out there, and it doesn't have a debug statement in it? :-)
Best, Steve
Actually I was trying to be stealthy and give my classes generic names, and I forgot to rename that one. The class name is consistent in the original code. :)
Steve, your code works - thanks! However, I'm wondering if there is still a way that I can print the email address when the page is loaded, as in my original version?
stealthy... :-) I'm still not sure what was wrong with your original code... I edited my solution to output the cemail. You don't even need to involve the controller in this.
Also, it's a good idea (often anyway), to use a standard controller and write your stuff as a controller extension. That way you get freebies like {!cancel} for free. Sure, sometimes you just want a totally standardalone controller... but sometimes it's nice to have the help.
Best, Steve.
Oh, perfect. This has been a very educational exchange for me; I'm just taking my first steps in Salesforce development.
Steve, thank you very much for your help, your excellent and thorough responses not only solved my problem but give me a better understanding of how this is all supposed to work. I've been really impressed with the community support here on the Developerforce forums, and you exemplify it.
Happy to help, especially with a lucid question from someone who obviously tried to solve it themselves before asking for advice. Best, Steve.