You need to sign in to do that
Don't have an account?
forcewithu
The code shown includes the Select commandButton that works well. But I’ve tried every event I could think of in both the actionSupport and selectRadio tags: onChange, onClick, onSelect, you name it. None of them will fire the getContactInfo action to rerender the page. If you select a radio button and do NOT click on the Select button, it still captures the information for further processing. I just can’t get it to rerender the outpanel so the user can see the additional contact information.
Can't get radio buttons to rerender
I’m having a problem getting my Visualforce radio buttons to work as designed in a wizard.
The original design was to have a table with multiple rows where the first column was a radio button and the subsequent columns were various fields associated with a particular contact. The idea was that someone could use the information displayed on each row to select a contact for use on subsequent pages. I discovered that it wasn’t really possible to split up the radio buttons for use on different table rows using Visualforce.
So, I went to a backup plan to display a group of radio buttons along with the name of the associated contact. Below the group of buttons is a table to display the other information for the selected contact. The desired behavior is to have the contact’s information automatically display when selecting the radio button. I can get it to display when using a Select button (CommandButton), but I can’t seem to get the radio buttons to fire an event that I can use to re-render the table.
I’ve gone through multiple designs and am currently attempting a hybrid of one suggested by an instructor after the original one didn’t work. Because selectRadio doesn’t have a rerender attribute, he suggested that I use actionSupport to add that functionality.
Here’s the Visualforce code for the radio buttons as it currently stands:
Code:
<apex:pageBlockSection title="Select Contact"> <apex:selectRadio id="Contact_Selection" value="{!ContactAssignment}" layout="pageDirection" onchange="{!ContactInfo}" immediate="true" required="true"> <apex:selectOptions value="{!ContactList}"> <apex:actionSupport event="onchange" action="{!getContactInfo}" reRender=”out" status="status" immediate="true"/> </apex:selectOptions> </apex:selectRadio> <p/> <apex:commandButton value="Select" action="{!getContactInfo}" rerender="out" status="status"/> </apex:pageBlockSection>
The code shown includes the Select commandButton that works well. But I’ve tried every event I could think of in both the actionSupport and selectRadio tags: onChange, onClick, onSelect, you name it. None of them will fire the getContactInfo action to rerender the page. If you select a radio button and do NOT click on the Select button, it still captures the information for further processing. I just can’t get it to rerender the outpanel so the user can see the additional contact information.
All I need to do is find a way to get the selection of a radio button to execute getContactInfo the way the Select button does.
Try taking that out.
:smileysad: I was afraid you'd ask that. (sigh) I'm so embarrased by this code. I didn't even know what Salesforce WAS about 6 weeks ago, so I was really floundering and learning by error as I tried to code something designed by someone else.
Anyway, here's the controller:
Now for the Visualforce page:
That being said, a few suggestions. First, why does getContact() return a list when you know there's only going to be one contact?
Is that just because you wanted it displayed in table format? (Hint, pageBlockTable would probably be better if you are going to use a dataTable in a pageBlock, but that does not matter to your particular problem. Also look at headerValue and value on column).
Also there is no need for you to have an action on your actionSupport component. It's not doing anything, just returning null. That's what it will do if you don't specify an action. Again just a suggestion to clean things up, should not change behavior.
But, have you put a System.debug in your setContactAssignment and verified that your setter is actually getting called on change?
I made a very simple page with a selectRadio component that updates an outputPanel with the value that was selected and that worked fine, so I know actionSupport with onchange will work.
Sorry to keep the back and forth going. But if you can try to see what's going on with System.debug statements, that will help a lot towards figuring out what is going wrong in your page.
Sorry for the overload of code, Jill. I thought you wanted to see everything, since I'd previously sent the most relevant snippets. Thanks for the suggestions to improve my code. As I said, this was something done by someone with NO Salesforce experience in just a very few weeks; so I'll take all the helpful suggestions I can get. :smileyhappy:
As for the System.debug, all it did was verify what I already knew: no event is firing when a radio button is selected. That's my whole problem. No matter what I do with actionSupport, I can't seem to get it to actually fire an event. As soon as I click on the Select button, an event is fired and everything works as desired. If I could just get an event (ANY event) to fire when the user clicks on a radio button, I can design the code to handle whatever event that is. But thus far, NO EVENT fires.
Could you possibly send your snippet of code that works? I have no problem reengineering my code to work with something that works. Until I can find some code that causes an event to fire, I'm kind of at a loss.
John
FOUND IT!
I needed to move the actionSupport tag up one level. Instead of being a child to selectOptions,
it needed to be a sibling (child of selectRadio). So, it needed to look like this:
Thanks for your help!
-John
Just so you know the requirement that we maintain the flexibility of apex:actionSupport has tripped up a ton of folks (my own team on occasion) because of the spatial relationship between the apex:actionSupport component and the component it is enhancing. We're looking at things like providing more built in event-to-action attributes on components like apex:selectRadio in the future to remove this very common error condition.