• 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

String to Date

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Lets say I have a form bean with an attribute as a String and tomorrow if they decide that the attribute should be changed to date , if I change the attribute to Date, does struts handle automatic conversion on the UI ? else should I do this conversion in the Action class tooo???
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, if you change the form variable to be a DATE, i dont see any reason for you doing the conversion. When you access the variable from the form, it will be a date ( guessing a valid date was entered, but i do wonder about the outcome of the conversion if an invalid entry was made).

I do not see any necessity of doing a conversion, as long as a valid date gets entered

BTW, do you get the conversion working fine ( string to date ) ??
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, Thx for the reply.....it need not be a String to Date ...it can be String to int too....am asking for a clarification...what I understand is..

When a form is submitted...all the values go as String..(request.getParameter() ).I want to know if Struts converts the form parameters according to the Data type required in the formBean...if thats the case, Can change the datatype for the formBean without affecting the UI display as well as making no changes for the data type conversion in my utils or Action classes???
 
Vicky Mohan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String to int --> it definitely will work ( as long as the value is a numeric). I have used it in lots of occasions. I just try to use that in occasions when i think there is no scope for conversion error. But if there is no value, it will be defaulted to 0 ( for int conversion).

Now to answer your question, Struts does attempt to do an automatic conversion and formbean will be automatically loaded with appropriate datatype. So, you dont have to do any conversions. Besides,I dont see any changes in UI as all values are String over there ..

Hope this helps.
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx Vijay...it helped me a lot
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic