Java 以Struts 1表单显示列表
我必须编写一个backoffice页面,以确定在Struts 1应用程序中,哪些商店必须显示在frontoffice页面上。因此,我有一个包含在表单中的商店(代码中为精品店)列表 表格:Java 以Struts 1表单显示列表,java,struts,taglib,struts-1,Java,Struts,Taglib,Struts 1,我必须编写一个backoffice页面,以确定在Struts 1应用程序中,哪些商店必须显示在frontoffice页面上。因此,我有一个包含在表单中的商店(代码中为精品店)列表 表格: public class ListeBoutiquesForm extends ActionForm { private List<Boutique> boutiques = new ArrayList<Boutique>(); public List<Bout
public class ListeBoutiquesForm extends ActionForm {
private List<Boutique> boutiques = new ArrayList<Boutique>();
public List<Boutique> getBoutiques() {
return boutiques;
}
public void setBoutiques(List<Boutique> boutiques) {
this.boutiques = boutiques;
}
}
精品类包含一个id、一个名称和一个名为“selected”的布尔值。我想为精品店列表中的每个元素显示一个复选框,并显示一个调用save操作的submit按钮,但是我缺乏编写JSP的Struts taglib知识。你能帮忙吗?我知道它应该包含一个逻辑:迭代
,一个html:checkbox
,可能还有一个html:hidden
来存储id,但我感觉有些东西缺失了,有些东西我不明白。可以这么说,它们是如何联系在一起的?如何在保存操作中获取具有更新值的ListFinanesForm
编辑:
根据Susie的建议,我提出了以下JSP:
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<html:errors/>
<html:form action="/admin/boutiqueviparis">
<input type="hidden" name="reqCode" value="sauverBoutiques" />
<table class="tableStatic noHead">
<logic:notEmpty name ="viparisListeBoutiquesForm" property="boutiques">
<logic:iterate id="boutique" name ="viparisListeBoutiquesForm" property="boutiques">
<tr>
<td>
<html:hidden name ="boutique" property="id" />
<bean:write name="boutique" property="nom" />
</td>
<td>
<html:checkbox name="boutique" property="selected" value="true" />
</td>
</tr>
</logic:iterate>
<html:submit styleClass="boutonrouge" value="Valider" onclick="this.form.reqCode.value='sauverBoutiques';return window.confirm('Modification validée');"/>
</logic:notEmpty>
</table>
</html:form>
我可以在Hibernate日志中看到update语句,但实际上没有保存任何内容。我记录了我的选择的字段的值,实际上,它是初始值,然后在显示的表单中更改它。有点令人费解
编辑:
实际上,
在最终的HTML中显示为
,用“id”代替id值。但是我不知道如何解决这个问题…下面是你应该做的事情。struts-config.xml文件将所有内容粘合在一起的配置文件
parameter ---> which method to call
name---> name of the action form
path---> URL
type---> action class that is invoked by the above url.
forward---->where to forward once it's done.
如您所见,我在myMethod()中设置了列表,并在下面的jsp中设置了访问权限
JSP页面:
<form name="myForm" action="myAction.do" method="post">
<logic:notEmpty name="myForm" property="myList">
<logic:iterate id="boutique" name="myForm" property="myList" type="com.Boutique">
<tr>
<td><bean:write name="boutique" property="id" /> </td>
<td><bean:write name="boutique" property="name" /></td>
<td><bean:write name="boutique" property="selected" /></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</form>
public ActionForward myMethod(ActionMapping actionMapping,
ActionForm myForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
List<Boutique> myList = new ArrrayList<Boutique>();
form.setMyList(myList);
return mapping.findForward("success");
}
在我的动作类方法中:
<form name="myForm" action="myAction.do" method="post">
<logic:notEmpty name="myForm" property="myList">
<logic:iterate id="boutique" name="myForm" property="myList" type="com.Boutique">
<tr>
<td><bean:write name="boutique" property="id" /> </td>
<td><bean:write name="boutique" property="name" /></td>
<td><bean:write name="boutique" property="selected" /></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</form>
public ActionForward myMethod(ActionMapping actionMapping,
ActionForm myForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
List<Boutique> myList = new ArrrayList<Boutique>();
form.setMyList(myList);
return mapping.findForward("success");
}
公共ActionForward myMethod(ActionMapping ActionMapping,
ActionForm myForm、HttpServletRequest、HttpServletRequest、,
HttpServletResponse(HttpServletResponse)引发异常{
List myList=新的arraylist();
表格.setMyList(myList);
返回映射。findForward(“成功”);
}
struts config.xml
<struts-config>
<form-beans>
<form-bean name="myForm" type="com.usps.nom.tops.web.struts.form.transportation.ITransportationInquiryDynaForm">
</form-bean>
</form-beans>
<action-mappings>
<action path="/myAction" type="com.MyAction"
name="myForm" scope="session" validate="false"
parameter="myMethod">
<forward name="success" path="tile.view"></forward>
</action>
</action-mappings>
</struts-config>
以下是您应该做的事情。struts-config.xml文件将所有内容粘合在一起的配置文件
parameter ---> which method to call
name---> name of the action form
path---> URL
type---> action class that is invoked by the above url.
forward---->where to forward once it's done.
如您所见,我在myMethod()中设置了列表,并在下面的jsp中设置了访问权限
JSP页面:
<form name="myForm" action="myAction.do" method="post">
<logic:notEmpty name="myForm" property="myList">
<logic:iterate id="boutique" name="myForm" property="myList" type="com.Boutique">
<tr>
<td><bean:write name="boutique" property="id" /> </td>
<td><bean:write name="boutique" property="name" /></td>
<td><bean:write name="boutique" property="selected" /></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</form>
public ActionForward myMethod(ActionMapping actionMapping,
ActionForm myForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
List<Boutique> myList = new ArrrayList<Boutique>();
form.setMyList(myList);
return mapping.findForward("success");
}
在我的动作类方法中:
<form name="myForm" action="myAction.do" method="post">
<logic:notEmpty name="myForm" property="myList">
<logic:iterate id="boutique" name="myForm" property="myList" type="com.Boutique">
<tr>
<td><bean:write name="boutique" property="id" /> </td>
<td><bean:write name="boutique" property="name" /></td>
<td><bean:write name="boutique" property="selected" /></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</form>
public ActionForward myMethod(ActionMapping actionMapping,
ActionForm myForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
List<Boutique> myList = new ArrrayList<Boutique>();
form.setMyList(myList);
return mapping.findForward("success");
}
公共ActionForward myMethod(ActionMapping ActionMapping,
ActionForm myForm、HttpServletRequest、HttpServletRequest、,
HttpServletResponse(HttpServletResponse)引发异常{
List myList=新的arraylist();
表格.setMyList(myList);
返回映射。findForward(“成功”);
}
struts config.xml
<struts-config>
<form-beans>
<form-bean name="myForm" type="com.usps.nom.tops.web.struts.form.transportation.ITransportationInquiryDynaForm">
</form-bean>
</form-beans>
<action-mappings>
<action path="/myAction" type="com.MyAction"
name="myForm" scope="session" validate="false"
parameter="myMethod">
<forward name="success" path="tile.view"></forward>
</action>
</action-mappings>
</struts-config>
最后,我根本没有使用Struts html:checkbox标记。经过一些研究,Struts 1似乎没有很好地处理复选框 这是我当前的JSP:
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<html:errors/>
<html:form action="/admin/boutiqueviparis">
<input type="hidden" name="reqCode" value="sauverBoutiques" />
<table class="tableStatic noHead">
<logic:notEmpty name ="viparisListeBoutiquesForm" property="boutiques">
<logic:iterate id="boutique" name ="viparisListeBoutiquesForm" property="boutiques">
<tr>
<td>
<html:hidden name="boutique" property="id" />
<bean:write name="boutique" property="nom" />
</td>
<td>
<logic:equal name="boutique" property="selected" value="true">
<input type="checkbox" name="boutique_<bean:write name="boutique" property="id" />" value="<bean:write name="boutique" property="id" />" checked="1" />
</logic:equal>
<logic:equal name="boutique" property="selected" value="false">
<input type="checkbox" name="boutique_<bean:write name="boutique" property="id" />" value="<bean:write name="boutique" property="id" />" />
</logic:equal>
</td>
</tr>
</logic:iterate>
<html:submit styleClass="boutonrouge" value="Valider" onclick="this.form.reqCode.value='sauverBoutiques';return window.confirm('Modification validée');"/>
</logic:notEmpty>
</table>
</html:form>
最后,我根本没有使用Struts html:checkbox标记。经过一些研究,Struts 1似乎没有很好地处理复选框 这是我当前的JSP:
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<html:errors/>
<html:form action="/admin/boutiqueviparis">
<input type="hidden" name="reqCode" value="sauverBoutiques" />
<table class="tableStatic noHead">
<logic:notEmpty name ="viparisListeBoutiquesForm" property="boutiques">
<logic:iterate id="boutique" name ="viparisListeBoutiquesForm" property="boutiques">
<tr>
<td>
<html:hidden name="boutique" property="id" />
<bean:write name="boutique" property="nom" />
</td>
<td>
<logic:equal name="boutique" property="selected" value="true">
<input type="checkbox" name="boutique_<bean:write name="boutique" property="id" />" value="<bean:write name="boutique" property="id" />" checked="1" />
</logic:equal>
<logic:equal name="boutique" property="selected" value="false">
<input type="checkbox" name="boutique_<bean:write name="boutique" property="id" />" value="<bean:write name="boutique" property="id" />" />
</logic:equal>
</td>
</tr>
</logic:iterate>
<html:submit styleClass="boutonrouge" value="Valider" onclick="this.form.reqCode.value='sauverBoutiques';return window.confirm('Modification validée');"/>
</logic:notEmpty>
</table>
</html:form>