tags:

views:

641

answers:

2

Hi,

I'm having a headache figuring how to retrieve the gwt Radio Buttons values in the server side.

Here is my UiBinder form:

<g:FormPanel ui:field="form"><g:VerticalPanel ui:field="fruitPanel">
    <g:RadioButton name="fruit">apple</g:RadioButton>
    <g:RadioButton name="fruit">banana</g:RadioButton>
    <g:SubmitButton>Submit</g:SubmitButton> ...

Here is how i initialize the form:

form.setAction("/submit");
form.setMethod(FormPanel.METHOD_POST);

So i though i would have to do this on the servlet:

fruit = req.getParameter("fruit")

But of course this doesn't work, parameter fruit doesn't exist :/

Edit: Ok i get parameter fruit but it's always "on"

I also did try to add the radio button in java with:

RadioButton rb0 = new RadioButton("fruit", "apple");
RadioButton rb1 = new RadioButton("fruit", "banana");
fruitPanel.add(rb0);
fruitPanel.add(rb1);

Edit: This is a GWT issue: Issue 4795

A: 

Hi Florian,

since I cannot comment on the question: Which version of GWT are you using?

I've create the exact same template as you did and Firebug tells me that it's posting:

"fruit=on"

Of course this payload is only posted when one of the checkboxes is checked. ;-)

But beware: I've recognized recently that GWT doesn't set the "value" of the radio button when used inside UiBinder template and instead just sends "on" as value which makes the radio button more or less useless to be used in a UiBinder template.

HTH Max

Makkes
Yep i did omit the panel in the FormPanel in my question, sorry.I'm using post, and my submit button is in the VerticalPanel.The servlet is reading the text boxes fine, but i can't seem to get the radio buttons.Also do you suggest that i should use java create the radio buttons, so i can then attach them to an UiBinder enpty panel?UiBinder is usefull for me as the form i'm dealing with are a bit large.
Florian d'Erfurth
It's working now, i had done some silly things in my servlet, though it's always "on" :/
Florian d'Erfurth
Phew, great! The thing with always "on" value really makes UiBinder useless for this use case. Trying to set the "value" via the g:RadioButton tag doesn't work since GWT then complains about ambiguous setters. Perhaps we should file a bug (http://code.google.com/p/google-web-toolkit/issues/list)?
Makkes
yes i guess that's an issue, would you like to post it?
Florian d'Erfurth
Done: http://code.google.com/p/google-web-toolkit/issues/detail?id=4795
Makkes
thanks a lot :) the weird thing is that it doesn't even work when i .add radio buttons to the VerticalPanel using java.
Florian d'Erfurth
You've got to set the value explicitely since the constructor RadioButton(String, String) doesn't do this. Do this:rb0.setFormValue("apple");rb1.setFormValue("banana");Annoying, really!
Makkes
OMG annoying indeed. thanks you for your answer ;)
Florian d'Erfurth
A: 

NO, no, no, no. This is not JSP, buddy!

Seems to me that you have a lot of documentation reading to do about how GWT works. This I cannot make clear in one answer post, but to start somewhere:

1) You are not running your code on the server, this is client side! 2) You should use GWT RPC to transfer data to/from the server 3) RTFM :)

Jeroen
He doesn't have to use RPC to transfer data to the server - POST/GET to a servlet is just as viable (and sometimes, when dealing with external apps, etc, it's the only way). And he seems to know what he's doing - he's posting the values from a form (FormPanel) to a servlet - what part of that is wrong?
Igor Klimer
Absolutely, I'm using a servlet also because i'm using blobstore in other forms.
Florian d'Erfurth