I have two methods in my Action class preprocess()
and getThresholdData()
:
I set a
List<String>
variable in thepreprocess()
method (called when the page loads);Then from the JSP page, a form is submitted and
getThresholdData()
is called.
JSP:
<body>
<s:form action="getThresholdDataConfigureTspThreshold">
<s:select list="tspNames" label="Select TSP:" name="tspName"></s:select>
<s:radio list="{'Default', 'Latest'}" label="Select Threshold type:"
name="thresholdType"></s:radio>
<s:submit value="Submit"></s:submit>
</s:form>
</body>
tspNames
(the list to iterate over) is set in the preprocess()
method of the action class as soon as page loads, like follows:
<a href="/gma/preprocessConfigureTspThreshold" />
Action class:
public class ConfigureTspThresholdAction extends ActionSupport{
private static final String DISPLAY = "display";
private Map session;
private List<String> tspNames;
private List<String> thresholdParametres;
private String tspName;
private String thresholdType;
public String preprocess() {
// Get tspNames from server after Table creation
tspNames = new ArrayList<String>();
tspNames.add("RELIANCE");
tspNames.add("AIRTEL");
tspNames.add("TATA");
tspNames.add("BSNL");
tspNames.add("MTNL");
session.put("tspNames", tspNames);
return DISPLAY;
}
public String getThresholdData(){
// Get parametres from server after creating table
thresholdParametres = new ArrayList<String>();
thresholdParametres.add("1");
thresholdParametres.add("2");
thresholdParametres.add("3");
thresholdParametres.add("4");
thresholdParametres.add("5");
System.out.println("************" + tspNames);
return DISPLAY;
}
/** GETTER AND SETTERS*/
}
struts.xml:
<action name="*ConfigureTspThreshold"
class="gma.struts.ConfigureTspThresholdAction" method="{1}">
<result name="display">pages/ConfigureTspThresholdInput.jsp</result>
</action>
The flow is:
- JSP loads
preprocess
is called where list is set. - User fills and submits a form, some work is done serverside and the user redirected to same JSP.
However the error comes as JSP is not able to be displayed as the list tspNames
which was set in preprocess()
method is coming null
.
Here, when I try to print the list
System.out.println("************" + tspNames);
which I had set in the first function it's value is null
.
Why is it so? Is the variable value lost after form is submitted? Is there to do something with session concept?