Question

I am new to webflow and I am facing several questions here. Basically I am want to bind a variable to a view state select option set and use that in the next view. For that I have used the following code.

<var name="flowScope.jobIdString" class="java.lang.String" />

<input name="userId" type="java.lang.Long" />

<on-start>
    <set name="userId" value="1234"></set>
</on-start>

<view-state id="startJob" view="/WEB-INF/jsp/startJob.jsp">

    <on-entry>
        <evaluate expression="jobService.getAllJobsForUser(userId)"
            result="flowScope.jobs">
            </evaluate>
    </on-entry>
    <transition on="createNew" to="createNewJob" />
    <transition on="editJob" to="editJob" />
</view-state>

<action-state id="createNewJob">
    <evaluate expression="patientBean" result="flowScope.patient" />
    <transition to="patientinfo" />
</action-state>

<action-state id="editJob">
    <evaluate expression="patientService.getPatientInfo(jobId)"
        result="flowScope.patient" />
    <transition to="patientinfo" />
</action-state>

<view-state id="patientinfo" model="patient"
    view="/WEB-INF/jsp/patientInfo.jsp">
</view-state>

Here I can access the first view but not going to the next view when I click either button. This is my startjob.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!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>Insert title here</title>
</head>
<body>



    <select size="8" name="jobIdString">
        <c:forEach items="${jobs}" var="job">
            <option value="job.id">${job.name}</option>
        </c:forEach>
    </select>

    <br />

    <input type="submit" name="_eventId_createNew" value="createNew">
    <input type="submit" name="_eventId_editJob" value="editJob">

</body>
</html>

This is my patientInfo.jsp file

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!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>Insert title here</title>
</head>
<body>
    <form:form modelAttribute="patient">
        <form:hidden path="id" />
        <table>
            <tr>
                <td>Name:</td>
                <td><form:input path="name" /></td>
            </tr>
            <tr>
                <td>Age:</td>
                <td><form:input path="age" /></td>
            </tr>
            <tr>
                <td><input type="submit" value="Save and Close" /></td>
                <td><input type="submit" value="Save and Continue" /></td>
            </tr>
        </table>
    </form:form>
</body>
</html>

Here I am binding a patient model to this view.

<webflow:flow-registry id="flowRegistry">
    <webflow:flow-location path="/WEB-INF/flow/webflow-flow.xml"
        id="webflow" />
</webflow:flow-registry>
<webflow:flow-executor id="flowExecutor"
    flow-registry="flowRegistry" />
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    <property name="flowRegistry" ref="flowRegistry" />
    <property name="order" value="0" />
</bean>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
    <property name="flowExecutor" ref="flowExecutor" />
</bean>

<bean id="jobService" class="com.b.webfolwprototype.service.JobService" />
<bean id="patientService" class="com.brandix.webfolwprototype.service.PatientService"></bean>

<bean id="patientBean" class="com.b.webfolwprototype.model.Patient"
    scope="prototype" />

<bean id="jobBean" class="com.b.webfolwprototype.model.Job"
    scope="prototype" />

This is my webflow config file (above).

basically this is not working properly.

  1. So I would like to resolve these following questions as well.

  2. How does these models are working without any wiring up. I have not used any of the annotations bean definitions are in the webflow config file (may be this might not be wired up correcly).

  3. Can I bid a variable like string (in this case the jobId) to a view (as I have tried in the startjob.jsp) If this is wrong how can this be done.

This is my PatientService

public class PatientService {

public void save(Patient patient) {
    System.out.println("save patinet");
}

public Patient getPatientInfo(Long jobId){
    Patient patient = new Patient();
    patient.setAge(35);
    patient.setName("test name");
    return patient;
}

}

This is my JobService

public class JobService {

public List<Job> getAllJobsForUser(Long userId) {

    ArrayList<Job> jobList = new ArrayList<Job>();
    Job job1 = new Job();
    job1.setId((long) 1234);
    job1.setName("Test Job Name");

    Job job2 = new Job();
    job2.setId((long) 1235);
    job2.setName("Test Job Name 2");

    jobList.add(job1);
    jobList.add(job2);
    return jobList;
}

}

These are my models

    public class Job implements Serializable {

    private static final long serialVersionUID = 4979685043689356058L;
    private Long id;
    private String name;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}


public class Patient implements Serializable {

    private static final long serialVersionUID = -1541400280884340541L;
    private String name;
    private int age;
    private Long patientId;

    public Long getPatientId() {
        return patientId;
    }

    public void setPatientId(Long patientId) {
        this.patientId = patientId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int i) {
        this.age = i;
    }

}
Was it helpful?

Solution

Your flow enters into view startjob.jsp which is the launching point. From here, swf doesn't know how to resume flow when you are clicking on the specified buttons. So in order to resume the flow, include the following in your startjob.jsp:

     <input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top