It's not a secret anymore!*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "jsf navigation " Watch "jsf navigation " New topic
Author

jsf navigation

Viswanath Sriram
Greenhorn

Joined: Jul 20, 2006
Posts: 12
Hi,
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;
if(value=="")
{
alert('Please select an event to edit');
return false;
}
else
{
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:

MyMessages.properties:
faces-config.xml
[ October 11, 2006: Message edited by: Bauke Scholtz ]
 
Consider Paul's rocket mass heater.
 
subject: jsf navigation
 
Similar Threads
How to Call the Backing Bean Method from javascript in JSF
Stopping the onbeforeunload event
JSF Navigation issues
how to pass values in onclick method of <h:commandLink>
Check if updates were made before page unload