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

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

 
Roman Pompka
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic