You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by zhouyc <zh...@gmail.com> on 2013/01/24 08:36:24 UTC

PersistenceConstants.FLASH cann't persist List langs

please help me to solve the problem?
after submitting and page redisplayed, username can be saved, but langs lost
values added by submit method.

@Property
@Persist(PersistenceConstants.FLASH)
private String username;

@Property
@Persist(PersistenceConstants.FLASH)
private List<String> langs;

void onActivate() {
    if (langs == null) {
       langs = new ArrayList<String>();
    }
}

void onSubmit() {
     langs.add("en");
}



--
View this message in context: http://tapestry.1045711.n5.nabble.com/PersistenceConstants-FLASH-cann-t-persist-List-String-langs-tp5719462.html
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: PersistenceConstants.FLASH cann't persist List langs

Posted by Ivan Khalopik <ik...@gmail.com>.
As far as I understood flash strategy is needed to store values between
form submission and render requests.
Your flow:
1. onActivate() create values and store them in session
2. onSubmit() retrieve values and remove them from session => add value to
detached collection
3. onActivate() retrieve values => they are null => create new and store
them in session

So, the right choice depends on what you need.
1. If you want to have values be available from render to form submission
request - always create values during render phase, e.g.:

onActivate() {
  langs = new ArrayList<String>();
}

2. If you need to have values be available from form submission to render
request - always create values during submit phase, e.g.:

onSubmit() {
  langs = new ArrayList<String>();
}

NOTE: this is the best choice as session is empty most of the time. Values
are created on form submission and immedeately goes to render phase where
this values are removed from the session.

3. If you need both variants - use SESSION strategy.

On Fri, Feb 22, 2013 at 1:57 PM, mvchris <ch...@mrvoip.com.au> wrote:

> bit of a hack but can you put the list to a single string delimited by
> control chars or caret ^
> prior to form submission
>
> then on rendering of 2nd page convert back from single string to list
>
> chris
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/PersistenceConstants-FLASH-cann-t-persist-List-String-langs-tp5719462p5720167.html
> 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
>
>


-- 
BR
Ivan

Re: PersistenceConstants.FLASH cann't persist List langs

Posted by mvchris <ch...@mrvoip.com.au>.
bit of a hack but can you put the list to a single string delimited by
control chars or caret ^
prior to form submission

then on rendering of 2nd page convert back from single string to list

chris



--
View this message in context: http://tapestry.1045711.n5.nabble.com/PersistenceConstants-FLASH-cann-t-persist-List-String-langs-tp5719462p5720167.html
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: PersistenceConstants.FLASH cann't persist List langs

Posted by zhouyc <zh...@gmail.com>.
if i don't want to store the List in the session for a long time, is there
any advice to solve this problem?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/PersistenceConstants-FLASH-cann-t-persist-List-String-langs-tp5719462p5720163.html
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: PersistenceConstants.FLASH cann't persist List langs

Posted by Muhammad Gelbana <m....@gmail.com>.
I "think" because you refer to the *langs* object in the *activation* event
method, it flashes the object. You find it as an empty list, correct ?
I'm not fully aware of the FLASH persistence but I suppose it's only meant
for persisting form fields across requests and a Collection isn't
applicable for that.

On Thu, Jan 24, 2013 at 9:36 AM, zhouyc <zh...@gmail.com> wrote:

> please help me to solve the problem?
> after submitting and page redisplayed, username can be saved, but langs
> lost
> values added by submit method.
>
> @Property
> @Persist(PersistenceConstants.FLASH)
> private String username;
>
> @Property
> @Persist(PersistenceConstants.FLASH)
> private List<String> langs;
>
> void onActivate() {
>     if (langs == null) {
>        langs = new ArrayList<String>();
>     }
> }
>
> void onSubmit() {
>      langs.add("en");
> }
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/PersistenceConstants-FLASH-cann-t-persist-List-String-langs-tp5719462.html
> 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
>
>