You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2007/10/22 10:14:53 UTC

T5: @Persist form field or not?

Hi,

I have two classes, Edit1 and Edit2,  name is the form field, when I submit
the form using Edit1, everything works, and when I tried Edit2, it generates
an exception:

java.lang.NullPointerException
Stack trace
	•	org.bfe.test.t5.pages.Edit.setName(Edit.java:52)
	•
org.apache.tapestry.internal.bindings.PropBinding.set(PropBinding.java:67)

What's the difference here? if I @Persist usr, error goes away, then why I
don't have @Persist name in the Edit1's case? thanks.

A.C.


public class Edit1 {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name;
    }

public class Edit2 {
    private Usr usr;

    public String getName() {
        return usr.getName();
    }

    public void setName(String name) {
        this.usr.setName(name);
    }


-- 
View this message in context: http://www.nabble.com/T5%3A-%40Persist-form-field-or-not--tf4669367.html#a13338569
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


RE: T5: @Persist form field or not?

Posted by Jonathan Barker <jo...@gmail.com>.
This topic comes up periodically.  Under T4, it might come up under
null-handlers for OGNL where a usr object could automatically be created if
one did not exist already.

One way or another, you need to make sure that usr is not null when you go
to assign the name.

It's OK for name to be null in Edit1, and usr.name to be null in Edit2, but
you can't have usr be null in Edit2.

That's half the answer anyway.  The other half must be in the behavior of
@Persist, or in code that you have not included.


> -----Original Message-----
> From: Angelo Chen [mailto:angelochen960@yahoo.com.hk]
> Sent: Monday, October 22, 2007 4:15 AM
> To: users@tapestry.apache.org
> Subject: T5: @Persist form field or not?
> 
> 
> Hi,
> 
> I have two classes, Edit1 and Edit2,  name is the form field, when I
> submit
> the form using Edit1, everything works, and when I tried Edit2, it
> generates
> an exception:
> 
> java.lang.NullPointerException
> Stack trace
> 	.	org.bfe.test.t5.pages.Edit.setName(Edit.java:52)
> 	.
> org.apache.tapestry.internal.bindings.PropBinding.set(PropBinding.java:67)
> 
> What's the difference here? if I @Persist usr, error goes away, then why I
> don't have @Persist name in the Edit1's case? thanks.
> 
> A.C.
> 
> 
> public class Edit1 {
>     private String name;
> 
>     public String getName() {
>         return name;
>     }
> 
>     public void setName(String name) {
>         this.name;
>     }
> 
> public class Edit2 {
>     private Usr usr;
> 
>     public String getName() {
>         return usr.getName();
>     }
> 
>     public void setName(String name) {
>         this.usr.setName(name);
>     }
> 
> 
> --
> View this message in context: http://www.nabble.com/T5%3A-%40Persist-form-
> field-or-not--tf4669367.html#a13338569
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


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


Re: Antwort: T5: @Persist form field or not?

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Kristian,

Thanks for the explanation, now it's getting a little clearer. let me
understand this and correct me if wrong:

Tapestry renders a page to the browser, onActivate was called at this time.
it generate another page or whatever you call it if a form is specified,
<form action="/myapp/edit.form_nam
e">, so this edit.form_name is the one that contains those onValidate,
onSuccess, onSubmit, etc, is it how T5 works behind the scene?  thanks.
A.C. 


kristian.marinkovic wrote:
> 
> hi angelo,
> 
> edit1 does not throw an exception because it is a string.
> Tapestry will automatically coerce the input and convert
> it to a string.
> 
> edit2 does not work without persist because after rendering
> the usr instance will be discarded and usr will reference null.
> on submit tapestry will try to call setName and  produce a NPE 
> because the usr is null.  knowing the type of a referenced bean
> or entity is not enough to be able to create one.
> 
> g,
> kris
> 
> 
> 
> 
> Angelo Chen <an...@yahoo.com.hk> 
> 22.10.2007 10:14
> Bitte antworten an
> "Tapestry users" <us...@tapestry.apache.org>
> 
> 
> An
> users@tapestry.apache.org
> Kopie
> 
> Thema
> T5: @Persist form field or not?
> 
> 
> 
> 
> 
> 
> 
> Hi,
> 
> I have two classes, Edit1 and Edit2,  name is the form field, when I 
> submit
> the form using Edit1, everything works, and when I tried Edit2, it 
> generates
> an exception:
> 
> java.lang.NullPointerException
> Stack trace
>                  • org.bfe.test.t5.pages.Edit.setName(Edit.java:52)
>                  •
> org.apache.tapestry.internal.bindings.PropBinding.set(PropBinding.java:67)
> 
> What's the difference here? if I @Persist usr, error goes away, then why I
> don't have @Persist name in the Edit1's case? thanks.
> 
> A.C.
> 
> 
> public class Edit1 {
>     private String name;
> 
>     public String getName() {
>         return name;
>     }
> 
>     public void setName(String name) {
>         this.name;
>     }
> 
> public class Edit2 {
>     private Usr usr;
> 
>     public String getName() {
>         return usr.getName();
>     }
> 
>     public void setName(String name) {
>         this.usr.setName(name);
>     }
> 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/T5%3A-%40Persist-form-field-or-not--tf4669367.html#a13338569
> 
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-%40Persist-form-field-or-not--tf4669367.html#a13339601
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Antwort: T5: @Persist form field or not?

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
hi angelo,

edit1 does not throw an exception because it is a string.
Tapestry will automatically coerce the input and convert
it to a string.

edit2 does not work without persist because after rendering
the usr instance will be discarded and usr will reference null.
on submit tapestry will try to call setName and  produce a NPE 
because the usr is null.  knowing the type of a referenced bean
or entity is not enough to be able to create one.

g,
kris




Angelo Chen <an...@yahoo.com.hk> 
22.10.2007 10:14
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
users@tapestry.apache.org
Kopie

Thema
T5: @Persist form field or not?







Hi,

I have two classes, Edit1 and Edit2,  name is the form field, when I 
submit
the form using Edit1, everything works, and when I tried Edit2, it 
generates
an exception:

java.lang.NullPointerException
Stack trace
                 • org.bfe.test.t5.pages.Edit.setName(Edit.java:52)
                 •
org.apache.tapestry.internal.bindings.PropBinding.set(PropBinding.java:67)

What's the difference here? if I @Persist usr, error goes away, then why I
don't have @Persist name in the Edit1's case? thanks.

A.C.


public class Edit1 {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name;
    }

public class Edit2 {
    private Usr usr;

    public String getName() {
        return usr.getName();
    }

    public void setName(String name) {
        this.usr.setName(name);
    }


-- 
View this message in context: 
http://www.nabble.com/T5%3A-%40Persist-form-field-or-not--tf4669367.html#a13338569

Sent from the Tapestry - User mailing list archive at Nabble.com.


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