• 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

Spring MVC validation problem using form:form pr spring:bind

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I have a form that is contained in a banner on all of the pages on my site. The problem is using the form tags or bind tags. If i use them, they are looking for the commandName associated with the page it is contained in instead of the commandName associated with that page.

The form in is included on each page by a jsp:include tag. I'm not sure what it is using the commandName of the main page when the form is in the included page.

Any help is greatly appreciated.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lisa, I had the same problem on my site.

Basically when the page loads it will look for the property on the command object, so the property that you are binding to has to be in that command. Because that property is in the header and used by all pages you can safely say that it is part of each command so create a common command class with that property and extend it with each of your command classes.

The second problem is that of naming. If you give your command a name then you need to access it by its name

<spring:bind path="myCommand.propertyName">
if you don't you can access it using the default name
<spring:bind path="command.propertyName">

So don't name your command and let all your pages bind using the default name 'command'.

I hope this makes sense.

One other thing, in Spring 2 which is fully backward compatible you don't need to use the bind anymore, they have given you a heap of tags which make life a lot easier and reduce the amount of lines in your jsp code tremendously.

Eg, going by the above example:
<c:out value="${command.propertyName}"/> no binding needed.

Have a look:
http://static.springframework.org/spring/docs/2.0.x/reference/mvc.html#mvc-formtaglib

Hope this helps.

Shawn
http://www.whatjar.co.uk
 
Lisa Carter
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help. It makes a lot of sense.
 
Lisa Carter
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok that worked, but how did you do your validation? I see the bind errors on the command line but the actual messages don't show int he jsp. I did a but I did do a c ut to see if the errors are there, and they were they just didn't show up. I'm using springs <form:form> taglib
 
reply
    Bookmark Topic Watch Topic
  • New Topic