• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hour check in an inputText

 
Alessio Belcastro
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,
I have an inputText where the user must insert an hour in the format HH:mm (so with the hours within 00 and 23, not AM-PM). I've tried two ways to check what the user enters:
1) Using convertDateTime:

It works for the checks on the hour, but the value of "time" (which is defined by me as a String type) in the bean is not saved as HH:mm but as a full datetime, like "Monday, May 14, 2007 2:39:56 PM" (I've also tried using timeStyle="short" instead of defining the pattern)
2) a Javascript control. The check works, if you type the hour in a wrong way you get an "error" alert, but then the page sends you to another page as specified in the commandLink action, as if the control hadn't been elaborated (as if the JSF part has an "higher priority" compared to Javascript)

I'm italian and I've started using JSF a week ago so I'm not very skilled about that...please, answer in a simple wayyy! Thank you
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Alessio! Benvenuto!

You will have better fortune, I think if you make the "export.time" property be a java.util.Date object instead of a string. This will require some back-end Calendar logic to get/set the String version of the date, but it will interact better with the JSF date formatting and conversion functions.
 
Alessio Belcastro
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your welcome! Grazie
Oooh, I didn't think about that! I've tried right now and it's working perfectly! I just had to convert to and by string as you said and to put the "HH:mm" pattern in the outputTexts to make it show just the hour and it's correct now! Thank you so much for your help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic