myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Bashan <>
Subject RE: How to validate a <tr:table>
Date Tue, 08 Jul 2008 07:48:45 GMT


Why not just writing the validation code in the action of the command


<h:commandButton value="next" action="" />


And in the bean:




public String next()


  If (rowSelected != null)


    return "next";





        null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Select row",
"Select row"));

  return null; 






From: Henry Chang [] 
Sent: Tuesday, July 08, 2008 6:31 AM
To: MyFaces Discussion
Subject: How to validate a <tr:table>


Hi, I've got a simple question regarding to validating <tr:table> component.
I just want to make sure that at least one of the rows in the table are
being selected before proceeding to the next page, after pressing the submit
button. I have validation code like this:


private CoreTable product;


public void validateToCart(FacesContext context, UIComponent toValidate,
            Object value) throws ValidatorException {
        Iterator selection = product.getSelectedRowKeys().iterator();
        if (!selection.hasNext()) {
            FacesMessage message = new FacesMessage("No items selected!");
            throw new ValidatorException(message);



How do I call this method from the page? I found that there is no validator
attribute in the <tr:table> component nor in the <tr:commandButton>
component. Thanks.


Best Regards,

Henry Chang

View raw message