You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chris Norris <CN...@widen.com> on 2005/06/02 18:33:04 UTC

dynamically generated form fields and form level validation

I'm going to try to boil this down to the neccesities.  If it doesn't
make sense, I'll provide some code.
 
I have a Foreach loop inside of a form.  The loop generates a couple of
sets of FieldLabel/ValidField components*.
 
The problem is that two of the fields' validation depend on each other.
If both fields are empty, they both need to be marked as errored so that
the error markup will be written.  If one or the other has a value, they
are both valid.  Can someone point me in the best direction for this?
 
My first thought was to record the name of the ValidField component when
the page was getting the value for it.  I would get the names, something
like validComponentName and validComponentName$0.  At form rewind time,
though, I couldn't figure out how to get the components given those
names and set them in error.  It seems impossible, given that getName()
will always return the most recent name generated for the component.  I
tried going through the ValidationDelegate's FieldTrackings and going
through the map returned by getComponents(), neither of which worked
very well.
 
My next option was going to be to make a special validator for this
purpose.  It would have to be a page property rather than a bean so that
the same validator would be used for both ValidFields.  All of these
approaches seem ugly to me.  Ideas?  Directions?
 
-Chris
 
 
*uses a Defer type component to take care of the off by one validation
error.  the Defer component wraps a FieldLabel and takes in a block that
contains a ValidField:
 protected void renderComponent(IMarkupWriter writer, IRequestCycle
cycle)
 {
  IMarkupWriter nested = writer.getNestedWriter();
  getBlock().renderBody(nested, cycle);
  renderBody(writer, cycle);
  nested.close();  
 }


Re: dynamically generated form fields and form level validation

Posted by ro...@scazdl.org.
Harish submitted a patch a /long/ while back that dealt with the scenario
of how to set a particular field in error when it's rendered in a loop. He
added a new "index" property, as I recall. The patch was never applied,
but if you search the archives for it,  you should be able to find it.
I also know that the patch cannot be cleanly applied to 3.0.3 due to
conflicting changes, so, you may just need to take the patch and use it as
the basis for your own modifications.
Will this issue be addressed in the new validation stuff Paul is working
on for 4.0?

Robert

> I'm going to try to boil this down to the neccesities.  If it doesn't
> make sense, I'll provide some code.
>
> I have a Foreach loop inside of a form.  The loop generates a couple of
> sets of FieldLabel/ValidField components*.
>
> The problem is that two of the fields' validation depend on each other.
> If both fields are empty, they both need to be marked as errored so that
> the error markup will be written.  If one or the other has a value, they
> are both valid.  Can someone point me in the best direction for this?
>
> My first thought was to record the name of the ValidField component when
> the page was getting the value for it.  I would get the names, something
> like validComponentName and validComponentName$0.  At form rewind time,
> though, I couldn't figure out how to get the components given those
> names and set them in error.  It seems impossible, given that getName()
> will always return the most recent name generated for the component.  I
> tried going through the ValidationDelegate's FieldTrackings and going
> through the map returned by getComponents(), neither of which worked
> very well.
>
> My next option was going to be to make a special validator for this
> purpose.  It would have to be a page property rather than a bean so that
> the same validator would be used for both ValidFields.  All of these
> approaches seem ugly to me.  Ideas?  Directions?
>
> -Chris
>
>
> *uses a Defer type component to take care of the off by one validation
> error.  the Defer component wraps a FieldLabel and takes in a block that
> contains a ValidField:
>  protected void renderComponent(IMarkupWriter writer, IRequestCycle
> cycle)
>  {
>   IMarkupWriter nested = writer.getNestedWriter();
>   getBlock().renderBody(nested, cycle);
>   renderBody(writer, cycle);
>   nested.close();
>  }
>
>


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


Re: dynamically generated form fields and form level validation

Posted by The Chris Method <th...@gmail.com>.
The problem is that the components are being generated in a loop. Calling
getComponent("password1") won't work if the component named "password1" is
in a loop and there are 10 of them.

-Chris

On 10/10/05, Gregor Melhorn <g....@web.de> wrote:
>
> Hello Chris,
>
> I don't understand the problem, I guess, since it seams quite simple
> to me...
>
> If you want to check two fields: Why don't you just check the values
> in the form listener using a validation delegate?
>
> If I want to check on the password and password confirmation field,
> I'd do it like that:
>
> public IPage onSubmit() {
> ValidationDelegate delegate = getDelegate();
>
> if ((getPassword1() != null) && (getPassword2() != null) &&
> (!(getPassword1().equals(getPassword2())))){
> delegate.setFormComponent((IFormComponent) getComponent("password1"));
> delegate.recordFieldInputValue(null);
> delegate.record("errormessage", null);
> delegate.setFormComponent((IFormComponent) getComponent("password2"));
> delegate.recordFieldInputValue(null);
> delegate.record("errormessage", null);
> return null;
> }
>
> if (delegate.getHasErrors()) {
> return null;
> }
> // continue listener...
>
> }
>
> Best regards
> Gregor
>
> am Montag, 10. Oktober 2005 um 22:15 schrieben Sie:
>
> > It is 4 months later and I still haven't come up with a solution for
> this. I
> > gave up on it back then and somebody else has come to me trying to solve
> the
> > problem. Things have changed since we are now using Tapestry 4, so the
> info
> > about the defer component is out of date, but the situation is about the
> > same. I need to perform validation that depends on two fields' inputs.
> How
> > do I do this?
>
> > -Chris
>
> > On 6/2/05, Chris Norris <CN...@widen.com> wrote:
> >>
> >> I'm going to try to boil this down to the neccesities. If it doesn't
> >> make sense, I'll provide some code.
> >>
> >> I have a Foreach loop inside of a form. The loop generates a couple of
> >> sets of FieldLabel/ValidField components*.
> >>
> >> The problem is that two of the fields' validation depend on each other.
> >> If both fields are empty, they both need to be marked as errored so
> that
> >> the error markup will be written. If one or the other has a value, they
> >> are both valid. Can someone point me in the best direction for this?
> >>
> >> My first thought was to record the name of the ValidField component
> when
> >> the page was getting the value for it. I would get the names, something
> >> like validComponentName and validComponentName$0. At form rewind time,
> >> though, I couldn't figure out how to get the components given those
> >> names and set them in error. It seems impossible, given that getName()
> >> will always return the most recent name generated for the component. I
> >> tried going through the ValidationDelegate's FieldTrackings and going
> >> through the map returned by getComponents(), neither of which worked
> >> very well.
> >>
> >> My next option was going to be to make a special validator for this
> >> purpose. It would have to be a page property rather than a bean so that
> >> the same validator would be used for both ValidFields. All of these
> >> approaches seem ugly to me. Ideas? Directions?
> >>
> >> -Chris
> >>
> >>
> >> *uses a Defer type component to take care of the off by one validation
> >> error. the Defer component wraps a FieldLabel and takes in a block that
> >> contains a ValidField:
> >> protected void renderComponent(IMarkupWriter writer, IRequestCycle
> >> cycle)
> >> {
> >> IMarkupWriter nested = writer.getNestedWriter();
> >> getBlock().renderBody(nested, cycle);
> >> renderBody(writer, cycle);
> >> nested.close();
> >> }
> >>
> >>
> >>
>
>
>
> --
> Mit freundlichen Grüßen
> Gregor Melhorn
> mailto:g.melhorn@web.de
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: dynamically generated form fields and form level validation

Posted by Gregor Melhorn <g....@web.de>.
Hello Chris,

I don't understand the problem, I guess, since it seams quite simple
to me...

If you want to check two fields: Why don't you just check the values
in the form listener using a validation delegate?

If I want to check on the password and password confirmation field,
I'd do it like that:

        public IPage onSubmit() {
                ValidationDelegate delegate = getDelegate();
                
                if ((getPassword1() != null) && (getPassword2() != null) && (!(getPassword1().equals(getPassword2())))){
                        delegate.setFormComponent((IFormComponent) getComponent("password1"));
                        delegate.recordFieldInputValue(null);
                        delegate.record("errormessage", null);
                        delegate.setFormComponent((IFormComponent) getComponent("password2"));
                        delegate.recordFieldInputValue(null);
                        delegate.record("errormessage", null);
                        return null;
                }

                if (delegate.getHasErrors()) {
                        return null;
                }
        // continue listener...

        }

Best regards
Gregor

am Montag, 10. Oktober 2005 um 22:15 schrieben Sie:

> It is 4 months later and I still haven't come up with a solution for this. I
> gave up on it back then and somebody else has come to me trying to solve the
> problem. Things have changed since we are now using Tapestry 4, so the info
> about the defer component is out of date, but the situation is about the
> same. I need to perform validation that depends on two fields' inputs. How
> do I do this?

> -Chris

> On 6/2/05, Chris Norris <CN...@widen.com> wrote:
>>
>> I'm going to try to boil this down to the neccesities. If it doesn't
>> make sense, I'll provide some code.
>>
>> I have a Foreach loop inside of a form. The loop generates a couple of
>> sets of FieldLabel/ValidField components*.
>>
>> The problem is that two of the fields' validation depend on each other.
>> If both fields are empty, they both need to be marked as errored so that
>> the error markup will be written. If one or the other has a value, they
>> are both valid. Can someone point me in the best direction for this?
>>
>> My first thought was to record the name of the ValidField component when
>> the page was getting the value for it. I would get the names, something
>> like validComponentName and validComponentName$0. At form rewind time,
>> though, I couldn't figure out how to get the components given those
>> names and set them in error. It seems impossible, given that getName()
>> will always return the most recent name generated for the component. I
>> tried going through the ValidationDelegate's FieldTrackings and going
>> through the map returned by getComponents(), neither of which worked
>> very well.
>>
>> My next option was going to be to make a special validator for this
>> purpose. It would have to be a page property rather than a bean so that
>> the same validator would be used for both ValidFields. All of these
>> approaches seem ugly to me. Ideas? Directions?
>>
>> -Chris
>>
>>
>> *uses a Defer type component to take care of the off by one validation
>> error. the Defer component wraps a FieldLabel and takes in a block that
>> contains a ValidField:
>> protected void renderComponent(IMarkupWriter writer, IRequestCycle
>> cycle)
>> {
>> IMarkupWriter nested = writer.getNestedWriter();
>> getBlock().renderBody(nested, cycle);
>> renderBody(writer, cycle);
>> nested.close();
>> }
>>
>>
>>



-- 
Mit freundlichen Grüßen
Gregor Melhorn
mailto:g.melhorn@web.de




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


Re: dynamically generated form fields and form level validation

Posted by The Chris Method <th...@gmail.com>.
It is 4 months later and I still haven't come up with a solution for this. I
gave up on it back then and somebody else has come to me trying to solve the
problem. Things have changed since we are now using Tapestry 4, so the info
about the defer component is out of date, but the situation is about the
same. I need to perform validation that depends on two fields' inputs. How
do I do this?

-Chris

On 6/2/05, Chris Norris <CN...@widen.com> wrote:
>
> I'm going to try to boil this down to the neccesities. If it doesn't
> make sense, I'll provide some code.
>
> I have a Foreach loop inside of a form. The loop generates a couple of
> sets of FieldLabel/ValidField components*.
>
> The problem is that two of the fields' validation depend on each other.
> If both fields are empty, they both need to be marked as errored so that
> the error markup will be written. If one or the other has a value, they
> are both valid. Can someone point me in the best direction for this?
>
> My first thought was to record the name of the ValidField component when
> the page was getting the value for it. I would get the names, something
> like validComponentName and validComponentName$0. At form rewind time,
> though, I couldn't figure out how to get the components given those
> names and set them in error. It seems impossible, given that getName()
> will always return the most recent name generated for the component. I
> tried going through the ValidationDelegate's FieldTrackings and going
> through the map returned by getComponents(), neither of which worked
> very well.
>
> My next option was going to be to make a special validator for this
> purpose. It would have to be a page property rather than a bean so that
> the same validator would be used for both ValidFields. All of these
> approaches seem ugly to me. Ideas? Directions?
>
> -Chris
>
>
> *uses a Defer type component to take care of the off by one validation
> error. the Defer component wraps a FieldLabel and takes in a block that
> contains a ValidField:
> protected void renderComponent(IMarkupWriter writer, IRequestCycle
> cycle)
> {
> IMarkupWriter nested = writer.getNestedWriter();
> getBlock().renderBody(nested, cycle);
> renderBody(writer, cycle);
> nested.close();
> }
>
>
>