This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsf navigation

 
Viswanath Sriram
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic