• 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

Custom tags for INPUT elements - newbie question

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

I have a requirement to validate dates entered in a HTML INPUT element. I do not want to use client side javascript to validate the date entered. Instead, I'm contemplating on using a custom tag that basically validates (to see if it confirms to a certain pattern, locale etc) the date entered. Is this the right alternative to Javascript approach? Are there some articles/tutorials/examples that talk about writing custom tags for input elements?

Thanks in advance,

PJ
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not possible to use a custom tag for client-side validation. Any custom tags, along with any other JSP elements on your page, are executed to format the page before it is sent to the browser. So by the time your user is entering values into the input elements, these elements have long gone out of scope.

The only viable means to perform client-side validation is Javascript. Your only reasonable alternative is to perform server-side validation after the form data has been submitted back to the server.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. I should have noted that even if you do perform client-side validation, you should always also perform server-side validation even so.
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also note that even if you do use JavaScript for client-side validation you can't rely on it. JavaScript can be switched off in the client's browser or their user-agent may not support JavaScript. You should therefore also perform any validation you need at the server-side (unless you can guarantee the users' browser configuration, e.g. a small intranet).

I think that Apache Struts may include a framework for server-side validation, but I'm not sure. [edited: It does: Form Validation and Struts Validator

As an aside JSTL (JSP standard tag library) includes tags for formatting dates for presentation.

Jules
[ August 31, 2004: Message edited by: Julian Kennedy ]
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

for client-side validation you can't rely on it



Exactly my point. Look at client-side validation as a "user experience" thing -- it's there so that the user gets as immediate feedback for errors as possible.

But never rely upon it for true validation -- always validate the data on the server regardless of what the client does.
[ August 31, 2004: Message edited by: Bear Bibeault ]
 
pjoisha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Thanks for your responses.

I was indeed alluding to server-side validation. Basically, with custom tags I would end up doing only server-side validation. My pages will be devoid of Javascript - hence client-side validation. Having said this, what I was really looking for were JSF type of tags ... something like this



So, I want these tags to allow for my model update only if the date validation succeeds (like in JSF architecture) else throw an error

As I'm not in a position to adopt JSF techonolgy in my application, I'm in the lookout for such components

Thanks,
PJ
[ August 31, 2004: Message edited by: Prashanth Joisha ]
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Re-read my first response. Custom tag technology cannot help you here. Anything on the page is evaluated to create the page to send to the client. You should be handling the server-side validation in the servlet to which the form is submitted.
 
reply
    Bookmark Topic Watch Topic
  • New Topic