• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsf navigation

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();"
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic