PDA

View Full Version : Retrieve HiddenField value on server side



ravi.m183
1 Feb 2010, 11:37 PM
Hi,

In one of my modules I am using HiddenField which is added to a FormPanel. I am submitting the FormPanel and it gets submitted to a HttpServlet. I want to retrieve the value which is set in the HiddenField.

My client side code is:



FormPanel formPanel = new FormPanel();
formPanel.setFrame(false);
formPanel.setBodyBorder(false);
formPanel.setHeaderVisible(false);
formPanel.setAction(GWT.getModuleBaseURL() + "excel-upload-service");
formPanel.setEncoding(Encoding.MULTIPART);
formPanel.setMethod(Method.POST);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);

HiddenField<String> hiddenField = new HiddenField<String>();
hiddenField.setId("hiddenField");
hiddenField.setValue("12345");

formPanel.add(hiddenField);
//On action submit the form
formPanel.submit();
I am trying to retrieve the value on the server side as follows:



public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

try
{
String value1 = req.getAttribute("hiddenField");
String value2 = req.getParameter("hiddenField");
}
}
I tried accessing both value1 and value2, but both are null values.

Can anyone please help?

Thanks
Ravi

micgala
2 Feb 2010, 2:30 AM
Hi.

getParameter is the right method.

But, instead of setting this:

hiddenField.setId("hiddenField");set this:

hiddenField.setName("hiddenField");

Regards,
Michel.

ravi.m183
2 Feb 2010, 3:17 AM
Hi,

I tried using hiddenField.setName("hiddenField");

But still it gives me a null value on the servlet.

Ravi


Hi.

getParameter is the right method.

But, instead of setting this:

hiddenField.setId("hiddenField");set this:

hiddenField.setName("hiddenField");Regards,
Michel.

appamail@hotmail.com
2 Feb 2010, 10:10 PM
If you need not to upload files.

Use


formPanel.setEncoding(Encoding.URLENCODED);

For the diffence, please google "multipart/form-data application/x-www-form-urlencoded"

;)

jmhwhite2001
18 Feb 2010, 11:34 AM
I'm having the same issue. I want to pass an object from a GXT app to a servlet and have it read. The object is of the type I've specified.

Thanks!