This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Can javascript function set value of a form bean property?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic