You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by er...@cdstiger.com on 2005/07/01 20:05:02 UTC

ValidationDelegate.isInError(IFormComponent) and @Foreach

I'm working on a custom ValidationDelegate that wraps a label and input
field in a div for validation error highlighting.
The labels and input fields are enclosed in a @Foreach giving the user
that ability to add additional fields at runtime for submission.

Unfortunately, i'm running into an issue with isInError(IFormComponent)
when processing the validation errors.  My delegate's writeLabelPrefix is
using isInError(IFormComponent) and it's evaluating to true on fields
that are not invalid.  I'm assuming this is a manifestation of incorrect
results warned about in the javadocs.

    /**
     * Checks to see if the field is in error. This will <em>not</em> work properly in a loop, but
     * is only used by {@link FieldLabel}. Therefore, using {@link FieldLabel}in a loop (where the
     * {@link IFormComponent}is rendered more than once) will not provide correct results.
     */
    protected boolean isInError(IFormComponent component)

What i'm failing to find is a workaround for this limitation.  Is there
some way to determine at the time that writeLabelPrefix is invoked, if the
particular occurrence of the component within the @Foreach is invalid?

Any help is appreciated.

--
eric

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


Re: ValidationDelegate.isInError(IFormComponent) and Foreach

Posted by er...@cdstiger.com.
Thanks for the response... however i wasn't totally satisfied with
Howard's workaround.  Like he says in the blog, it forces knowledge of
tapestry's inner workings into the template.

So, i dug into this more and came up with my own solution.  It involves
more code, but makes up for it with more elegant usage in the template.

Let me start with it's usage in the template as part of a @Foreach:

<span jwcid="@Foreach" source="ognl:attributes" value="ognl:attribute"
    index="ognl:components.labelAttributeValue.index">
  <span jwcid="labelAttributeValue">
    <label><span key="attribute.label">Attribute</span></label>
    <input type="text" size="25" jwcid="inputAttributeValue"
      class="campaign"/>
    <input jwcid="add@Submit" type="submit" value="+" class="plus"
      label="+"
      selected="ognl:addAfterAttribute" tag="ognl:attribute"
      listener="ognl:listeners.add"/>
    <input jwcid="remove@Submit" type="submit" value="-" class="minus"
      label="-"
      selected="ognl:removeAttribute" tag="ognl:attribute"
      listener="ognl:listeners.remove"/>
  </span>
</span>

What i have here is the fragment of the form where there is a text input
and add/remove buttons.

jwcid="labelAttributeValue" is an instance of my extension to FieldLabel

In my FieldLabel extension i made two changes:
1) added index property (getter/setter) that is set by the index attribute
of @Foreach as shown in the snippet above.
2) Instead of writing the displayName, i modified it to render it's body. 
This way, less markup goes into the code, and the template has more
control over it's display.  This also allows the label to completely wrap
the html label and html input within the template.

When the FieldLabel renders it passes the index value to the
IValidationDelegate write methods.  Then in my delegate i added a new
method isIndexInError(int,IFormComponent) that serves the same purpose as
isInError(IFormComponent), but works with the current index within the
@Foreach.  All that isIndexInError does is determines if a
fieldTracking.errorRenderer exists for a fieldTracking that has a
fieldName matching the componentName$index - 1 (or just componentName if
index == 0).

When implemented, this method works great for both forms containing
@Foreach loops, and those that don't and i think results in friendlier
more intuitive template markup.

>  <ervandew <at> cdstiger.com> writes:
>
>> What i'm failing to find is a workaround for this limitation.  Is there
>> some way to determine at the time that writeLabelPrefix is invoked, if
>> the
>> particular occurrence of the component within the  <at> Foreach is
>> invalid?
>
> Please see
> http://howardlewisship.com/blog/2004/12/
> back-from-shoppingcom-defer-component.html
>
> --
> Author of an e-Book for learning Tapestry
> (http://www.agileskills2.org/EWDT)
>
>
> ---------------------------------------------------------------------
> 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: ValidationDelegate.isInError(IFormComponent) and Foreach

Posted by Kent Tong <ke...@cpttm.org.mo>.
 <ervandew <at> cdstiger.com> writes:

> What i'm failing to find is a workaround for this limitation.  Is there
> some way to determine at the time that writeLabelPrefix is invoked, if the
> particular occurrence of the component within the  <at> Foreach is invalid?

Please see
http://howardlewisship.com/blog/2004/12/
back-from-shoppingcom-defer-component.html

--
Author of an e-Book for learning Tapestry (http://www.agileskills2.org/EWDT)


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