The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

joshbay84 (4) [Avatar] Offline
#1
I have a FormPanel like
loginFormPanel.setAction( GWT.getModuleBaseURL() + "/usermanagement" );
loginFormPanel.setMethod( FormPanel.METHOD_POST );


The declaration in the gwt.xml is as below:
<servlet path='/usermanagement' class='com.my.tet.server.UserManagementServlet'/>

UserManagementServlet is a normal HttpServlet not the one provided by GWT as shown below:


public class UserManagementServlet
extends HttpServlet
{
public void doPost( HttpServletRequest req, HttpServletResponse res )
{
Enumeration reqParams = req.getParameterNames();

while( reqParams.hasMoreElements())
{
Object obj = reqParams.nextElement();//This is never executed
System.out.println( "element : " + obj );
}

}

}


The issue that I am facing is that req.getParameterNames() returns null.
I am not sure how to get the request parameters since all I have done is placed one widget after another on a VerticalPanel and then added it to the FormPanel, so in request.getParameter("name"), what would be the name parameter?

Also, is there any way by which we can call a particular method of GWT Servlet from the submit action of FormPanel ?
joshbay84 (4) [Avatar] Offline
#2
Re: FormPanel
Got that to work, problem was that setName method on the widgets were not called and hence no parameters were sent.

But now I have another query, I am not able to call GWT servlet directly using below:
loginFormPanel.setAction( GWT.getModuleBaseURL() + "/usermanagementservlet" );
loginFormPanel.setMethod( FormPanel.METHOD_POST );


because I do not know which method will be called on the servlet. I cannot override doPost because it is final in RemoteServiceServlet.

If there is no way to call this servlet using above methods of FormPanel, then I guess FormPanel is used only to submit request to normal Servlet and not gwt one.

Please let me know if I am doing something wrong?

Regards,
Joshua.
robert.hanson (173) [Avatar] Offline
#3
Re: FormPanel
You can't target a RemoteServiceServlet with FormPanel, it must be a regular servlet, and you would need to override doPost().
jcmorris-mts (4) [Avatar] Offline
#4
Re: FormPanel
Rob et. al.

So, if I understand this thread correctly, one can :
a) Use widgets on regular panels to make some kind of GUI and tie it to the server via a RemoteServiceServlet or
b) Use a FormPanel and tie it to a plain HttpServlet and override doPost().

When would you choose to do one over the other, assuming that both are creating a GUI for submitting form data?
robert.hanson (173) [Avatar] Offline
#5
Re: FormPanel
Right. As far at when to use which, it is just a matter of taste. If it makes more sense in you application to use a regular servlet, then go for it, especially if it helps simplify the application. There is no right or wrong way.