【发布时间】:2015-04-25 18:29:45
【问题描述】:
我的ActionForm 中有一个List<String>,它必须在JSP 页面中使用Struts1.1 表示为文本字段
List<String> url=new ArrayList<String>();
public List<String> getUrl() {
return url;
}
public void setUrl(List<String> url) {
this.url = url;
}
以下是我在 JSP 页面中使用的代码
<logic:iterate id="urlIterate" name="pForm" property="url">
<html:text property="?????" name="urlIterate"/>
</logic:iterate>
<html:text> 对List<SomeClass> 很有效,因为属性可以指向特定变量,List<SomeClass> 充当 bean。
<logic:iterate id="listUserId" property="listUsers" name="pForm">
<html:text name="listUserId" property="username"/>
</logic:iterate>
其中 listUsers 是 List 和 User 类型的类
私有列表列表用户;
在property="username"username是User类里面的一个变量
为List<String>
<bean:write name="urlIterate" />
我没有发现使用<bean:write> 显示为文本的问题,因为它只有name 属性。
但是要使用<html:text>,我们需要添加另一个强制属性property。
谁能帮帮我。 property='?????' 使用什么值才能使 html:text 正常工作。
提前致谢
提供更多代码.. UI 的 JSP 页面。
<%@taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<html>
<head>
</head>
<body>
<html:form action="/plist">
<h1>Struts <logic:iterate> example</h1>
<logic:iterate property="listMsg" name="pForm" id="listMsgId">
<p>
List Messages </p> <html:text property="listMsgId" indexed="true"/>
</logic:iterate>
<html:submit/>
</html:form>
</body>
</html>
动作类:
public class PrintMsgAction extends Action {
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception {
List<OptionsListCollection> listoptions=new ArrayList<OptionsListCollection>();
for(int i=0;i<10;i++){
listoptions.add(new OptionsListCollection("Option"+i, "OptionValue"+i));
}
List<String> listMsg = new ArrayList<String>();
listMsg.add("Message A");
listMsg.add("Message B");
listMsg.add("Message C");
listMsg.add("Message D");
PrintForm pForm=(PrintForm)form;
pForm.setListMsg(listMsg);
return mapping.findForward("plist");
}
}
和ActionForm
public class PrintForm extends ActionForm{
private List<String> listMsg;
public List<String> getListMsg() {
return listMsg;
}
public void setListMsg(List<String> listMsg) {
this.listMsg = new ArrayList<String>();
this.listMsg = listMsg;
}
}
【问题讨论】:
标签: java jsp struts jsp-tags struts-1