Cant access the value of textfield element in action class
Here is the detail of the question
In struts.......
<action name="ICUGramEntry" class="sfa.view.ICUAction">
<result name="success" type="tiles">icuGramTiles</result>
</action>
In ICUAction class.............
package sfa.view;
import java.util.Map;
import java.util.TreeMap;
import com.opensymphony.xwork2.ActionSupport;
public class ICUAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -5693693076048575455L;
private Map<String, String> FieldType;
private String rad;
public String execute(){
System.out.println("ICUAction.execute()");
setFieldType(new TreeMap<String, String>());
setRad("ABC");
getFieldType().put("003", "RBM");
getFieldType().put("004", "ABM");
getFieldType().put("005", "MSR");
return SUCCESS;
}
public void setFieldType(Map<String, String> fieldType) {
FieldType = fieldType;
}
public Map<String, String> getFieldType() {
return FieldType;
}
public void setRad(String rad) {
this.rad = rad;
}
public String getRad() {
return rad;
}
}
In tiles......
<definition name="icuGramTiles" extends="baseLayout">
<put-attribute name="body" value="/icuGram.jsp"/>
</definition>
/icuGram.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ taglib prefix="s" uri="/struts-tags"%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<script type="text/javascript">
<body>
<span class="pageHeader" >ICU GRAM</span>
<s:form action="ICUGramInsert" method="POST" theme="simple">
<jsp:include page="/headerbar.jsp"></jsp:include>
<s:select id="fieldtype" list="FieldType" name="TYPE" cssClass="smallSelect" cssStyle="width:200px;"
"></s:select>
<s:textfield name="rad"></s:textfield>
</body>
</html>
i can view the value in textfield on jsp as
ABC
as set in action
setRad("ABC");
from here ICUGramInsert action is called
<action name="ICUGramInsert"
class="sfa.view.ICUGramInsert" >
开发者_StackOverflow社区 <result type="chain">/Detail.jsp</result>
</action>
and it goes to sfa.view.DetailAction
package sfa.view;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
public class ICUGramInsert extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String TYPE;
public String execute()
{
System.out.println("DetailAction.execute()...1"+this.getTYPE());
System.out.println("DetailAction.execute()...2"+this.getrad());
return SUCCESS;
}
public void setTYPE(String tYPE) {
TYPE = tYPE;
}
public String getTYPE() {
return TYPE;
}
}
i get the console out put of this.getTYPE() as follows=============> DetailAction.execute()...1null DetailAction.execute()...2null
I am not sure why you have used ServletRequestAware interceptor here since Struts2 automatically perform data transfer both way.
Regarding your execute method its signature is not as per the Framework it should be
public String execute () throw exception {
}
However, when I try to retrieve this value after page is submitted in action I am not able to get this value ... by getParameter method on the request object.
That sounds like you aren't submitting the value to the action from your form.
Make sure that you are:
- Submitting the value of first name to the action via your form
- Prefer having an instance field called
firstName
that has a getter and a setter, rather than accessing the String values directly from theHttpServletRequest
精彩评论