Search code examples
javagwtgwt2

getvalue of check box on server side in GWT


I am using GWT. I have a chkBox and fileupload which are added to formPanel.

after formPanel.submit();

On Server Side

I want the value of chkbox

so

if (item.isFormField()) {
        if (item.getFieldName().equalsIgnoreCase("chkbox")) {
                        chkbox= Streams.asString(item.openStream());
                    }

                }

when chkbox.getvalue is true , the value on server side is On and chkbox.getValue is false the i get null on the server side.

i need the values of chkbox so that i can perform operation on file depending on the value of chkbox


Solution

  • "On" is the default value of a checkbox when no form value has been provided.

    That value will only be sent to the server if the box is checked (absence of the field means it was unchecked): http://www.w3.org/TR/html5/form-submission.html#constructing-form-data-set

    If you really want to send anything else, then don't give your checkbox a name and instead use a Hidden field that you update using a ValueChangeHandler on the Checkbox.