You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Stephen Nutbrown <st...@gmail.com> on 2015/07/25 15:30:17 UTC

Form recorded error disappearing

Hi,

I have a simple form with one field which takes in a code. This code is to
identify guests at our wedding, the security of it isn't really paramount.

We would like to be able to have users enter the code into the form, OR
scan a QR code. The QR code points to an address, e.g

www.foo.com/1234

The onActivate method picks up that 1234 and gets an "Invite" object if one
exists with that code. If not, I would like to record an error on the form,
the code looks like this:

@SessionState(create = false)
Invitation invite;

@Component(id = "pinform")
private Form form;

@Component(id = "pinNumber")
private TextField pinNumberField;

public Object onActivate(Invitation invite) {
this.invite = invite;
if(invite != null){
return Wedding.class;
}else{
form.recordError(pinNumberField, "Sorry, this number is not valid.");
return null;
}
}

Although this does pick up the wedding and the "else" is fired for an
incorrect pin, the recorded error does not show.

My onValidate method (for if someone actually submits the form rather than
scanning a QR code) works and looks like this:

public void onValidateFromPinForm() {
invite = dao.find(Invitation.class, pinNumber);
if (invite == null) {
form.recordError(pinNumberField, "Sorry, this number is not valid.");
}
}

public Object onSuccessFromPinForm() {
return Wedding.class;
}

How can I persist the error on the form from the onActivate method? I have
tried using @Persist, this throws an exception:

Field form of class com.wedding.steveandstacey.pages.Index can not be
claimed by @org.apache.tapestry5.annotations.Persist as it is already
claimed by @org.apache.tapestry5.annotations.Component.

Any ideas?

Thanks,
Steve

Re: Form recorded error disappearing

Posted by Bob Harner <bo...@gmail.com>.
Stephen,

Where did you try putting @Persist? The error you got sounds like you put
it on the property you annotated with @Component. Try putting it on your
pin number property, not pinNumberField

Can we see your tml file?

I normally use @InjectComponent rather than @Component
On Jul 25, 2015 9:30 AM, "Stephen Nutbrown" <st...@gmail.com> wrote:

> Hi,
>
> I have a simple form with one field which takes in a code. This code is to
> identify guests at our wedding, the security of it isn't really paramount.
>
> We would like to be able to have users enter the code into the form, OR
> scan a QR code. The QR code points to an address, e.g
>
> www.foo.com/1234
>
> The onActivate method picks up that 1234 and gets an "Invite" object if one
> exists with that code. If not, I would like to record an error on the form,
> the code looks like this:
>
> @SessionState(create = false)
> Invitation invite;
>
> @Component(id = "pinform")
> private Form form;
>
> @Component(id = "pinNumber")
> private TextField pinNumberField;
>
> public Object onActivate(Invitation invite) {
> this.invite = invite;
> if(invite != null){
> return Wedding.class;
> }else{
> form.recordError(pinNumberField, "Sorry, this number is not valid.");
> return null;
> }
> }
>
> Although this does pick up the wedding and the "else" is fired for an
> incorrect pin, the recorded error does not show.
>
> My onValidate method (for if someone actually submits the form rather than
> scanning a QR code) works and looks like this:
>
> public void onValidateFromPinForm() {
> invite = dao.find(Invitation.class, pinNumber);
> if (invite == null) {
> form.recordError(pinNumberField, "Sorry, this number is not valid.");
> }
> }
>
> public Object onSuccessFromPinForm() {
> return Wedding.class;
> }
>
> How can I persist the error on the form from the onActivate method? I have
> tried using @Persist, this throws an exception:
>
> Field form of class com.wedding.steveandstacey.pages.Index can not be
> claimed by @org.apache.tapestry5.annotations.Persist as it is already
> claimed by @org.apache.tapestry5.annotations.Component.
>
> Any ideas?
>
> Thanks,
> Steve
>