You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Newham, Cameron" <ca...@bl.uk> on 2009/09/24 10:41:06 UTC

Validation on textfields in a grid?

I could have sworn I had this working at one point, but now it doesn't.

 

Tml:

 

<table t:type="grid" t:class="topgrid" t:source="allKeywords"
t:rowIndex="rowIndex" t:row="keywordVisual"
t:add="nsBases,spacer,tag,attribute,attributeVal,keyword"
t:reorder="booleanOp,useNSTag,nsBases,tag,spacer,useAttribute,attribute,
attributeVal,keyword,remove"
t:exclude="inverseUseNSTag,inverseUseAttribute">

 

...

 

<t:parameter name="keywordCell">

<t:textfield size="40" t:id="keywordField"
value="keywordVisual.keyword.value"/>

</t:parameter>

 

...

 

 

The Java:

 

...

 

@Component

private TextField keywordField;

 

...

 

 

public void onValidateForm()

{

            if (keywordVisual.getKeyword().getValue() == null)

            {

                        tagForm.recordError(keywordField, "Please
provide a value");

            }

}

 

...

 

 

 

The validation is only occurring on the last field in the table - I
presume that is because keywordField is being set to the last value,
which is fair enough. In that case, how can I perform validation and
give error messages on the other keywordFields? I can't find an example
of this on JumpStart or in the docs (or maybe the example is there but I
just haven't seen it).

 

 


**************************************************************************
 
Experience the British Library online at http://www.bl.uk/
 
The British Library's new interactive Annual Report and Accounts 2007/08 : http://www.bl.uk/knowledge
 
Help the British Library conserve the world's knowledge. Adopt a Book. http://www.bl.uk/adoptabook
 
The Library's St Pancras site is WiFi - enabled
 
*************************************************************************
 
The information contained in this e-mail is confidential and may be legally privileged. It is intended for the addressee(s) only. If you are not the intended recipient, please delete this e-mail and notify the mailto:postmaster@bl.uk : The contents of this e-mail must not be disclosed or copied without the sender's consent.
 
The statements and opinions expressed in this message are those of the author and do not necessarily reflect those of the British Library. The British Library does not take any responsibility for the views of the author.
 
*************************************************************************
 

RE: Validation on textfields in a grid?

Posted by "Newham, Cameron" <ca...@bl.uk>.
Does anyone have any further thoughts on this? There must be a way to do
this - and if there isn't then perhaps there should be?


-----Original Message-----
From: Newham, Cameron [mailto:cameron.newham@bl.uk] 
Sent: 25 September 2009 10:08
To: Tapestry users
Subject: RE: Validation on textfields in a grid?

Using a validator would be ok, but unfortunately that assumes that the
component being validated exists in isolation. In my case I only want to
do the validation depending on parameters that have been set by other
components on the page, viz:

	public void onValidateForm()
	{
		if ((tagSelectionId == -1) && (nsTagSelectionId == -1)
&& !removeLine && !addLine)
		{
			if (keywordVisual.getKeyword().getValue() ==
null)
			{
				tagForm.recordError(keywordField,
"Please provide a value");
			}
		}
	}

As far as I can see page properties are not available in a validator and
there is no way to pass these to a validator.

Is there any way I can access the components on a page indirectly?
(i.e.: so I don't have to specify them with @Component). Then I could
iterate over the textfields in my grid and provide tagForm.recordError()
with the correct components to mark.

It seems odd to me that the facility onValidateForm() is provided for
doing validation of the entire form and yet access to the components in
that form, which may have been dynamically created in a Grid, does not
seem possible unless they have been statically created. Maybe I'm not
seeing something here or thinking about it the wrong way?


-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: 24 September 2009 14:52
To: Tapestry users
Subject: Re: Validation on textfields in a grid?

Em Thu, 24 Sep 2009 10:46:10 -0300, Newham, Cameron
<ca...@bl.uk>  
escreveu:

> Thanks again Thiago.
>
> Yes, my fault for not saying exactly what I wanted to achieve.
>
> I agree that one can iterate over the values in the source and check
> them, but I need to mark the field/fields which fail validation on the
> form with:
>
> tagForm.recordError(keywordField, "Please provide a value");

That's why using the TextField's validate parameter is recommended. It  
will put the error markers in the right places. If your needed
validation  
doesn't use other properties than the one edited by the TextField,  
implement your own Validator and use it. You also get an improved  
reusability. :)

> An easy way out would be just to have a single error line, but from a
UI
> perspective it would be much nicer to have the big red X next to the
> actual field that fails, not to mention being consistent with the rest
> of the application and how errors in forms are displayed.

I agree.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


************************************************************************
**
 
Experience the British Library online at http://www.bl.uk/
 
The British Library's new interactive Annual Report and Accounts 2007/08
: http://www.bl.uk/knowledge
 
Help the British Library conserve the world's knowledge. Adopt a Book.
http://www.bl.uk/adoptabook
 
The Library's St Pancras site is WiFi - enabled
 
************************************************************************
*
 
The information contained in this e-mail is confidential and may be
legally privileged. It is intended for the addressee(s) only. If you are
not the intended recipient, please delete this e-mail and notify the
mailto:postmaster@bl.uk : The contents of this e-mail must not be
disclosed or copied without the sender's consent.
 
The statements and opinions expressed in this message are those of the
author and do not necessarily reflect those of the British Library. The
British Library does not take any responsibility for the views of the
author.
 
************************************************************************
*
 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


**************************************************************************
 
Experience the British Library online at http://www.bl.uk/
 
The British Library's new interactive Annual Report and Accounts 2007/08 : http://www.bl.uk/knowledge
 
Help the British Library conserve the world's knowledge. Adopt a Book. http://www.bl.uk/adoptabook
 
The Library's St Pancras site is WiFi - enabled
 
*************************************************************************
 
The information contained in this e-mail is confidential and may be legally privileged. It is intended for the addressee(s) only. If you are not the intended recipient, please delete this e-mail and notify the mailto:postmaster@bl.uk : The contents of this e-mail must not be disclosed or copied without the sender's consent.
 
The statements and opinions expressed in this message are those of the author and do not necessarily reflect those of the British Library. The British Library does not take any responsibility for the views of the author.
 
*************************************************************************
 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Validation on textfields in a grid?

Posted by "Newham, Cameron" <ca...@bl.uk>.
Using a validator would be ok, but unfortunately that assumes that the
component being validated exists in isolation. In my case I only want to
do the validation depending on parameters that have been set by other
components on the page, viz:

	public void onValidateForm()
	{
		if ((tagSelectionId == -1) && (nsTagSelectionId == -1)
&& !removeLine && !addLine)
		{
			if (keywordVisual.getKeyword().getValue() ==
null)
			{
				tagForm.recordError(keywordField,
"Please provide a value");
			}
		}
	}

As far as I can see page properties are not available in a validator and
there is no way to pass these to a validator.

Is there any way I can access the components on a page indirectly?
(i.e.: so I don't have to specify them with @Component). Then I could
iterate over the textfields in my grid and provide tagForm.recordError()
with the correct components to mark.

It seems odd to me that the facility onValidateForm() is provided for
doing validation of the entire form and yet access to the components in
that form, which may have been dynamically created in a Grid, does not
seem possible unless they have been statically created. Maybe I'm not
seeing something here or thinking about it the wrong way?


-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: 24 September 2009 14:52
To: Tapestry users
Subject: Re: Validation on textfields in a grid?

Em Thu, 24 Sep 2009 10:46:10 -0300, Newham, Cameron
<ca...@bl.uk>  
escreveu:

> Thanks again Thiago.
>
> Yes, my fault for not saying exactly what I wanted to achieve.
>
> I agree that one can iterate over the values in the source and check
> them, but I need to mark the field/fields which fail validation on the
> form with:
>
> tagForm.recordError(keywordField, "Please provide a value");

That's why using the TextField's validate parameter is recommended. It  
will put the error markers in the right places. If your needed
validation  
doesn't use other properties than the one edited by the TextField,  
implement your own Validator and use it. You also get an improved  
reusability. :)

> An easy way out would be just to have a single error line, but from a
UI
> perspective it would be much nicer to have the big red X next to the
> actual field that fails, not to mention being consistent with the rest
> of the application and how errors in forms are displayed.

I agree.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


**************************************************************************
 
Experience the British Library online at http://www.bl.uk/
 
The British Library's new interactive Annual Report and Accounts 2007/08 : http://www.bl.uk/knowledge
 
Help the British Library conserve the world's knowledge. Adopt a Book. http://www.bl.uk/adoptabook
 
The Library's St Pancras site is WiFi - enabled
 
*************************************************************************
 
The information contained in this e-mail is confidential and may be legally privileged. It is intended for the addressee(s) only. If you are not the intended recipient, please delete this e-mail and notify the mailto:postmaster@bl.uk : The contents of this e-mail must not be disclosed or copied without the sender's consent.
 
The statements and opinions expressed in this message are those of the author and do not necessarily reflect those of the British Library. The British Library does not take any responsibility for the views of the author.
 
*************************************************************************
 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Validation on textfields in a grid?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 24 Sep 2009 10:46:10 -0300, Newham, Cameron <ca...@bl.uk>  
escreveu:

> Thanks again Thiago.
>
> Yes, my fault for not saying exactly what I wanted to achieve.
>
> I agree that one can iterate over the values in the source and check
> them, but I need to mark the field/fields which fail validation on the
> form with:
>
> tagForm.recordError(keywordField, "Please provide a value");

That's why using the TextField's validate parameter is recommended. It  
will put the error markers in the right places. If your needed validation  
doesn't use other properties than the one edited by the TextField,  
implement your own Validator and use it. You also get an improved  
reusability. :)

> An easy way out would be just to have a single error line, but from a UI
> perspective it would be much nicer to have the big red X next to the
> actual field that fails, not to mention being consistent with the rest
> of the application and how errors in forms are displayed.

I agree.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Validation on textfields in a grid?

Posted by "Newham, Cameron" <ca...@bl.uk>.
Thanks again Thiago.

Yes, my fault for not saying exactly what I wanted to achieve.

I agree that one can iterate over the values in the source and check
them, but I need to mark the field/fields which fail validation on the
form with:

tagForm.recordError(keywordField, "Please provide a value");

So how do I get the correct keywordField object as any number of them
are created in the Grid, depending on how many rows there are, and the
names are generated by Tapestry, as is the connection from the field in
the form to the TextField Component object in my code.

An easy way out would be just to have a single error line, but from a UI
perspective it would be much nicer to have the big red X next to the
actual field that fails, not to mention being consistent with the rest
of the application and how errors in forms are displayed.


-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: 24 September 2009 14:25
To: Tapestry users
Subject: Re: Validation on textfields in a grid?

Em Thu, 24 Sep 2009 10:19:37 -0300, Newham, Cameron
<ca...@bl.uk>  
escreveu:

> Hi Thiago,

Hi!

> The row parameter is only accessing my data from the source parameter,
> not the components themselves.

I just remembered that Grids inside Forms typically only work when you
use  
the row parameter.

> Also, I am not clear about validation through the validate parameter -
> is there an example of this I can look at? However, I have to do the
> validation myself; I simplified the code posted and actually need to
do
> some other things besides checking for null from the text field.

Well, this information changes the solution. :)
In the validateForm event, you need to validate all the objects in the  
Grid, not just one, so you need to iterate over the collection used as
the  
Grid source. The event is not repeated for every element, being fired
just  
once.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


**************************************************************************
 
Experience the British Library online at http://www.bl.uk/
 
The British Library's new interactive Annual Report and Accounts 2007/08 : http://www.bl.uk/knowledge
 
Help the British Library conserve the world's knowledge. Adopt a Book. http://www.bl.uk/adoptabook
 
The Library's St Pancras site is WiFi - enabled
 
*************************************************************************
 
The information contained in this e-mail is confidential and may be legally privileged. It is intended for the addressee(s) only. If you are not the intended recipient, please delete this e-mail and notify the mailto:postmaster@bl.uk : The contents of this e-mail must not be disclosed or copied without the sender's consent.
 
The statements and opinions expressed in this message are those of the author and do not necessarily reflect those of the British Library. The British Library does not take any responsibility for the views of the author.
 
*************************************************************************
 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Validation on textfields in a grid?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 24 Sep 2009 10:19:37 -0300, Newham, Cameron <ca...@bl.uk>  
escreveu:

> Hi Thiago,

Hi!

> The row parameter is only accessing my data from the source parameter,
> not the components themselves.

I just remembered that Grids inside Forms typically only work when you use  
the row parameter.

> Also, I am not clear about validation through the validate parameter -
> is there an example of this I can look at? However, I have to do the
> validation myself; I simplified the code posted and actually need to do
> some other things besides checking for null from the text field.

Well, this information changes the solution. :)
In the validateForm event, you need to validate all the objects in the  
Grid, not just one, so you need to iterate over the collection used as the  
Grid source. The event is not repeated for every element, being fired just  
once.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Validation on textfields in a grid?

Posted by "Newham, Cameron" <ca...@bl.uk>.
Hi Thiago,

Thank you, but I'm not quite clear on what you mean.

The row parameter is only accessing my data from the source parameter,
not the components themselves.

Also, I am not clear about validation through the validate parameter -
is there an example of this I can look at? However, I have to do the
validation myself; I simplified the code posted and actually need to do
some other things besides checking for null from the text field.


-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: 24 September 2009 13:51
To: Tapestry users
Subject: Re: Validation on textfields in a grid?

Try accessing the Grid elements using the row parameter and use the  
validation done by the validate parameter instead of doing it yourself.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


**************************************************************************
 
Experience the British Library online at http://www.bl.uk/
 
The British Library's new interactive Annual Report and Accounts 2007/08 : http://www.bl.uk/knowledge
 
Help the British Library conserve the world's knowledge. Adopt a Book. http://www.bl.uk/adoptabook
 
The Library's St Pancras site is WiFi - enabled
 
*************************************************************************
 
The information contained in this e-mail is confidential and may be legally privileged. It is intended for the addressee(s) only. If you are not the intended recipient, please delete this e-mail and notify the mailto:postmaster@bl.uk : The contents of this e-mail must not be disclosed or copied without the sender's consent.
 
The statements and opinions expressed in this message are those of the author and do not necessarily reflect those of the British Library. The British Library does not take any responsibility for the views of the author.
 
*************************************************************************
 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Validation on textfields in a grid?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Try accessing the Grid elements using the row parameter and use the  
validation done by the validate parameter instead of doing it yourself.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org