Hi Swarna,

There are two problems with your approach.
First, @Session cannot be used with checkboxes since unchecked checkboxes are 
not submitted when not checked. It may work, but it's not a supported feature 
since it is very likely to fail.
Second, if a field with the same name is submitted as a field present in 
session, @Session WON'T restore the previous value because it suppose you want 
to replace old values with the new ones.
For example, if your first page contains:
        <d:column title="Add to Pack">
        <s:checkbox name="selectedMessages" value="${Task.task_Id}"/>
        </d:column>
And your second page contains:
        <d:column title="Add to Pack">
        <s:checkbox name="selectedMessages[some_higher_indexes]" 
value="${Task.task_Id}"/>
        </d:column>
The the values from the first page will be lost since the second request submit 
new values for selectedMessages.

You can easily check if values are in session by using the key attribute in 
@Session.
For example, with @Session(key="selectedMessages_key"), you can get the 
selectedMessages by using session.getAttribute("selectedMessages_key").
Remember that field is saved in session after the EventHandling lifecycle 
stage, session.getAttribute("selectedMessages_key") will not return the 
expected value before that time.


The complete documentation about @Session is here: 
http://www.stripesframework.org/display/stripes/Save+ActionBean+fields+in+session

Christian


________________________________
From: swarna mahesh [mailto:[email protected]]
Sent: Wednesday, November 18, 2009 5:19 AM
To: [email protected]
Subject: [Stripes-users] @Session for list

I am sending the results from a checkbox in a display table and submit it to my 
action. The code works fine for the first time, but it doesnt save anything in 
the session, when i want to add more items, the previous values are gone and 
only the current selection is saved in the list. How do I retain the values in 
session when I try to add more items through the checkbox?

Code in my jsp:
------------------------

        <d:column title="Add to Pack">
        <s:checkbox name="selectedMessages" value="${Task.task_Id}"/>
        </d:column>

---- <p><s:submit name="Add_to_Pack" value="Add to Pack"/></p>
----------------------------------------------------------------------------------------------------------------------------------------
Actionbean code:
--------------------------

@Session
private List<String> selectedMessages;
public List<String> getSelectedMessages() {
return selectedMessages;
}
public void setSelectedMessages(List<String> selectedMessages) {
this.selectedMessages = selectedMessages;
}

@HandlesEvent(value="Add_to_Pack")
    public Resolution Add_to_Pack() {
     return new ForwardResolution(VIEW);
    }


--
Best Regards,
Swarna
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to