• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

How to set default values in an spring form input?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I add a default value to a spring-based form:input control?
I am using spring-form.tld tag library for binding my user input controls to command object.


I tried to modify the above code to:

But the form:input does NOT allow "value" attribute.

Please advise.




 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can define this property by editing command object in the controller.
To be more exact I need to see your controller method.
 
Aakash Chandel
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Boris Romashov wrote:You can define this property by editing command object in the controller.
To be more exact I need to see your controller method.



I got the issue resolved by initialing command object properties with default values.

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

Boris Romashov wrote:You can define this property by editing command object in the controller.
To be more exact I need to see your controller method.



I'm currently having the same problem and the solution provided seems ok but that implies everytime the default values will be the same.
I need to show values from a database in the corresponding inputs. The purpose is to allow the user edit the values previously captured.
Is that possible? What do you mean by editing the command object?

Thanks in advance
 
Boris Romashov
Ranch Hand
Posts: 38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

obed morton wrote:that implies everytime the default values will be the same.
I need to show values from a database in the corresponding inputs. The purpose is to allow the user edit the values previously captured.
Is that possible? What do you mean by editing the command object?


"editing the command object" captures your case very easy (in opposite to post author's solution).
I show you how controller should look in spring-3.0 (using annotations).


Controller method has an argument bill that will be passed to a form (it's called command object).
You can prepopulate it here.
As controller is a usual spring bean you can easily autowire other beans to it and prepopulate with some values from business-logic.
 
obed morton
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot.

Now thats using annotations. Im new to spring so Im having hard time using them, will try that solution though but that takes me to another question do i need to name my method 'createGET'? im trying to understand the order in which the methods are called so that one is called before the jsp is rendered? I was thinking one of the following colud help me initApplicationContext
onBind
initBinder

thanks again

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

obed morton wrote:Thanks a lot.

Now thats using annotations. Im new to spring so Im having hard time using them, will try that solution though but that takes me to another question do i need to name my method 'createGET'? im trying to understand the order in which the methods are called so that one is called before the jsp is rendered? I was thinking one of the following colud help me initApplicationContext
onBind
initBinder

thanks again



You haven't used Annotations in Java before, they aren't a Spring specific thing.

Anyway, it is much better with Annotations because your classes can now be true POJOs with no classes to extend or interfaces to implement from an api or framework., So no need for initApplicationContext, onBind or initBinder requirements.

Mark
 
obed morton
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Due to the fact I started using SimpleFormController for most parts of my project I decided not to include Annotations (I'm not sure you can even mix them but I guess that would ruin the meaning). So for now I managed to modify the bean defalut values by using a formBackingObject http://maestric.com/doc/java/spring/mvc and it works

Mark Spritzler wrote:
You haven't used Annotations in Java before, they aren't a Spring specific thing.

Anyway, it is much better with Annotations because your classes can now be true POJOs with no classes to extend or interfaces to implement from an api or framework., So no need for initApplicationContext, onBind or initBinder requirements.

Mark



You're right, while looking at samples, tutorials and the documentation I've seen that Annotations is the way to go with Spring so I guess that's the next thing on my to do list

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic