You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Erik Hatcher <er...@ehatchersolutions.com> on 2004/03/15 16:36:49 UTC

Fwd: problem decorating required field's FieldLabels on first page load

I entered a bug for this yesterday, and it was bugging me enough to 
look into it.  Locally I changed the direction from "in" to "auto" on 
the validator parameter of ValidField.jwc and now it works!

Are there any reasons for me *not* to commit this change?

Thanks,
	Erik


Begin forwarded message:

> From: Erik Hatcher <er...@ehatchersolutions.com>
> Date: March 14, 2004 7:41:27 PM EST
> To: "Tapestry users" <ta...@jakarta.apache.org>
> Subject: Re: problem decorating required field's FieldLabels on first 
> page load
> Reply-To: "Tapestry users" <ta...@jakarta.apache.org>
>
> Galen - this is definitely a bug.  I just attempted the same thing 
> (using CVS HEAD) and sure enough, writeLabelPrefix/Suffix is not able 
> to see the validator attached to the field.
>
> This is a real bummer.
>
> Does anyone have ideas how this bug can be fixed?  As Galen pointed 
> out, it has to do with the order of events somehow.  But for label 
> decoration to be truly useful, access to the validator is necessary.  
> I'm really surprised this has not surfaced before - no one must 
> decorate required field labels?  This was something that went into my 
> infamous LabelTag in the Struts world - and we gotta have such 
> capability in Tapestry also.
>
> 	Erik
>
> On Mar 12, 2004, at 1:56 PM, Galen Meurer wrote:
>
>> Hi all,
>>
>> First things first, I'm using beta-4.
>>
>> It seems that for the very first call to a page's validation 
>> delegate's
>> writeLabelPrefix and writeLabelSuffix methods, the validator has not 
>> yet
>> been instantiated. It is instantiated, though, for the call to 
>> writePrefix
>> shortly thereafter.
>>
>> This strikes me as very similar to a problem that Peter Butler had
>> (2/3/2004): "Component Form Is Null First Time Page Is Viewed in 
>> 3.0b3, OK
>> After Session Restart", but I did not see any responses to that post.
>>
>> I am trying to decorate the FieldLabel according to if the field is 
>> required
>> rather than (or possibly in addition to) decorating the ValidField. 
>> Unlike
>> ValidationDelegate.writePrefix, however, writeLabelPrefix and
>> writeLabelSuffix do not get the IValidator passed to them. However, 
>> you can
>> get to the validator from the component (as long as it is a 
>> ValidField) -- I
>> have attempted to do so like this:
>>
>>   public void writeLabelPrefix(IFormComponent component, IMarkupWriter
>> writer, IRequestCycle cycle) {
>>     IValidator validator = getValidator(component);
>>     if (null != validator) {
>>       if (validator.isRequired()) {
>>         writer.begin("span");
>>         writer.attribute("class", "required-label");
>>       }
>>     }
>>   }
>>
>>   private IValidator getValidator(IFormComponent component) {
>>     IValidator validator = null;
>>     if (component instanceof ValidField) {
>>       ValidField field = (ValidField)component;
>>       validator = field.getValidator();
>>     } else if (component instanceof ValidDatePicker) {
>>       ValidDatePicker field = (ValidDatePicker)component;
>>       validator = field.getValidator();
>>     } else {
>>       logger.warn("the component is not a known type, we can't 
>> decorate");
>>     }
>>     logger.debug("validator is " + ((null == validator) ? "null" : 
>> "not
>> null"));
>>     return validator;
>>   }
>>
>> This works Ok,  except for the very first invocation of the page. For 
>> the
>> first invocation, the validator is null.
>>
>> First time:
>> 2004-03-11 20:52:10,718 DEBUG [PresentationDelegate] validator is null
>> 2004-03-11 20:52:10,718 DEBUG [PresentationDelegate] validator is null
>>
>> Reloading the page:
>> 2004-03-11 20:52:25,359 DEBUG [PresentationDelegate] validator is not 
>> null
>> 2004-03-11 20:52:25,359 DEBUG [PresentationDelegate] validator is not 
>> null
>>
>> The FieldLabel gets properly decorated every time for every user 
>> subsequent
>> to the first page load.
>>
>> I thought perhaps that order mattered in the page specification, so I 
>> tried
>> making sure that the validator appeared before the delegate, but that 
>> didn't
>> help.
>>
>> Is there a better way to do decorate the labels? It has to be a 
>> method that
>> doesn't involve me putting any decorations into the template or the
>> specification. Alternatively, is there something I can do to make 
>> sure the
>> validator is instantiated that makes it work the first time the page 
>> is
>> loaded? If no on both those, can I request that the validator get
>> instantiated earlier?
>>
>> Thanks very much,
>> Galen Meurer
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


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


Re: problem decorating required field's FieldLabels on first page load

Posted by Mindbridge <mi...@yahoo.com>.
Personally, I do think this is a bug, so it must be fixed one way or another
before the release.
+1 on that

I would only consider the efficiency issue -- as you know, 'auto' works
always, but it is not as efficient as 'in', since it is always evaluated.
There are a lot of calls, which may cause grief performance-wise, perhaps
some sort of caching will be ideal?
(One possibility is to create a cachedValidator property initialized to null
and only call getValidator() if that is null)

Nevertheless, my opinion is that it is better to work slowly, than to break
quickly. :)


----- Original Message ----- 
From: "Erik Hatcher" <er...@ehatchersolutions.com>
To: "Tapestry development" <ta...@jakarta.apache.org>
Sent: Monday, March 15, 2004 5:36 PM
Subject: Fwd: problem decorating required field's FieldLabels on first page
load


> I entered a bug for this yesterday, and it was bugging me enough to
> look into it.  Locally I changed the direction from "in" to "auto" on
> the validator parameter of ValidField.jwc and now it works!
>
> Are there any reasons for me *not* to commit this change?
>
> Thanks,
> Erik
>
>
> Begin forwarded message:
>
> > From: Erik Hatcher <er...@ehatchersolutions.com>
> > Date: March 14, 2004 7:41:27 PM EST
> > To: "Tapestry users" <ta...@jakarta.apache.org>
> > Subject: Re: problem decorating required field's FieldLabels on first
> > page load
> > Reply-To: "Tapestry users" <ta...@jakarta.apache.org>
> >
> > Galen - this is definitely a bug.  I just attempted the same thing
> > (using CVS HEAD) and sure enough, writeLabelPrefix/Suffix is not able
> > to see the validator attached to the field.
> >
> > This is a real bummer.
> >
> > Does anyone have ideas how this bug can be fixed?  As Galen pointed
> > out, it has to do with the order of events somehow.  But for label
> > decoration to be truly useful, access to the validator is necessary.
> > I'm really surprised this has not surfaced before - no one must
> > decorate required field labels?  This was something that went into my
> > infamous LabelTag in the Struts world - and we gotta have such
> > capability in Tapestry also.
> >
> > Erik
> >
> > On Mar 12, 2004, at 1:56 PM, Galen Meurer wrote:
> >
> >> Hi all,
> >>
> >> First things first, I'm using beta-4.
> >>
> >> It seems that for the very first call to a page's validation
> >> delegate's
> >> writeLabelPrefix and writeLabelSuffix methods, the validator has not
> >> yet
> >> been instantiated. It is instantiated, though, for the call to
> >> writePrefix
> >> shortly thereafter.
> >>
> >> This strikes me as very similar to a problem that Peter Butler had
> >> (2/3/2004): "Component Form Is Null First Time Page Is Viewed in
> >> 3.0b3, OK
> >> After Session Restart", but I did not see any responses to that post.
> >>
> >> I am trying to decorate the FieldLabel according to if the field is
> >> required
> >> rather than (or possibly in addition to) decorating the ValidField.
> >> Unlike
> >> ValidationDelegate.writePrefix, however, writeLabelPrefix and
> >> writeLabelSuffix do not get the IValidator passed to them. However,
> >> you can
> >> get to the validator from the component (as long as it is a
> >> ValidField) -- I
> >> have attempted to do so like this:
> >>
> >>   public void writeLabelPrefix(IFormComponent component, IMarkupWriter
> >> writer, IRequestCycle cycle) {
> >>     IValidator validator = getValidator(component);
> >>     if (null != validator) {
> >>       if (validator.isRequired()) {
> >>         writer.begin("span");
> >>         writer.attribute("class", "required-label");
> >>       }
> >>     }
> >>   }
> >>
> >>   private IValidator getValidator(IFormComponent component) {
> >>     IValidator validator = null;
> >>     if (component instanceof ValidField) {
> >>       ValidField field = (ValidField)component;
> >>       validator = field.getValidator();
> >>     } else if (component instanceof ValidDatePicker) {
> >>       ValidDatePicker field = (ValidDatePicker)component;
> >>       validator = field.getValidator();
> >>     } else {
> >>       logger.warn("the component is not a known type, we can't
> >> decorate");
> >>     }
> >>     logger.debug("validator is " + ((null == validator) ? "null" :
> >> "not
> >> null"));
> >>     return validator;
> >>   }
> >>
> >> This works Ok,  except for the very first invocation of the page. For
> >> the
> >> first invocation, the validator is null.
> >>
> >> First time:
> >> 2004-03-11 20:52:10,718 DEBUG [PresentationDelegate] validator is null
> >> 2004-03-11 20:52:10,718 DEBUG [PresentationDelegate] validator is null
> >>
> >> Reloading the page:
> >> 2004-03-11 20:52:25,359 DEBUG [PresentationDelegate] validator is not
> >> null
> >> 2004-03-11 20:52:25,359 DEBUG [PresentationDelegate] validator is not
> >> null
> >>
> >> The FieldLabel gets properly decorated every time for every user
> >> subsequent
> >> to the first page load.
> >>
> >> I thought perhaps that order mattered in the page specification, so I
> >> tried
> >> making sure that the validator appeared before the delegate, but that
> >> didn't
> >> help.
> >>
> >> Is there a better way to do decorate the labels? It has to be a
> >> method that
> >> doesn't involve me putting any decorations into the template or the
> >> specification. Alternatively, is there something I can do to make
> >> sure the
> >> validator is instantiated that makes it work the first time the page
> >> is
> >> loaded? If no on both those, can I request that the validator get
> >> instantiated earlier?
> >>
> >> Thanks very much,
> >> Galen Meurer
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org


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