aspose file tools*
The moose likes Other Application Frameworks and the fly likes MVC form action problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "MVC form action problem" Watch "MVC form action problem" New topic
Author

MVC form action problem

Dan Field
Greenhorn

Joined: Mar 13, 2009
Posts: 8
I am very inexperienced MVC and Java in general, and I am struggling with a form problem.

The problem is that the form call below works, but not in all cases. It seems some browsers don't like the empty actions.



I have the class Confirm in a file called Confirm.java that should populate each field.




And I have another class called ModelAndView onSubmit which handles the request.



But what should I call for the action when I can't leave it empty?
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Hey Dan,

I assume you are using SimpleFormController(Spring Ofcourse). In that case you ought to set formview and successview.
How does your this page gets loaded for very first time(URL Handler Mapping)? What's that ? The same should goes into your action attribute of Form tag. eg. invoice.jsp
I am wondering your all form fields are hidden.
(Provide us more detail.)
Dan Field
Greenhorn

Joined: Mar 13, 2009
Posts: 8
Hi Vishal,

The formView is set as confirmSP.jsp. There is no successView that I could find.

I tried adding that as the action, but then the hidden information in the form doesn't seem to be passed correctly.

The hidden information needs to be available for the onSubmit function. So a user will simply click on the submit button and the information is passed.

The handler mapping is:



The onSubmit function is in the confirmSPFormController.java.
Rosco Duncan
Ranch Hand

Joined: Apr 23, 2007
Posts: 41
Just a thought Dan, but you currently are setting action=""

What happens if you leave out the action attribute altogether?

When I do that, Spring automatically generates one for me that gets me happily into the appropriate controller method. It ends up lookng like this when generated:



I have a controller the looks like this (using spring 2.5 and attributes):

Dan Field
Greenhorn

Joined: Mar 13, 2009
Posts: 8
I tried removing the action, but this caused an exception as an action is mandatory.

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/prodwcb2].[jsp]] Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /confirmSP.jsp(40,0) According to the TLD or the tag file, attribute action is mandatory for tag form
Rosco Duncan
Ranch Hand

Joined: Apr 23, 2007
Posts: 41
Hmmm,

I guess you must have a different version of something around the tab lib.

What happens if you set the action=confirmSP.do

Im assuming confirmSPFormController contains the submission hander method where you are hoping to see your hidden fields populated?
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Hello Dan,

Your action should be same as handler mapping as pointed out by Rosco. i.e confirmSP.do. Everything else looks good.And action attribute is mandatory.
Dan Field
Greenhorn

Joined: Mar 13, 2009
Posts: 8
I tried adding confirmSP.do as the action.

Doing that led to a problem with the formBackingObject. The data that is meant to be set in formBackingObject (in the confirmSPFormController class) for the ConfirmForm object is all null.

So with a newer browser and action="" this isn't a problem, but with an older browser when setting action="confirmSP.do" the formBackingObject is broken.

I hope this makes sense, I'm learning about this all as I look into this code.
Rosco Duncan
Ranch Hand

Joined: Apr 23, 2007
Posts: 41
Hi Dan,

Ive just been looking back at the step-by-step example for Spring MVC.

If you havent taken half a day to walkthrough this, I would thouroughly reccommend it to you.

Anyhow, I find http://static.springframework.org/docs/Spring-MVC-step-by-step/part4.html#step4.5 interesting. Note here they are using Spring MVC in a very straight forward manner - no annotations or other trickery. The <form:form> tag does not include the action at all. Its not mandatory for Spring, but probably for HTML. Im guessing Spring generates this.

Also look at the way the controller is configured and coded (here). Note that they are setting sessionForm to true, and specifying the command class. (you are probably doing somethign like this already). In the java for the form controller the method formBackingObject initialises the command object.

Im not sure which bit of the puzzle you are missing, but if you arent making progress, I would get this walkthrough working and compare it to what you have got. If you havent already, the experience is well worth the effort.

Hope that helps.

Rosco
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Dan,

I was looking at the jsp that you have provided in very first post. You don't have spring binding. I am sorry I forgot to point out that thing in the beginning. Using Spring binding, you bind your command class with html components.And this is how your command class (ConfirmForm, in your case) gets populated. For example,



I am just curious which tag library you are using.

Doing that led to a problem with the formBackingObject. The data that is meant to be set in formBackingObject (in the confirmSPFormController class) for the ConfirmForm object is all null.

Right now let's don't worry about formbackingobject.

So with a newer browser and action="" this isn't a problem, but with an older browser when setting action="confirmSP.do" the formBackingObject is broken.

What do you mean by older/newer browser? It doesn't depend on browsers.
Dan Field
Greenhorn

Joined: Mar 13, 2009
Posts: 8
The taglib is called Wall.

When I say browser, in this case I'm talking about mobile phone browsers. Mobile phones tend to have different browsers, but the taglib wall should handle this.

I've found that in this case wall actually does something I didn't know about. I tried calling confirmSP.jsp from a standard browser that I can check the source code with, and wall is populating the form action.

So I now think that this problem is to do with the wall taglib not dealing correctly with the mobile phone browser type.

Initially when I said at the start of this thread that the code had action="", this was incorrect as I didn't realise the wall taglib was changing it. Or possibly it was correct and because wall was failing the action was being left empty...

Thank you for the help Vishal and Rosco. I think I need to start looking at whats going wrong with the wall taglib as the error is more likely to lie there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC form action problem