I have a List<String>
in my ActionForm
which has to be represented as a text field in the JSP page using Struts1.1
List<String> url=new ArrayList<String>();
public List<String> getUrl() {
return url;
}
public void setUrl(List<String> url) {
this.url = url;
}
The Following is the code that I have used inside JSP page
<logic:iterate id="urlIterate" name="pForm" property="url">
<html:text property="?????" name="urlIterate"/>
</logic:iterate>
<html:text>
is working good for List<SomeClass>
because property can be point to a particular variable and List<SomeClass>
acts as a bean.
<logic:iterate id="listUserId" property="listUsers" name="pForm">
<html:text name="listUserId" property="username"/>
</logic:iterate>
where listUsers is a List
with User
type of class private List listUsers; In property="username"
username
is a variable inside User
Class
For List<String>
<bean:write name="urlIterate" />
I don't find issue to display as a text using <bean:write>
since it has only name
attribute. But to use <html:text>
we need to add another mandatory attribute property
.
Can any one please help me out. what value to be used for property='?????'
in order to make the html:text
to work correctly.
Thanks in advance
Providing more code.. JSP page for UI.
<%@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>
Action Class:
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");
}
}
and 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;
}
}
Check struts-logic-iterate-example . Your code should read -
<logic:iterate id="urlIterate" name="pForm" >
<html:text property="urlIterate" indexed="true"/>
</logic:iterate>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.