Thanks a lot Ivan for the extra info.

On Mon, Nov 19, 2012 at 11:36 AM, Ivan Khalopik <ikhalo...@gmail.com> wrote:

> When you use recordError(field, "Message") you have not only messages
> listed by <t:errors/> component but also this messages are connected to the
> fileds and can be used later:
>
> 1. You can remove <t:errors> and use <t:error for="field"/> component that
> will render error message for specified field, e.g.
> <div>
> <t:label t:for="dnsServerField">DUT</t:label>
> <t:textfield t:id="dnsServerField" t:value="testOptions('server.ip').value"
> />
> <t:error for="dnsServerField">
> </div>
>
> 2. You can remove <t:errors> component and use ValidationDecorator service
> instead. You can configure it to highlight fields in error with red border
> and to render error messages to the right of this field, e.g. for
> bootstrap:
>
> public class BootstrapValidationDecorator extends BaseValidationDecorator {
>     private final Environment environment;
>     private final MarkupWriter markupWriter;
>
>     public BootstrapValidationDecorator(Environment environment,
> MarkupWriter markupWriter) {
>         this.environment = environment;
>         this.markupWriter = markupWriter;
>     }
>
>     public void insideField(Field field) {
>         if (inError(field)) {
>             addErrorClass();
>         }
>     }
>
>     public void afterField(Field field) {
>         if (inError(field)) {
>             markupWriter.element("span", "class", "help-inline");
>             markupWriter.write(getError(field));
>             markupWriter.end();
>         }
>     }
>
>     private void addErrorClass() {
>         Element element = markupWriter.getElement();
>         do {
>             element = element.getContainer();
>         } while (!element.getAttribute("class").contains("control-group"));
>         element.addClassName("error");
>     }
>
>     private boolean inError(Field field) {
>         ValidationTracker tracker =
> environment.peekRequired(ValidationTracker.class);
>         return tracker.inError(field);
>     }
>
>     private String getError(Field field) {
>         ValidationTracker tracker =
> environment.peekRequired(ValidationTracker.class);
>         return tracker.getError(field);
>     }
> }
>
> On Mon, Nov 19, 2012 at 12:06 PM, Taha Siddiqi <tawus.tapes...@gmail.com
> >wrote:
>
> > These are two components t:error and t:errors. You have to use t:error.
> > t:errors doesn't have for component
> >
> >
> > On Nov 19, 2012, at 2:26 PM, Muhammad Gelbana wrote:
> >
> > > Thanks ! But unfortunately that didn't work either. All error
> components
> > > list all error messages whether they are bound to it or or even if the
> > > error component isn't bound at all (i.e. <errors />)!
> > > I checked tapestry jumpstart for guidance and found that I was using
> > > @InjectComponent instead of @Component but I didn't notice any
> difference
> > > so I assume there isn't.
> > >
> > > My template file looks like this:
> > >
> > >> <t:block t:id="dnsTestOptions">
> > >> <fieldset>
> > >> <legend>${testType} Options</legend>
> > >> <div>
> > >> <div><t:errors t:for="dnsServerField"/></div>
> > >> <div>
> > >> <t:label t:for="dnsServerField">DUT</t:label>
> > >> <t:textfield t:id="dnsServerField"
> > >> t:value="testOptions('server.ip').value" />
> > >> </div>
> > >> <div><t:errors t:for="domainNameField" /></div>
> > >> <div>
> > >> <t:label t:for="domainNameField">Domain Name</t:label>
> > >> <t:textfield t:id="domainNameField"
> > >> t:value="testOptions('domain-name').value" />
> > >> </div>
> > >> </div>
> > >> </fieldset>
> > >> </t:block>
> > >
> > >
> > > Withing my page, the form and form fields injection statements are:
> > >
> > >> @Component(id = "testConfigurationForm")
> > >> private Form testForm;
> > >> @Component
> > >> private TextField dnsServerField, domainNameField;
> > >
> > >
> > > That's how I record my errors
> > >
> > >> testForm.recordError(field, "Please provide a valid IPv4 address.");
> > >
> > >
> > > I even tried making sure that I'm not recording an error twice for both
> > > fields (Since the error message would be identical) I prefixed the
> error
> > > message with the field's label and it was clear that each error
> component
> > > is listing all errors even the ones not bound to it !
> > >
> > > Thanks again.
> > >
> > > On Mon, Nov 19, 2012 at 8:18 AM, Taha Siddiqi <
> tawus.tapes...@gmail.com
> > >wrote:
> > >
> > >> Hi
> > >>
> > >> Checkout the "for" parameter in
> > >>
> >
> http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Error.html
> > .
> > >> You can specify a field there to retrieve error specific to that field
> > >>
> > >> regards
> > >> Taha
> > >>
> > >> On Nov 19, 2012, at 2:10 AM, Muhammad Gelbana wrote:
> > >>
> > >>> I have a form that submits by reloading the whole page. But my form's
> > >>> fields are in separate zones. Before submitting the form, these zones
> > get
> > >>> changed (i.e. different fields are shown with each zone update) till
> > the
> > >>> user is satisfied and then he submits the form in the manner
> mentioned.
> > >>>
> > >>> Now after I validate my fields and record errors using
> > recordError(Field,
> > >>> String), I don't find a difference between that method and using the
> > >> other
> > >>> one recordError(String). What is the difference if the t:error
> > component
> > >>> doesn't utilize the Field object passed to the first method to
> indicate
> > >> the
> > >>> difference between the error messages ?!
> > >>>
> > >>> I mean it always lists all error messages in a list without
> indicating
> > to
> > >>> which field does this error message belong ? Shouldn't it be
> something
> > >> like:
> > >>>
> > >>>
> > >>>> You must resolve these errors before proceeding:
> > >>>
> > >>> Field A:
> > >>>>   . Error msg 1.
> > >>>>   . Error msg 2.
> > >>>> Field C:
> > >>>>   . Error msg 1.
> > >>>> Field B:
> > >>>>   . Error msg 1.
> > >>>>   . Error msg 2.
> > >>>
> > >>>
> > >>> ?
> > >>>
> > >>> After checking the Error component source code, I think this
> deserves a
> > >>> JIRA issue. Am I correct or did I miss something here ?
> > >>
> > >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> > For additional commands, e-mail: users-h...@tapestry.apache.org
> >
> >
>
>
> --
> BR
> Ivan
>

Reply via email to