Search code examples
javastruts

Can not get select list back in struts Action class in java


I have a list i take it from DB and populate to the page using this code

DynamicComboCM allPartners = new DynamicComboCM();
allPartners.setAllRecommendedList(daoClass.getAllPartners(ds));
request.setAttribute("allPartners", allPartners);

Here DynamicComboCM is bean that contains the property allRecommendedList and i populate this list from DB using daoClass which returns an ArrayList then i set it to request and get it on jsp page like this.

    <html:select styleId="partnerListForRecommended" name="Bean2"
    property="bean2Property" size="15" multiple="true">
<html:optionsCollection name="allPartners"
    property="allRecommendedList" label="label" value="value" />
    </html:select>

i get the list on jsp as expected, on jsp user moves some records from this list to another list and in this way this list reduced by size as some recoreds had move to other list. now when i press save button i m not getting this list,

can any one please help me how to get this list again in jsp, i tried it using request.getAttribute("allPartners"); but not working. Thanks in advance.


Solution

    • One of solution is to put list allPartners into session.

      to set
      request.getSession().setAttribute("allPartners", allPartners);

      to get when needed
      request.getSession().getAttribute("allPartners");

    • Another solution (using request scope) is to get allPartners from database again (better from the cache).