[
https://issues.apache.org/jira/browse/TAP5-374?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12677079#action_12677079
]
Howard M. Lewis Ship commented on TAP5-374:
-------------------------------------------
>From PageImpl:
public void persistFieldChange(ComponentResources resources, String
fieldName, Object newValue)
{
if (!loadComplete)
throw new
RuntimeException(StructureMessages.persistChangeBeforeLoadComplete());
persistentFieldManager.postChange(name, resources, fieldName, newValue);
}
public Object getFieldChange(String nestedId, String fieldName)
{
if (fieldBundle == null) fieldBundle =
persistentFieldManager.gatherChanges(name);
return fieldBundle.getValue(nestedId, fieldName);
}
My guess is that this could be caused by having some *other* persistent field
in the page. This first field forces the fieldBundle() to gather values. You
initialization code sets the property to a new Map(). Then getFieldChange() is
invoked for the property and your change isn't there, just resetting the value
back to null.
Anyway, breaking pageAttached() into two phases will help: first all persisted
fields will be rolled back, *then* pageAttached() logic can set default values
for persisted fields (which will be properly accounted for in the session from
that point on).
> Persistent (@Persist) fields not set correctly between requests if they are
> initialised from pageAttached() method
> ------------------------------------------------------------------------------------------------------------------
>
> Key: TAP5-374
> URL: https://issues.apache.org/jira/browse/TAP5-374
> Project: Tapestry 5
> Issue Type: Bug
> Components: tapestry-core
> Affects Versions: 5.0.15, 5.0.16
> Reporter: Joel Halbert
> Assignee: Howard M. Lewis Ship
>
> I am seeing unexpected behaviour when using persistent fields and the
> page lifecycle method, pageAttached(), (T 5.0.15).
> I have a persistent field,
> @Persist
> private Map myMap;
> I also have a page lifecycle method,
> void pageAttached() {
> if (myMap == null){
> myMap = new HashMap();
> }
> }
> I expect that when the page first loads and myMap is null then myMap
> will be initialised to an empty map, thereafter I expect anything I put
> into the map to persist across requests.
> What I actually see is that, if the above pageAttached method is present
> then any data that I put into myMap does not persist across requests
> (the map is always empty). I was not expecting this.
> If I do not initialise myMap in pageAttached then data does persist.
> By design or bug?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.