You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Galen Meurer <si...@galenmeurer.com> on 2004/03/12 19:56:30 UTC

problem decorating required field's FieldLabels on first page load

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


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

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
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


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

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
The problem is calling getValidator returns null in 
writeLabelPrefix/Suffix.

In other words, you cannot decorate a field label with information of 
that field being required.

	Erik


On Mar 15, 2004, at 5:58 AM, Peter Butler wrote:

> Hi Galen
>
> I worked around this problem by checking if the form was null:
>
> 	public void writeLabelPrefix(
> 		IFormComponent component,
> 		IMarkupWriter writer,
> 		IRequestCycle cycle) {
> 		if (component.getForm() != null && isInError(component))
> {
> 			writer.begin("span");
> 			writer.attribute("class", "label-error");
> 		} else {
> 			writer.begin("span");
> 			writer.attribute("class", "label");
> 		}
> 	}
>
> Will something similar work in your situation?
>
> Cheers
>
> Peter
>
> www.clever.co.nz
>
> -----Original Message-----
> From: Galen Meurer [mailto:sitio@galenmeurer.com]
> Sent: Saturday, 13 March 2004 7:57 a.m.
> To: Tapestry users
> Subject: problem decorating required field's FieldLabels on first page
> load
>
>
> 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-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


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

Posted by Peter Butler <pe...@141.com>.
Hi Galen

I worked around this problem by checking if the form was null:

	public void writeLabelPrefix(
		IFormComponent component,
		IMarkupWriter writer,
		IRequestCycle cycle) {
		if (component.getForm() != null && isInError(component))
{
			writer.begin("span");
			writer.attribute("class", "label-error");
		} else {
			writer.begin("span");
			writer.attribute("class", "label");
		}
	}

Will something similar work in your situation?

Cheers

Peter

www.clever.co.nz

-----Original Message-----
From: Galen Meurer [mailto:sitio@galenmeurer.com] 
Sent: Saturday, 13 March 2004 7:57 a.m.
To: Tapestry users
Subject: problem decorating required field's FieldLabels on first page
load


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