• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MVC form action problem

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic