You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andy Huhn <am...@hslt-online.com> on 2008/05/02 09:35:17 UTC
[T5]: Persistent bean for BeanEditForm?
Hello,
I have a page that uses a BeanEditForm to allow the user to edit a bean.
I'm using the @Validate annotation on various fields in the bean to mark
them as required, or to assign a minimum length, etc.
My problem is that if the validation fails and the page redisplays, all
of the user's changes are lost. I thought about using @Persist to
persist the bean (_orgnztn in the class below), but won't that cause
issues, since this is a Hibernate entity? Won't that cause a reference
to the Session to be persisted also, so that the next time this page is
loaded, it may use the wrong Session?
My page class is something like this:
public class EditOrganization {
@Component
private BeanEditForm _orgnztnEditForm;
@Persist( "flash" )
private Integer _orgnztnId;
private Organization _orgnztn;
public Object onActivate( Integer prmOrgnztnId ) {
setOrgnztnId( prmOrgnztnId );
return( null );
}
public Object onActivate() {
if( getOrgnztnId() != null ) {
setOrgnztn( <snip>get from DAO</snip> );
}
return( unathrzdRdrct() );
}
public Object onPassivate() {
return( getOrgnztnId() );
}
public Object onSuccess() {
Organization thisOrgnztn = getOrgnztn();
<snip>Use Hibernate to update the
Organization record in the DB</snip>
return( <snip>a page class</snip> );
}
public Organization getOrgnztn() {
return _orgnztn;
}
public void setOrgnztn(Organization prmOrgnztn ) {
_orgnztn = prmOrgnztn;
}
public Integer getOrgnztnId() {
return _orgnztnId;
}
public void setOrgnztnId( Integer prmOrgnztnId ) {
_orgnztnId = prmOrgnztnId;
}
}
And my template is similar to this:
<t:layout
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" >
<t:beaneditform object="orgnztn" t:id="orgnztnEditForm">
</t:beaneditform>
</t:layout>
Thanks,
Andy
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5]: Persistent bean for BeanEditForm?
Posted by Tobias Wehrum <Le...@dragonlab.de>.
Hi Andy,
maybe I'm leaning to much out of the window because I have not enough
Hibernate knowledge, but I don't think Hibernate stores its sessions in
the entities - more like vice versa storing references to the entities
in the session. (Don't count to much on my word - like I said, it's just
an assumption.)
Well, at least I can say for sure: I'm using @Persist on my hibernate
entities and it never caused a problem.
Tobias
Andy Huhn schrieb:
> Hello,
>
> I have a page that uses a BeanEditForm to allow the user to edit a bean.
> I'm using the @Validate annotation on various fields in the bean to mark
> them as required, or to assign a minimum length, etc.
>
> My problem is that if the validation fails and the page redisplays, all
> of the user's changes are lost. I thought about using @Persist to
> persist the bean (_orgnztn in the class below), but won't that cause
> issues, since this is a Hibernate entity? Won't that cause a reference
> to the Session to be persisted also, so that the next time this page is
> loaded, it may use the wrong Session?
>
> My page class is something like this:
>
> public class EditOrganization {
>
> @Component
> private BeanEditForm _orgnztnEditForm;
>
> @Persist( "flash" )
> private Integer _orgnztnId;
>
> private Organization _orgnztn;
>
> public Object onActivate( Integer prmOrgnztnId ) {
> setOrgnztnId( prmOrgnztnId );
> return( null );
> }
>
> public Object onActivate() {
> if( getOrgnztnId() != null ) {
> setOrgnztn( <snip>get from DAO</snip> );
> }
> return( unathrzdRdrct() );
> }
>
> public Object onPassivate() {
> return( getOrgnztnId() );
> }
>
> public Object onSuccess() {
> Organization thisOrgnztn = getOrgnztn();
>
> <snip>Use Hibernate to update the
> Organization record in the DB</snip>
> return( <snip>a page class</snip> );
> }
>
> public Organization getOrgnztn() {
> return _orgnztn;
> }
>
> public void setOrgnztn(Organization prmOrgnztn ) {
> _orgnztn = prmOrgnztn;
> }
>
> public Integer getOrgnztnId() {
> return _orgnztnId;
> }
>
> public void setOrgnztnId( Integer prmOrgnztnId ) {
> _orgnztnId = prmOrgnztnId;
> }
>
> }
>
> And my template is similar to this:
>
> <t:layout
> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" >
>
> <t:beaneditform object="orgnztn" t:id="orgnztnEditForm">
> </t:beaneditform>
>
> </t:layout>
>
> Thanks,
> Andy
>
>
> ---------------------------------------------------------------------
> 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