It's not a secret anymore!
The moose likes JSF and the fly likes Why jsf form with javascript validation doesn't forward the view? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Why jsf form with javascript validation doesn Watch "Why jsf form with javascript validation doesn New topic

Why jsf form with javascript validation doesn't forward the view?

Roman Pompka

Joined: Jun 21, 2012
Posts: 1
I'm running a JSF 2.0 application on Tomcat 7. I want to use javascript for form validation. Here is a simplified version of my problem:

I have two jsf files index.xhtml and result.xhtml and one file with javascript code. Both xhtml files are in apps root folder.
In index.xhtml:


The content of result.xhtml is insignificant. When I run this index.xhtml I get what I expected. When I fill the textboxes with the same values and click the button the checkPassword function is triggered but the browser stays on index.xhtml and I want it to forward to result.xhtml. What am I doing wrong? I'm interested not only in a walkaround but in a reason why it's not working. Can you help me?
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

I think this is your problem.

JSF generates its own ids.

In your case you are using "form" as the id of the <h:form>.

I would look at the HTML source and see exactly what the id is.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417


Are you really storing a copy of the password right on the web page???

I've seen some really insecure apps, but that approach would win prizes. You could give LinkedIn and Twitter a run for their money.

Anyway, as William pointed out, there are 2 different "id" values. One is the JSF id attribute value and the other is the generated HTML id value. JavaScript must use the generated value, which is synthesized by concatenating the ids of the "naming container" elements (a JSF form is a naming container).

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Why jsf form with javascript validation doesn't forward the view?
jQuery in Action, 3rd edition