File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes jsf navigation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "jsf navigation " Watch "jsf navigation " New topic

jsf navigation

Viswanath Sriram

Joined: Jul 20, 2006
Posts: 12
I want to do validation.When i click the commandbutton some validation should be done here.depending on that the action should be done.But if the function is returning false also the the form is calling the backing bean.I should stop that action if the function return false.
Is this the correct way

function check()
var value=document.getElementById('form:field1').value;
alert('Please select an event to edit');
return false;
return true;
h:commandButton value="Edit" action="#{bean.method}"
onKlick ="javascript:check();"
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Wheter it is the correct way or not is up to you.

Generally you have 3 possibilities to do validation:

1) Create a Validator class implementing javax.faces.Validator. Then refer to this validator using the f:validator tag nested in a UIInput component (or the validator attribute of the UIInput component).

2) Do the validation in the backing bean. For example:

3) Use JS like you did.


Or, in case of required values, just add the required attribute to the UIInput component as following:By default an error message "Validation Error: Value is required." will show up in the h:message. This is customizable as follows:
[ October 11, 2006: Message edited by: Bauke Scholtz ]
I agree. Here's the link:
subject: jsf navigation
jQuery in Action, 3rd edition