File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Why jsf form with javascript validation doesn Watch "Why jsf form with javascript validation doesn New topic
Author

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

Roman Pompka
Greenhorn

Joined: Jun 21, 2012
Posts: 1
Hi
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:


script.js:

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.

WP
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Yikes!!!

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).


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why jsf form with javascript validation doesn't forward the view?