Stripes form, save data for using on next program excecution

582 views Asked by At

I am creating a form in Stripes. There are two text fields in the form (Name and Code) which should be filled in by user. After user inputs data, by clicking the add button, I want data to be shown on the same page (let’s say under the add button) and user could be able to input another data so that when clicking the button next time he could see all data entered from the beginning on the same page and still have the ability to input more data. I used an arraylist to save user inputs in a list and iterate through it by c:forEach in jstl. The problem is arraylist doesn’t keep data and when I input new data, it overwrites the former data. I don’t know how/where to save data so that each time user could add more data and at the same time see them all in the page.

ClassActionBean.java

package com.example.action;

public class ClassActionBean implements ActionBean {
private ActionBeanContext context;
private String name;
private String code;
private ArrayList<String> list = new ArrayList<String>();

@DefaultHandler
public Resolution showData() {
    list.add(getName());
    list.add(getCode());
    return new ForwardResolution("/WEB-INF/jsp/import.jsp");
    //return new RedirectResolution("/Class.action");
}

public ActionBeanContext getContext() { 
    return context; 
}

public void setContext(ActionBeanContext context) { 
    this.context = context; 
}

public ArrayList<String> getList() {
    return list;
}

public void setList(ArrayList<String> list) {
    this.list = list;
}

public String getName() {
    return name;
}

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

public String getCode() {
    return code;
}

public void setCode(String code) {
    this.code = code;
}

}

import.jsp

<%@page contentType="text/html;charset=ISO-8859-1" language="java" %>
<%@taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"    "http://www.w3.org/TR/html4/strict.dtd" >
<html>
<head><title>Test</title></head>
<body>
<stripes:form beanclass="com.example.action.ClassActionBean">
<table>
    <tr>
        <td>Name:</td>
        <td><stripes:text name="name"/></td>
    </tr>
    <tr>
        <td>Code:</td>
        <td><stripes:text name="code"/></td>
    </tr>
    <tr>
        <td>
            <stripes:submit name="showData" value="Add"/> 
        </td>
    </tr>

    <c:forEach var="current" items="${actionBean.list }">
    <tr>
        <td><c:out value="${current}"/></td>
    </tr>
    </c:forEach>
 </table>
 </stripes:form>
</body>
</html>
1

There are 1 answers

0
Nestor Hernandez Loli On

How about using @Wizard annotation, here a good example https://stripesframework.atlassian.net/wiki/display/STRIPES/Wizard+Forms