Hi All, I am new to struts and creating a struts application having workflow. for this workflow I am using the below code in the struts2.xml
<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="com.fdar.apress.s2.actions.event.BaseEventAction"> <interceptor-ref name="eventStack"> start </interceptor-ref> <result>/WEB-INF/jsp/event/enterEventDetails-input.jsp</result> </action> <action name="completeEvent" class="com.fdar.apress.s2.actions.event.BaseEventAction"> <interceptor-ref name="eventStack"> end </interceptor-ref> <result>/WEB-INF/jsp/event/eventReview.jsp</result> </action> <action name="flashedSelectEventType" class="com.fdar.apress.s2.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> ------------------------------------ BaseEventAction is a kind of dummy action package com.fdar.apress.s2.actions.event; import com.fdar.apress.s2.domain.Event; import com.fdar.apress.s2.actions.BaseAction; import com.opensymphony.xwork2.ModelDriven; 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; } } ================================================= Now in the enterEventDetails-input.jsp I am creating a event and then moving forword for selection of the location. <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="/struts-tags" prefix="s"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title><s:text name="createEvent.enterEvent.title"/></title> </head> <body> <s:form action="enterEventDetails" namespace="/event" method="post"> <s:textfield key="event.name" name="name"></s:textfield> <s:textfield key="event.startDate" name="partialStartDate"></s:textfield> <s:textfield key="event.startTime" name="partialStartTime"></s:textfield> <s:textfield key="event.timeZoneOffset" name="timeZoneOffset"></s:textfield> <s:textfield key="event.votingStartTime" name="partialVotingStartTime"></s:textfield> <s:textfield key="event.duration" name="duration"></s:textfield> <s:submit key="button.create"/> </s:form> </body> </html> ================================================= package com.fdar.apress.s2.actions.event; import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator; import com.opensymphony.xwork2.validator.annotations.CustomValidator; import com.opensymphony.xwork2.validator.annotations.Validation; import com.opensymphony.xwork2.validator.annotations.VisitorFieldValidator; import com.fdar.apress.s2.actions.user.DebuggingFile; import com.fdar.apress.s2.domain.Event; import com.fdar.apress.s2.domain.Progress; import com.fdar.apress.s2.util.TimeUtil; import java.util.Calendar; import java.util.Date; import java.text.DateFormat; import org.apache.struts2.config.ParentPackage; import org.apache.struts2.config.Result; import org.apache.struts2.config.Results; import org.apache.struts2.dispatcher.ServletActionRedirectResult; @ParentPackage("enterEvent") @Results (value={ @Result(type= ServletActionRedirectResult.class, value="selectLocation",params={"method","input"}), @Result(type= ServletActionRedirectResult.class, name="selectType",value="/event/flashedSelectEventType.action") }) @Validation public class EnterEventDetailsAction extends BaseEventAction implements Preparable { private Date partialStartDate; private String partialStartTime; private String partialVotingStartTime; public void prepare() throws Exception { DebuggingFile debugFile = new DebuggingFile(); debugFile.writeToDebugFile("CLASS::EnterEventDetailsAction METHOD::prepare Begin"); 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 getPartialStartTime() { return partialStartTime; } @CustomValidator(type ="timeValidator", key="validate.timeOfDay") public void setPartialStartTime(String partialStartTime) { this.partialStartTime = partialStartTime; } 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(partialStartTime); 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; } } ============================================ Then its redirecting me to select a location and after choosing the location I am using the class to add event to location package com.fdar.apress.s2.actions.event; import org.apache.struts2.dispatcher.ServletActionRedirectResult; import org.apache.struts2.config.ParentPackage; import org.apache.struts2.config.Result; import com.fdar.apress.s2.services.LocationService; import com.fdar.apress.s2.actions.user.DebuggingFile; import com.fdar.apress.s2.domain.Location; import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator; import com.opensymphony.xwork2.validator.annotations.Validation; import java.util.List; @ParentPackage("enterEvent") @Result(type= ServletActionRedirectResult.class,value="selectContestants") @Validation public class SelectLocationAction extends BaseEventAction implements Preparable { private List<Location> locations; private Long selectedLocation = null; private LocationService service; public void setLocationService(LocationService service) { this.service = service; } public void prepare() throws Exception { locations = service.findAll(); } public List<Location> getLocations() { return locations; } public Long getSelectedLocation() { return selectedLocation; } @RequiredFieldValidator(message = "Default message", key = "validation.selectLocation") public void setSelectedLocation(Long selectedLocation) { this.selectedLocation = selectedLocation; } public String input() { return INPUT; } public String execute() throws Exception { event.setLocation(service.findById(selectedLocation)); return SUCCESS; } } =========================== Now I am getting the issue that the event object is coming null during the second action. I mean giving a null pointer exception on the line >> event.setLocation(service.findById(selectedLocation)); As I understand the problem is I am not able to preserve the session object in the session object. Please help. Thanks Vipin -- View this message in context: http://old.nabble.com/Struts-WorkFlow-object-created-in-first-request-becoming-null-tp26571682p26571682.html Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org