You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Henry Chang <he...@hotmail.com> on 2008/07/08 05:31:21 UTC

How to validate a

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

Re: How to validate a

Posted by Mike Kienenberger <mk...@gmail.com>.
If you programmically create a message, you either need to assign the
"table" client-id to the message (instead of null) or you need to
display global messages and not just "table" messages.

On 7/8/08, Henry Chang <he...@hotmail.com> wrote:
>
>
>
>
> Hi,
>
>
>
> Thank you for your suggestion. Then how could I display the error message on
> the screen? I tried to use <tr:message> but it does not display anything.
>
>
>
> <tr:commandButton id="table" text="Next" action="#{BackingBean.next}" />
>
>  <tr:message for="table" />
>
>
>
>
>
> Henry
>
>
>
>
>
> From: Guy Bashan [mailto:guy.bashan@gmail.com]
>  Sent: Tuesday, July 08, 2008 3:49 PM
>  To: 'MyFaces Discussion'
>  Subject: RE: How to validate a <tr:table>
>
>
>
>
> 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:henrychang04@hotmail.com]
>  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

RE: How to validate a

Posted by Henry Chang <he...@hotmail.com>.
Hi,

 

Thank you for your suggestion. Then how could I display the error message on
the screen? I tried to use <tr:message> but it does not display anything.

 

<tr:commandButton id="table" text="Next" action="#{BackingBean.next}" />

 <tr:message for="table" />

 

 

Henry

 

From: Guy Bashan [mailto:guy.bashan@gmail.com] 
Sent: Tuesday, July 08, 2008 3:49 PM
To: 'MyFaces Discussion'
Subject: RE: How to validate a <tr:table>

 

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:henrychang04@hotmail.com] 
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


RE: How to validate a

Posted by Guy Bashan <gu...@gmail.com>.
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:henrychang04@hotmail.com] 
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