Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to validate (check) filelds with JSTL

 
Azz Romaysa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I know that the simple way to check fields of a form is with javascript. But I don't know if you also can doe that with JSTL.

If yes please an example.

Abu Romaysa
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSTL is server side stuff. it means that if some page has JSTL within it, it comes to client after doing all processing at server-side. and the client get a simple HTML page. similar to scriplets.

better do it with javascript on the client-side, and make sure to put validation at the server end as well. because never rely on just client-side validation.

cheers.
 
Chintan Zaveri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This one is old but I think, the question is still valid.

How can I validate form fields using JSTL?

I would like to remove all leading and trailing spaces and then perform validation such as:

1. Whether or not a parameter is empty
2. Whether or not a non-empty parameter has length X (e.g. 20 characters)
3. Whether or not the given email is a valid email (syntax-only)
4. Whether or not the given website URL is a valid URL (syntax-only)
5. Whether or not some field "abc" is checked.
6. Which of the given radio buttons are checked.
7. Whether or not there are any special characters in the given field (in such a case, I would like to give error)

I know this can be done using Javascript and Core Java and I am not interested in those solutions.

I did google for this before posting but couldn't find anything appropriate. Please let me know if I have overlooked something.

Thanks in advance and kind regards,

Chintan Zaveri.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65113
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chintan Zaveri:
Please let me know if I have overlooked something.
You completely overlooked Adeel's answer.

JSTL tags are evaluated on the server long before the resulting HTML page is being sent to the browser. Please see this article to correct your understanding of how JSPs work.

I know this can be done using Javascript and Core Java and I am not interested in those solutions.
Think again.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're after a pure Java solution, look for a MVC framework such as JSF or Struts. A decent MVC framework already ships with built-in validation techniques.

JSTL is just there to control the flow in JSP. Not for validation or so.

That said, for the best user experience, I would also add (yes, add) Javascript based validation, because this way the user will be saved from an extra request to the server side.
 
Chintan Zaveri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault:

I didn't really miss Adeel's reply - I was just a little too dumb not to think over it. :-( Thanks for the excellent article! :-)

Bauke Scholtz: Thanks for the encouraging post! Will use Struts.

Well, I just said "I am not interested in JS or Core Java solution" because I wanted to learn how this could have been done in JSP - maybe, using JSTL.

I am using Javascript, too.

Regards,

Chintan.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic