• 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

Can javascript function set value of a form bean property?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My JSP presents a bunch of text boxes. When user submits the JSP, I need to generate a date/time string and insert the info frm the text boxes + this date string as a new record in my DB.
I have a form bean that has getter and setter methods for text box elements and date_time ( -- a hidden field on the JSP )

JSP Submit:

Javascript:


In regular JSP/Javascript, I would have done:

But here since the form bean is associated with the form elements, when I want to set the value for a form bean property, what shd I do? Is this even possible frm a Javascript function??
Please help.
Thanks
-- $uDhA
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Setting the form bean property is not done on the server side when the request is posted. The form bean properties will be set even if you use plain html inputs with names corresponding to the bean property.
We change the values of the inputs via JS all the time. <html:text ...> will generate an input tag with the name specified. Then you just set the value of that element and submit the form! Do not forget to submit the form in you JS when using an event like onSubmit="yourFunction()"
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sudha,
The right way to do it would be to add the date time stamp in your service layer if you are using the jsp->action->service->dao layers or atleast in the action layer. Avoid doing this in the jsp if you can. Your peers will not be expecting to look for business logic in the jsps if someone else wants to maintain your app, the will look for the service layer or at least the action layer.
Thanks
Sahil
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your form class, you can initialize a current datetime on the date_time.
date_time = ....;
public String getDate_time() {
return this.date_time;
}
You don't want setDate_time function if you don't want to set it.
 
Sudha Joish
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the replies.
JSP --> Action --> Service
I added a function to generate date_time in the Service class. This returns date_time to Action, which then sets the property.
Works like a champ.
Thanks again for all the useful pointers.
-- $uDhA
reply
    Bookmark Topic Watch Topic
  • New Topic