You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by spsarolkar <sp...@gmail.com> on 2009/08/18 10:07:49 UTC

Problem using scope interceptor

I am trying apress book example chapter06. Here is my struts.xml file
<struts>
	
    <constant name="struts.codebehind.defaultPackage" value="base-package"/>
    <constant name="struts.codebehind.pathPrefix" value="/WEB-INF/jsp/"/>
    <package name="base-package" extends="struts-default" >
        <default-interceptor-ref name="paramsPrepareParamsStack" />
        <global-results>
            <result name="unknownError">/WEB-INF/jsp/error.jsp</result>
            <result
name="dupPK">/WEB-INF/jsp/user/findUser-success.jsp</result>
        </global-results>
        <global-exception-mappings>
            <exception-mapping
exception="org.hibernate.exception.ConstraintViolationException"
result="dupPK" />
            <exception-mapping exception="java.lang.Exception"
result="unknownError" />
        </global-exception-mappings>
        <action name="index" class="org.xinus.actions.BaseAction">
            <result name="success">/WEB-INF/jsp/index.jsp</result>
        </action>
    </package>
    <package name="enterEvent" namespace="/event" extends="base-package">
        <interceptors>
            <interceptor name="flash"
class="com.opensymphony.webwork.interceptor.FlashInterceptor" />
            <interceptor-stack name="eventStack">
                <interceptor-ref name="scope">
                    model
                    partialEvent
                </interceptor-ref>
                <interceptor-ref name="paramsPrepareParamsStack"/>
            </interceptor-stack>
        </interceptors>
        <default-interceptor-ref name="eventStack"/>

        <action name="addEventFlow"
class="org.xinus.actions.event.BaseEventAction">
            <interceptor-ref name="eventStack">
                start
            </interceptor-ref>
            <result>/WEB-INF/jsp/event/enterEventDetails-input.jsp</result>
        </action>
        <action name="endEventFlow"
class="org.xinus.actions.event.BaseEventAction">
            <interceptor-ref name="eventStack">
                end
            </interceptor-ref>
            <result>/WEB-INF/jsp/event/eventReview.jsp</result>
        </action>
        <action name="flashedSelectEventType"
class="org.xinus.actions.event.SelectLocationTypeAction">
            <interceptor-ref name="flash">
                Retrieve
            </interceptor-ref>
            <interceptor-ref name="eventStack" />
            <result>/WEB-INF/jsp/event/selectLocationType-input.jsp</result>
        </action>
    </package>
    
</struts>

Here is my BaseEventAction.java
public class BaseEventAction extends BaseAction implements
ModelDriven<Event> {

    protected Event event = null;

    public Event getModel() {
        return event;
    }

    public void setModel(Event model) {
        this.event = model;
    }

}

Here is my EnterEventDetailsAction.java
@ParentPackage("enterEvent")
@Result(type=
ServletActionRedirectResult.class,value="selectLocationType",params={"method","input"})
@Validation
public class EnterEventDetailsAction extends BaseEventAction implements
Preparable {

    private Date partialStartDate;
    private String patialStartTime;
    private String partialVotingStartTime;

    public void prepare() throws Exception {
        event = new Event();
        event.setStatus(Progress.NOT_STARTED);
        event.setLastUpdateTime( Calendar.getInstance().getTime() );
    }

    public Date getPartialStartDate() {
        return partialStartDate;
    }

    @RequiredFieldValidator(message="Validation Error",
key="validate.notEmpty")
    public void setPartialStartDate(Date partialStartDate) {
        this.partialStartDate = partialStartDate;
    }

    public String getPatialStartTime() {
        return patialStartTime;
    }

    @CustomValidator(type ="timeValidator", key="validate.timeOfDay")
    public void setPatialStartTime(String patialStartTime) {
        this.patialStartTime = patialStartTime;
    }

    public String getPartialVotingStartTime() {
        return partialVotingStartTime;
    }

    @CustomValidator(type ="timeValidator", key="validate.timeOfDay")
    public void setPartialVotingStartTime(String partialVotingStartTime) {
        this.partialVotingStartTime = partialVotingStartTime;
    }

    @VisitorFieldValidator(message="Default message", fieldName="model",
shortCircuit=false, appendPrefix=false)
    public String execute() throws Exception {

        Calendar cal = Calendar.getInstance();

        cal.setTime(partialStartDate);
        TimeUtil timeUtil = new TimeUtil(patialStartTime);
        event.setStartTime( timeUtil.resolveDate( partialStartDate,
event.getTimeZoneOffset() ) );

        cal = Calendar.getInstance();
        cal.setTime(partialStartDate);
        timeUtil = new TimeUtil(partialVotingStartTime);
        event.setVotingStartTime( timeUtil.resolveDate( partialStartDate,
event.getTimeZoneOffset() ) );
        
        return SUCCESS;

    }
}

Here is my SelectLocationTypeAction.java
@ParentPackage("enterEvent")
@Result(type=
ServletActionRedirectResult.class,value="enterLocationDetails")
public class SelectLocationTypeAction extends BaseEventAction implements
Preparable {

    private Integer typeId;
    private List<Location> types;

    public Integer getTypeId() {
        return typeId;
    }

    public void setTypeId(Integer typeId) {
        this.typeId = typeId;
    }

    public List<Location> getTypes() {
        return types;
    }

    public void prepare() throws Exception {
        types = new ArrayList<Location>();
        types.add(new Address());
        types.add(new Broadcast());
    }

    public String input() throws Exception {
        if(event!=null)System.out.println("````````````````Event found in
EnterLocationDetails!input````````````````");
        else System.out.println("````````````````Event not found in
EnterLocationDetails!input````````````````");
        return INPUT;
    }

}


I am not able to persist Event object across the two requests
I am getting event as 'null' in SelectLocationTypeAction.java
-- 
View this message in context: http://www.nabble.com/Problem-using-scope-interceptor-tp25020317p25020317.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org