You're redirecting to the jsp which creates a whole new http request with null 
parameters.

Instead, you'll want to stash your jsps under WEB-INF so they are protected and 
can't be accessed directly; have your action beans return new 
ForwardResolution("to-the.jsp") instead.  You'll probably have to convert your 
first request from a direct jsp to an action bean which has a @DefaultHandler 
to forward you to the index jsp.  This approach may initially sound like a bit 
of extra work but it really is much nicer once you get comfortable with it.

See the preactions paragraph at 
http://www.stripesframework.org/display/stripes/Best+Practices






From: b l [mailto:[email protected]]
Sent: Monday, July 06, 2009 11:07 AM
To: [email protected]
Subject: [Stripes-users] Parameters in Actionbean won't save

I'm having trouble with something that seems very simple.  Here is my ActionBean


package ....action;

import net.sourceforge.stripes.
action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.DontValidate;
import net.sourceforge.stripes.action.HandlesEvent;

import ....pojo.ImgCal;
import ....service.DailyDataImageService;

import org.apache.log4j.Logger;


@UrlBinding("/DailyData.action")
public class DailyDataActionBean extends W2BActionBean {
    private static final Logger logger = 
Logger.getLogger(DailyDataActionBean.class);

    private DailyDataImageService imgService = new DailyDataImageService();

    private ImgCal imgCal;

    private int curMonth;
    private int prevCurMonth;
    private int curYear;

    public int getCurMonth() {
        return curMonth;
    }

    public void setCurMonth(int curMonth) {
        this.curMonth = curMonth;
    }

    public int getCurYear() {
        return curYear;
    }

    public void setCurYear(int curYear) {
        this.curYear = curYear;
    }

    public ImgCal getImgCal() {
        logger.debug("GET IMG CAL: ");
        if(this.imgCal == null) {
            logger.debug("NULL!");
            this.imgCal = imgService.getImageCalendar(getCurMonth(), 
getCurYear());
        }
        return imgCal;
    }

    public void setImgCal(ImgCal imgCal) {
        this.imgCal = imgCal;
    }

    public int getPrevCurMonth() {
        return prevCurMonth;
    }

    public void setPrevCurMonth(int prevCurMonth) {
        this.prevCurMonth = prevCurMonth;
    }


    @DontValidate
    @DefaultHandler
    public Resolution view() {
        logger.debug("VIEW BEING CALLED");
        this.curMonth = imgService.getCurMonth();
        this.curYear = imgService.getCurYear();
        this.prevCurMonth = imgService.getCurMonth();

        this.imgCal = imgService.getImageCalendar(getCurMonth(), getCurYear());

        logger.debug("IMG CAL: " + getImgCal().getMonthHeader());
        return new RedirectResolution("/DailyData.jsp");
    }

    @HandlesEvent("update")
    @DontValidate
    public Resolution update() {
        logger.debug("In Update: month " + getCurMonth() + " year " + 
getCurYear());
        imgCal = imgService.getImageCalendar(getCurMonth(), getCurYear());
        prevCurMonth = curMonth;
        return new RedirectResolution("/DailyData.jsp");
    }
}

When the action is called, view() is called correctly.  The imgCal is then 
built correctly (I print it out to verify) and then the resolution to the jsp 
works right.  However, once getImgCal() is called from the jsp, imgCal is then 
null (all my bean parameters are then null).  I don't understand why everything 
is null after I've initialized them in view().  If I reinitialize everything 
inside their getters then everything works correctly, but this is extremely 
inefficient as it takes a long time to build imgCal.  I've also tried using the 
StripesStuff plugin and the @Session notation, with the same result.  Is there 
something I'm missing?  This seems like this should be very basic 
functionality.  I have other actions that work, so to my knowledge, I don't 
think the problem is with my web.xml or setup in general.  Any ideas?
------------------------------------------------------------------------------
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to