Hi,
Why not just writing the validation code in the action of the command
button?
<h:commandButton value="next" action="myBean.next" />
And in the bean:
..
..
public String next()
{
If (rowSelected != null)
{
return "next";
}
else
{
FacesContext.getCurrentInstance().addMessage(
null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Select row",
"Select row"));
return null;
}
Guy.
From: Henry Chang [mailto:[EMAIL PROTECTED]
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