Hi,
I upgraded my application to 5.2.4 and everything seemed great, but I
eventually noticed some weird behavior regarding some functionality that
previously worked in my application.
I have a page that displays Entities in a Grid. Each row has a link that
triggers an event with the context of the given entity ID. At this
point, the page stores the id in a persisted Object called PageId, and
sets a boolean to conditionally delegate/render a sub-page in the
template. In @BeginRender, the PageId is pushed into the environment.
The sub-page provides a BeanEditForm for the given Entity object so a
user can update information.
The sub-page uses @Environmental on a PageId object to grab the one
pushed on the stack from the Grid page. In onPrepareForRender, an Entity
object is loaded from the DB based on the value in the PageId.
Everything is good so far. The Entity object is @Property and @Persist
annotated. At the end of the onPrepareForRender method, the Entity is
set properly. However, it seems to get de-referenced at some point
between that method and AfterRender. I put a debug message in
AfterRender and the entity object is no longer referencing the expected
values. Strangely enough, if I define @Persist Entity entity2 and write
entity2 = entity.clone() in the onPrepareForRender method, in
AfterRender, entity2 is still the expected Entity object...
After some further prodding, I found out that whichever entity object is
set as the object parameter of the BeanEditForm is being re-initialized
as if it was assigned = new Entity(). This is breaking my page because I
have been using the entity object to 'initialize' the BeanEditForm
fields to the stored values of the entity. Since the entity ends up
re-initialized during rendering, none of the previously stored fields
are available for a user to see and edit.
What is happening to the entity object, I thought BeanEditForm was
supposed to use it if it was an initialized property (enforced in the
container in a "prepare" event)? The first time the Entity link is
clicked on the GridPage, the entity object ends up null. The second time
as well. The third time, it displays whatever the previous link should
have displayed and continues in this fashion indefinitely. I'd assume I
must have some flawed logic here somewhere, but it is a bit baffling
that it used to work in 5.1.
Simplified code example:
GridPage.java
@Inject
private Environment env;
@Persist
private String subPage;
@Persist @Property
private PageId id;
@Persist @Property
private boolean subtabSelect;
public Object onActionFromDetailsLink(String cid){
subtabSelect = true;
this.subPage = DETAILS_TAB;
id = new PageId(cid);
debug("DetailsLink clicked. SubPageId set to " + this.subPage);
...
}
@BeginRender
public void pushPageId(){
debug("Loaded ViewTPTab and SubPageId = " + this.id);
env.push(PageId.class, id);
}
@AfterRender
public void popPageId(){
this.id = env.pop(PageId.class);
}
DetailsTab.java:
@Environmental
private PageId id;
@Inject
private Environment env;
@Property @Persist
private ThirdParty tp;
@Persist
private ThirdParty tp2;
@Inject
private TPDAO tpdao;
public void onPrepareForRender(){
tp = (ThirdParty) tpdao.read(id.getId());
/* .... pull some info from the tp object, parse and place
into Persisted fields. These fields are the only ones displayed properly
in the BeanEditForm. BeanEditForm is referencing the tp object. */
tp2 = tp.clone();
debug("In onPrepareForRender of DetailsTab. Loaded ::"+tp+"::
from DB");
}
public void afterRender(){
debug("In afterRender... the TP object is : " + tp ); //tp is null
debug("... tp2 : " + tp2); //tp2 = tpdao.read(id.getId())
}
void onPrepareForSubmit(){
env.push(PageId.class, heldId); //push back into environment on
submit from BeanEditForm
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org