You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Xinhua <xi...@rrd.com> on 2008/01/30 18:11:19 UTC

Tapestry 5 - Custom Component Validation

I create a custom component (AttrLable) which extends AbstractField. In the
BeginRender(MarkupWriter writer), I will need to override the label tag
based on whether there is an error in the input field which is associated to
this label. 

On the form submission, I will do the form validation and if errors are
found, I will highlight the label and input field in the form page. But the
problem is how I can pass the error flag to the component class (Attrlabel)
which will rend the component.

Thanks in advance!


Xinhua 
-- 
View this message in context: http://www.nabble.com/Tapestry-5---Custom-Component-Validation-tp15186101p15186101.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Tapestry 5 - Custom Component Validation

Posted by Michael Courcy <mi...@gmail.com>.
I'm really not sure that I grasp your need but

given that you declare the component in the template

@Component(id="myAttLabel")
private AttLabel myAttLabel;

public void  onValidate(){
  if(...whatever that could be an error...){
     myAttLabel.setErrorFlag(true);
  }
}

should do the job

But I think the answer of Josh Canfield is better
http://www.nabble.com/Tapestry-5---Custom-Component-Validation-tt15186101.html#a15186101
Because you can track the error within the component


Xinhua a écrit :
> This is what I am trying to do. But I could not pass the error flag from page
> to component(AttLabel). I do not want to use @Persist to do this, but like
> to add it to something like request object. So what annotation can I use? 
> Can you show me the way (some codes) to do this? 
>
> Xinhua
>
>
> Michael Courcy wrote:
>   
>> I you have control on the validation why not putting a flag in your 
>> component when a validation error happen.
>>
>> Your render process would depend of this flag.
>>
>> does it help ?
>>
>> Xinhua a écrit :
>>     
>>> I create a custom component (AttrLable) which extends AbstractField. In
>>> the
>>> BeginRender(MarkupWriter writer), I will need to override the label tag
>>> based on whether there is an error in the input field which is associated
>>> to
>>> this label. 
>>>
>>> On the form submission, I will do the form validation and if errors are
>>> found, I will highlight the label and input field in the form page. But
>>> the
>>> problem is how I can pass the error flag to the component class
>>> (Attrlabel)
>>> which will rend the component.
>>>
>>> Thanks in advance!
>>>
>>>
>>> Xinhua 
>>>   
>>>       
>> -- 
>> Michael Courcy
>> http://courcy.blogspot.com
>> http://courcy-en.blogspot.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>>     
>
>   


-- 
Michael Courcy
http://courcy.blogspot.com
http://courcy-en.blogspot.com


Re: Tapestry 5 - Custom Component Validation

Posted by Xinhua <xi...@rrd.com>.
This is what I am trying to do. But I could not pass the error flag from page
to component(AttLabel). I do not want to use @Persist to do this, but like
to add it to something like request object. So what annotation can I use? 
Can you show me the way (some codes) to do this? 

Xinhua


Michael Courcy wrote:
> 
> I you have control on the validation why not putting a flag in your 
> component when a validation error happen.
> 
> Your render process would depend of this flag.
> 
> does it help ?
> 
> Xinhua a écrit :
>> I create a custom component (AttrLable) which extends AbstractField. In
>> the
>> BeginRender(MarkupWriter writer), I will need to override the label tag
>> based on whether there is an error in the input field which is associated
>> to
>> this label. 
>>
>> On the form submission, I will do the form validation and if errors are
>> found, I will highlight the label and input field in the form page. But
>> the
>> problem is how I can pass the error flag to the component class
>> (Attrlabel)
>> which will rend the component.
>>
>> Thanks in advance!
>>
>>
>> Xinhua 
>>   
> 
> 
> -- 
> Michael Courcy
> http://courcy.blogspot.com
> http://courcy-en.blogspot.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Tapestry-5---Custom-Component-Validation-tp15186101p15213531.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Tapestry 5 - Custom Component Validation

Posted by Michael Courcy <mi...@gmail.com>.
I you have control on the validation why not putting a flag in your 
component when a validation error happen.

Your render process would depend of this flag.

does it help ?

Xinhua a écrit :
> I create a custom component (AttrLable) which extends AbstractField. In the
> BeginRender(MarkupWriter writer), I will need to override the label tag
> based on whether there is an error in the input field which is associated to
> this label. 
>
> On the form submission, I will do the form validation and if errors are
> found, I will highlight the label and input field in the form page. But the
> problem is how I can pass the error flag to the component class (Attrlabel)
> which will rend the component.
>
> Thanks in advance!
>
>
> Xinhua 
>   


-- 
Michael Courcy
http://courcy.blogspot.com
http://courcy-en.blogspot.com


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


Re: Tapestry 5 - Custom Component Validation

Posted by Xinhua <xi...@rrd.com>.
Thanks for the reply.

Besed on your codes, I can get the error flag; but can not know if the error
is on this component because this tracker may contain errors for other
components. I am thinking that I can use inError(Field field) to find the
answer. But if I use beaneditform to generate the form, I will not define
each individual field in the page class (but just define a beaneditform). In
this case, I can not use inError(Field field) method. Is there a way to
create a Tapestry Field from Bean?

Thanks,

XW


joshcanfield wrote:
> 
> Hi,
> 
> I believe you can achieve what you want by grabbing the ValidationTracker
> from the Environment. The Form component pushes it to the environment
> during
> beginRender and pops it in cleanupRender, your component will beginRender
> after the form.
> 
> you would do something like:
> @Inject
> Environment _environment;
> void beginRender() {
> ...
> ValidationTracker tracker = _environment.peek(ValidationTracker.class);
> tracker.getHasErrors();
> }
> 
> I haven't run, or even compiled this code, and I'm still back in 5.0.6 so
> perhaps something has changed, but I'm fairly certain it should work.
> 
> Good luck,
> Josh
> 
> On Jan 30, 2008 9:11 AM, Xinhua <xi...@rrd.com> wrote:
> 
>>
>> I create a custom component (AttrLable) which extends AbstractField. In
>> the
>> BeginRender(MarkupWriter writer), I will need to override the label tag
>> based on whether there is an error in the input field which is associated
>> to
>> this label.
>>
>> On the form submission, I will do the form validation and if errors are
>> found, I will highlight the label and input field in the form page. But
>> the
>> problem is how I can pass the error flag to the component class
>> (Attrlabel)
>> which will rend the component.
>>
>> Thanks in advance!
>>
>>
>> Xinhua
>> --
>> View this message in context:
>> http://www.nabble.com/Tapestry-5---Custom-Component-Validation-tp15186101p15186101.html
>> Sent from the Tapestry - User mailing list archive at
>> Nabble.com<http://nabble.com/>
>> .
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 
> -- 
> --
> TheDailyTube.com. Sign up and get the best new videos on the internet
> delivered fresh to your inbox.
> 
> 

-- 
View this message in context: http://www.nabble.com/Tapestry-5---Custom-Component-Validation-tp15186101p15234347.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Tapestry 5 - Custom Component Validation

Posted by Josh Canfield <jo...@thedailytube.com>.
Hi,

I believe you can achieve what you want by grabbing the ValidationTracker
from the Environment. The Form component pushes it to the environment during
beginRender and pops it in cleanupRender, your component will beginRender
after the form.

you would do something like:
@Inject
Environment _environment;
void beginRender() {
...
ValidationTracker tracker = _environment.peek(ValidationTracker.class);
tracker.getHasErrors();
}

I haven't run, or even compiled this code, and I'm still back in 5.0.6 so
perhaps something has changed, but I'm fairly certain it should work.

Good luck,
Josh

On Jan 30, 2008 9:11 AM, Xinhua <xi...@rrd.com> wrote:

>
> I create a custom component (AttrLable) which extends AbstractField. In
> the
> BeginRender(MarkupWriter writer), I will need to override the label tag
> based on whether there is an error in the input field which is associated
> to
> this label.
>
> On the form submission, I will do the form validation and if errors are
> found, I will highlight the label and input field in the form page. But
> the
> problem is how I can pass the error flag to the component class
> (Attrlabel)
> which will rend the component.
>
> Thanks in advance!
>
>
> Xinhua
> --
> View this message in context:
> http://www.nabble.com/Tapestry-5---Custom-Component-Validation-tp15186101p15186101.html
> Sent from the Tapestry - User mailing list archive at Nabble.com<http://nabble.com/>
> .
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.