- 浏览: 102065 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
krystal_0424:
...
并发控制-两阶段锁定协议 -
medicine:
...
mysql的repeatable read事务隔离级别的测试 -
atomicsun:
写的太好了 赞个,正需要这个测试 参考 ,多谢博主
mysql的repeatable read事务隔离级别的测试 -
herowzz:
Service+DAO废弃了,请问Query的这段代码放在哪里 ...
对WJD(WEB+JAVA+DB)编程,JAVA部分的看法 -
Kisses99:
这样做表面上看起来简洁,但遇到复杂的查询逻辑,还是很难处理
对WJD(WEB+JAVA+DB)编程,JAVA部分的看法
问题1.从客户端传来的id,需要转化成持久化对象,webwork默认会为我们创建出空对象,但不满足,希望webwork能按照id值绑定持久化对象.
解决办法:创建自己的转化器
1.创建xwork-conversion.properties,内容如下
其中CommonEntity为所有持久化实体类的超类,更详细的资料见:
http://wiki.opensymphony.com/display/XW/XWork+Conversion
2.实现自定义转换器
在这里,因为不了解webwork有什么合适的机制对converter的创建进行控制,因此,converter使用静态属性delegate,该属性由ServletContextListener来注入
这样便可完成参数的绑定了,页面传的参数形式,譬如 foo.bar=1即可
问题2:如何绑定到列表
1.使用java5泛型,xwork..-tiger.jar
2.客户端参数形式changedList[0].id=1,changedList[0].name=name,changedList[1].id=2,changedList[1].name=name2
3.预load对象,以使得其它属性能正确的绑定到对象中.处理逻辑为"先过滤出id,对起进行参数绑定,之后,再交由webwork自带的参数拦截器去绑定其它的参数",拦截器代码如下(保留使用原有的params拦截器):
其中,changedList表示的是修改过的对象,newList表示的是新增的对象
总结:需要建立Xwork的Converter,Interceptor。servlet的ServletContextListener为converter注入orm的持久对象查找方法;orm提供find(class,id)这样的方法
解决办法:创建自己的转化器
1.创建xwork-conversion.properties,内容如下
com.abest.common.domain.CommonEntity=com.abest.common.EntityWebworkConverter
其中CommonEntity为所有持久化实体类的超类,更详细的资料见:
http://wiki.opensymphony.com/display/XW/XWork+Conversion
2.实现自定义转换器
public class EntityWebworkConverter extends WebWorkTypeConverter { public static EntityWebworkConverterDelegate delegate = null; public EntityWebworkConverter() { } public Object convertFromString(Map map, String[] strings, Class toClass) { return delegate.convertFromString(map,strings,toClass); } public String convertToString(Map map, Object o) { return delegate.convertToString(map,o); } }
public class EntityWebworkConverterDelegate extends WebWorkTypeConverter { private QueryService queryService = null; public EntityWebworkConverterDelegate(QueryService queryService) { this.queryService = queryService; } public Object convertFromString(Map map, String[] strings, Class toClass) { if(strings.length > 0) { int id = 0; try { id = Integer.parseInt(strings[0]); } catch (NumberFormatException e) { } if(id > 0) { return queryService.find(toClass,id); } } try { return toClass.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } public void setQueryService(QueryService queryService) { this.queryService = queryService; } public String convertToString(Map map, Object o) { return null; } }
在这里,因为不了解webwork有什么合适的机制对converter的创建进行控制,因此,converter使用静态属性delegate,该属性由ServletContextListener来注入
这样便可完成参数的绑定了,页面传的参数形式,譬如 foo.bar=1即可
问题2:如何绑定到列表
1.使用java5泛型,xwork..-tiger.jar
2.客户端参数形式changedList[0].id=1,changedList[0].name=name,changedList[1].id=2,changedList[1].name=name2
3.预load对象,以使得其它属性能正确的绑定到对象中.处理逻辑为"先过滤出id,对起进行参数绑定,之后,再交由webwork自带的参数拦截器去绑定其它的参数",拦截器代码如下(保留使用原有的params拦截器):
public class AnotherGridEditDataBindInterceptor extends AroundInterceptor { protected void after(ActionInvocation actionInvocation, String s) throws Exception { } protected void before(ActionInvocation actionInvocation) throws Exception { Object action = actionInvocation.getAction(); Map map = actionInvocation.getInvocationContext().getParameters(); Map entityIdMap = new HashMap(); for(int i = 0;i < 200;i++) { String key = "changedList[" + i + "].id"; String[] ids = (String[]) map.get(key); if(ids != null && ids.length > 0) { entityIdMap.put("changedList["+i+"]",ids); map.remove(key); } } for(int i = 0;i < 200;i++) { String key = "newList[" + i + "].id"; String[] ids = (String[]) map.get(key); if(ids != null && ids.length > 0) { entityIdMap.put("newList["+i+"]",ids); map.remove(key); } } bindParametersToTarget(entityIdMap,action); } private void bindParametersToTarget(Map propertiesValue, Object target) { ActionContext invocationContext = ActionContext.getContext(); OgnlValueStack stack = null; Object preRoot = null; try { invocationContext.put(InstantiatingNullHandler.CREATE_NULL_OBJECTS, Boolean.TRUE); invocationContext.put(XWorkMethodAccessor.DENY_METHOD_EXECUTION, Boolean.TRUE); invocationContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE); if (propertiesValue != null) { stack = ActionContext.getContext().getValueStack(); preRoot = stack.pop(); stack.push(target); for (Iterator iterator = propertiesValue.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); stack.setValue(entry.getKey().toString(), entry.getValue()); } } } finally { invocationContext.put(InstantiatingNullHandler.CREATE_NULL_OBJECTS, Boolean.FALSE); invocationContext.put(XWorkMethodAccessor.DENY_METHOD_EXECUTION, Boolean.FALSE); invocationContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.FALSE); if (preRoot != null) { stack.pop(); stack.push(preRoot); } } } }
其中,changedList表示的是修改过的对象,newList表示的是新增的对象
总结:需要建立Xwork的Converter,Interceptor。servlet的ServletContextListener为converter注入orm的持久对象查找方法;orm提供find(class,id)这样的方法
评论
9 楼
lijiangt
2007-06-28
不过感觉楼上几位思路更好,这样最简单。
8 楼
lijiangt
2007-06-28
主要是利用DynaBean,从客户端提交的数据都保存导DynaBean里面,然后再通过beanutils拷贝到实体对象里面去, 现在准备用struts2,正打算实现一个拦截器,将客户端表单提交过来的数据保存到DynaBean对象里面,然后再手动拷贝导实体对象。
7 楼
lijiangt
2007-06-28
我最近也在思考这个问题,之前在struts 1.3.8里面都是这样做的:<br/>
struts-config.xml 表单配置:<br/>
<div class='code_title'>xml 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-xml' start='1'>
<li class='alt'><span><span class='tag'><</span><span class='tag-name'>form-bean</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"projectForm"</span><span> </span></span></li>
<li class=''><span> <span class='attribute'>type</span><span>=</span><span class='attribute-value'>"org.apache.struts.validator.LazyValidatorForm"</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span><span class='tag'></</span><span class='tag-name'>form-bean</span><span class='tag'>></span><span> </span></span></li>
</ol>
</div>
<br/>
struts-config.xml action-mapping配置:<br/>
<div class='code_title'>xml 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-xml' start='1'>
<li class='alt'><span><span class='tag'><</span><span class='tag-name'>action</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project"</span><span> </span></span></li>
<li class=''><span> <span class='attribute'>type</span><span>=</span><span class='attribute-value'>"com.bupticet.strutsinterceptor.InterceptorActionProxy"</span><span> </span></span></li>
<li class='alt'><span> <span class='attribute'>name</span><span>=</span><span class='attribute-value'>"projectForm"</span><span> </span><span class='attribute'>parameter</span><span>=</span><span class='attribute-value'>"method"</span><span> </span><span class='attribute'>scope</span><span>=</span><span class='attribute-value'>"request"</span><span> </span></span></li>
<li class=''><span> <span class='attribute'>validate</span><span>=</span><span class='attribute-value'>"false"</span><span> </span><span class='attribute'>cancellable</span><span>=</span><span class='attribute-value'>"true"</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"add-success"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/add_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"save-success"</span><span> </span></span></li>
<li class='alt'><span> <span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project.do?method=view&amp;id="</span><span> </span><span class='attribute'>redirect</span><span>=</span><span class='attribute-value'>"true"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"save-cancel"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project.do"</span><span> </span></span></li>
<li class='alt'><span> <span class='attribute'>redirect</span><span>=</span><span class='attribute-value'>"true"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"save-failure"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/add_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"edit-success"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/edit_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"view-success"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/view_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"list-success"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/list_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"update-failure"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/edit_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"update-cancel"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project.do"</span><span> </span></span></li>
<li class=''><span> <span class='attribute'>redirect</span><span>=</span><span class='attribute-value'>"true"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"update-success"</span><span> </span></span></li>
<li class=''><span> <span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project.do?method=view&amp;id="</span><span> </span><span class='attribute'>redirect</span><span>=</span><span class='attribute-value'>"true"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"delete-success"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project.do?method=list"</span><span> </span><span class='attribute'>redirect</span><span>=</span><span class='attribute-value'>"true"</span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"search-page"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/search_project.jsp"</span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span><span class='tag'></</span><span class='tag-name'>action</span><span class='tag'>></span><span> </span></span></li>
</ol>
</div>
<br/>
<br/>
页面表单:<br/>
<div class='code_title'>xml 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-xml' start='1'>
<li class='alt'><span><span class='tag'><</span><span class='tag-name'>html:form</span><span> </span><span class='attribute'>action</span><span>=</span><span class='attribute-value'>"/project?method=save"</span><span> </span><span class='attribute'>method</span><span>=</span><span class='attribute-value'>"post"</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>width</span><span>=</span><span class='attribute-value'>'10%'</span><span> nowrap </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"boxHead"</span><span class='tag'>></span><span>项目名称:</span><span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>background</span><span>=</span><span class='attribute-value'>"../images/leftbg2.gif"</span><span class='tag'>></span><span class='tag'><</span><span class='tag-name'>html:text</span><span> </span><span class='attribute'>property</span><span>=</span><span class='attribute-value'>"name"</span><span> </span><span class='attribute'>size</span><span>=</span><span class='attribute-value'>'100'</span><span> </span><span class='attribute'>maxlength</span><span>=</span><span class='attribute-value'>'100'</span><span class='tag'>/></span><span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'></</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>width</span><span>=</span><span class='attribute-value'>'10%'</span><span> nowrap </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"boxHead"</span><span class='tag'>></span><span>项目编号:</span><span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>background</span><span>=</span><span class='attribute-value'>"../images/leftbg2.gif"</span><span class='tag'>></span><span class='tag'><</span><span class='tag-name'>html:text</span><span> </span><span class='attribute'>property</span><span>=</span><span class='attribute-value'>"projectNo"</span><span> </span><span class='attribute'>size</span><span>=</span><span class='attribute-value'>'50'</span><span> </span><span class='attribute'>maxlength</span><span>=</span><span class='attribute-value'>'60'</span><span class='tag'>/></span><span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'></</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>width</span><span>=</span><span class='attribute-value'>'10%'</span><span> nowrap </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"boxHead"</span><span class='tag'>></span><span>项目类别:</span><span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>background</span><span>=</span><span class='attribute-value'>"../images/leftbg2.gif"</span><span class='tag'>></span><span class='tag'><</span><span class='tag-name'>html:text</span><span> </span><span class='attribute'>property</span><span>=</span><span class='attribute-value'>"sort"</span><span> </span><span class='attribute'>size</span><span>=</span><span class='attribute-value'>'50'</span><span> </span><span class='attribute'>maxlength</span><span>=</span><span class='attribute-value'>'60'</span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span>% </span></span></li>
<li class=''><span> String[] <span class='attribute'>allExistSorts</span><span> = </span><span class='attribute-value'>com</span><span>.bupticet.research.web.collection.ProjectCollection.getExistSorts(); </span></span></li>
<li class='alt'><span> if(allExistSorts.length<span class='tag'>></span><span>0){ </span></span></li>
<li class=''><span> pageContext.setAttribute("allExistSorts", allExistSorts); </span></li>
<li class='alt'><span> %<span class='tag'>></span><span> </span></span></li>
<li class=''><span> &nbsp;&lt;==备选项:<span class='tag'><</span><span class='tag-name'>html:select</span><span> </span><span class='attribute'>property</span><span>=</span><span class='attribute-value'>"existSorts"</span><span> </span><span class='attribute'>onchange</span><span>=</span><span class='attribute-value'>"autoPopulate(this,'sort');"</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>html:option</span><span> </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"-1"</span><span class='tag'>></span><span>--- 请选择 ---</span><span class='tag'></</span><span class='tag-name'>html:option</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>html:option</span><span> </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>""</span><span class='tag'>></span><span class='tag'></</span><span class='tag-name'>html:option</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>html:options</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"allExistSorts"</span><span> </span><span class='attribute'>labelName</span><span>=</span><span class='attribute-value'>"allExistSorts"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span><span class='tag'></</span><span class='tag-name'>html:select</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span><span class='tag'><</span><span>%} %</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'></</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span>...... </span></li>
</ol>
</div>
<br/>
<br/>
Action代码:<br/>
<div class='code_title'>java 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-j' start='1'>
<li class='alt'><span><span class='comment'>/**</span> </span></li>
<li class=''><span><span class='comment'> * </span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span><span class='keyword'>package</span><span> com.bupticet.research.web.action; </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span><span class='keyword'>import</span><span> java.util.Enumeration; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> java.util.HashMap; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> java.util.List; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> java.util.Map; </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span><span class='keyword'>import</span><span> javax.servlet.http.HttpServletRequest; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> javax.servlet.http.HttpServletResponse; </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span><span class='keyword'>import</span><span> org.apache.commons.beanutils.BeanUtils; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> org.apache.commons.beanutils.DynaBean; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> org.apache.struts.action.ActionForm; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> org.apache.struts.action.ActionForward; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> org.apache.struts.action.ActionMapping; </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span><span class='keyword'>import</span><span> com.bupticet.base.web.struts.BaseAction; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> com.bupticet.base.web.struts.StrutsUtils; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> com.bupticet.constant.StrutsConstant; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> com.bupticet.helper.GlobalSession; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> com.bupticet.model.ClientInfo; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> com.bupticet.research.entity.Fruit; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> com.bupticet.research.entity.Project; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> com.bupticet.research.service.ProjectManager; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> com.bupticet.util.RequestUtils; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> com.bupticet.util.encode.Decoder; </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span><span class='comment'>/**</span> </span></li>
<li class=''><span><span class='comment'> * @author lijt</span> </span></li>
<li class='alt'><span><span class='comment'> * </span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span><span class='keyword'>public</span><span> </span><span class='keyword'>class</span><span> ProjectAction </span><span class='keyword'>extends</span><span> BaseAction { </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='keyword'>private</span><span> ProjectManager projectManager; </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/**</span> </span></li>
<li class=''><span><span class='comment'> * @param projectManager</span> </span></li>
<li class='alt'><span><span class='comment'> * the projectManager to set</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> </span><span class='keyword'>void</span><span> setProjectManager(ProjectManager projectManager) { </span></span></li>
<li class=''><span> <span class='keyword'>this</span><span>.projectManager = projectManager; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/**</span> </span></li>
<li class=''><span><span class='comment'> * </span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ProjectAction() { </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/*</span> </span></li>
<li class=''><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class='alt'><span><span class='comment'> * </span> </span></li>
<li class=''><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#delete(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class='alt'><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward delete(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> String id = req.getParameter(<span class='string'>"id"</span><span>); </span></span></li>
<li class='alt'><span> checkInputPara(<span class='keyword'>new</span><span> String[] { id }); </span></span></li>
<li class=''><span> projectManager.removeObject( id); </span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.DELETE_SUCCESS); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='comment'>/*</span> </span></li>
<li class='alt'><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class=''><span><span class='comment'> * </span> </span></li>
<li class='alt'><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#edit(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class=''><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> ActionForward edit(ActionMapping mapping, ActionForm form, </span></span></li>
<li class=''><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class='alt'><span> String id = req.getParameter(<span class='string'>"id"</span><span>); </span></span></li>
<li class=''><span> checkInputPara(<span class='keyword'>new</span><span> String[] { id }); </span></span></li>
<li class='alt'><span> Project p = projectManager.getObject( id); </span></li>
<li class=''><span> <span class='keyword'>if</span><span> (p == </span><span class='keyword'>null</span><span>) { </span></span></li>
<li class='alt'><span> <span class='keyword'>this</span><span>.throwEntityMissingException(); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> DynaBean f = (DynaBean) form; </span></li>
<li class=''><span> BeanUtils.copyProperties(f, p); </span></li>
<li class='alt'><span> saveToken(req); </span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.EDIT_SUCCESS); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/*</span> </span></li>
<li class=''><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class='alt'><span><span class='comment'> * </span> </span></li>
<li class=''><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#list(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class='alt'><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward list(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> <span class='keyword'>int</span><span> pageNum = RequestUtils.getIntParameter(req, </span><span class='string'>"pageNum"</span><span>, </span><span class='number'>1</span><span>); </span></span></li>
<li class='alt'><span> <span class='keyword'>boolean</span><span> isAsc = RequestUtils.getBooleanParameter(req, </span><span class='string'>"isAsc"</span><span>, </span><span class='keyword'>false</span><span>); </span></span></li>
<li class=''><span> String orderField = RequestUtils.getStringParameter(req, <span class='string'>"orderField"</span><span>, </span></span></li>
<li class='alt'><span> <span class='string'>"project0.BEGIN_DATE"</span><span>); </span></span></li>
<li class=''><span> req.setAttribute(<span class='string'>"list"</span><span>, projectManager.getObjectsForPage( </span></span></li>
<li class='alt'><span> pageNum, <span class='number'>20</span><span>, orderField, isAsc)); </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.LIST_SUCCESS); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/*</span> </span></li>
<li class=''><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class='alt'><span><span class='comment'> * </span> </span></li>
<li class=''><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#save(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class='alt'><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward save(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> <span class='keyword'>if</span><span> (isCancelled(req)) { </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.SAVE_CANCEL); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> checkAndClearToken(req); </span></li>
<li class=''><span> saveToken(req); </span></li>
<li class='alt'><span> <span class='keyword'>if</span><span> (!</span><span class='keyword'>this</span><span>.validateForm(mapping, form, req)) { </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.SAVE_FAILURE); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> DynaBean f = (DynaBean) form; </span></li>
<li class='alt'><span> <span class='keyword'>if</span><span> (</span><span class='keyword'>null</span><span> != projectManager.checkName((String) f.get(</span><span class='string'>"name"</span><span>))) { </span></span></li>
<li class=''><span> <span class='keyword'>this</span><span>.saveErrors(req, </span></span></li>
<li class='alt'><span> addError(<span class='string'>"projectForm.error.existSameNameProject"</span><span>)); </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.SAVE_FAILURE); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> <span class='keyword'>if</span><span> (</span><span class='keyword'>null</span><span> != projectManager.checkNo((String) f.get(</span><span class='string'>"projectNo"</span><span>))) { </span></span></li>
<li class='alt'><span> <span class='keyword'>this</span><span>.saveErrors(req, </span></span></li>
<li class=''><span> addError(<span class='string'>"projectForm.error.existSameNoProject"</span><span>)); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.SAVE_FAILURE); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> GlobalSession globalSession = (GlobalSession) req.getSession(<span class='keyword'>true</span><span>) </span></span></li>
<li class=''><span> .getAttribute(<span class='string'>"globalSession"</span><span>); </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span> Project project = <span class='keyword'>new</span><span> Project(); </span></span></li>
<li class='alt'><span> BeanUtils.copyProperties(project, f); </span></li>
<li class=''><span> project.setEnterorId(globalSession.getUserID()); </span></li>
<li class='alt'><span> projectManager.saveObject( project); </span></li>
<li class=''><span> <span class='keyword'>return</span><span> StrutsUtils.getExtForward(mapping, StrutsConstant.SAVE_SUCCESS, </span></span></li>
<li class='alt'><span> project.getId()); </span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='comment'>/*</span> </span></li>
<li class='alt'><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class=''><span><span class='comment'> * </span> </span></li>
<li class='alt'><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#update(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class=''><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> ActionForward update(ActionMapping mapping, ActionForm form, </span></span></li>
<li class=''><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class='alt'><span> <span class='keyword'>if</span><span> (isCancelled(req)) { </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.UPDATE_CANCEL); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> checkAndClearToken(req); </span></li>
<li class='alt'><span> saveToken(req); </span></li>
<li class=''><span> <span class='keyword'>if</span><span> (!</span><span class='keyword'>this</span><span>.validateForm(mapping, form, req)) { </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.UPDATE_FAILURE); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> DynaBean f = (DynaBean) form; </span></li>
<li class=''><span> String id = (String) f.get(<span class='string'>"id"</span><span>); </span></span></li>
<li class='alt'><span> String existId = projectManager.checkName((String) f.get(<span class='string'>"name"</span><span>)); </span></span></li>
<li class=''><span> <span class='keyword'>if</span><span> (existId != </span><span class='keyword'>null</span><span> && !id.equals(existId)) { </span></span></li>
<li class='alt'><span> <span class='keyword'>this</span><span>.saveErrors(req, </span></span></li>
<li class=''><span> addError(<span class='string'>"projectForm.error.existSameNameProject"</span><span>)); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.UPDATE_FAILURE); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> existId = projectManager.checkNo((String) f.get(<span class='string'>"projectNo"</span><span>)); </span></span></li>
<li class=''><span> <span class='keyword'>if</span><span> (existId != </span><span class='keyword'>null</span><span> && !id.equals(existId)) { </span></span></li>
<li class='alt'><span> <span class='keyword'>this</span><span>.saveErrors(req, </span></span></li>
<li class=''><span> addError(<span class='string'>"projectForm.error.existSameNoProject"</span><span>)); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.UPDATE_FAILURE); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> Project project = projectManager.getObject( </span></li>
<li class=''><span> (String) f.get(<span class='string'>"id"</span><span>)); </span></span></li>
<li class='alt'><span> BeanUtils.copyProperties(project, f); </span></li>
<li class=''><span> projectManager.saveObject( project); </span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> StrutsUtils.getExtForward(mapping, </span></span></li>
<li class=''><span> StrutsConstant.UPDATE_SUCCESS, project.getId()); </span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/*</span> </span></li>
<li class=''><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class='alt'><span><span class='comment'> * </span> </span></li>
<li class=''><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#view(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class='alt'><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward view(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> String id = req.getParameter(<span class='string'>"id"</span><span>); </span></span></li>
<li class='alt'><span> checkInputPara(<span class='keyword'>new</span><span> String[] { id }); </span></span></li>
<li class=''><span> Project p = projectManager.getObject( id); </span></li>
<li class='alt'><span> <span class='keyword'>if</span><span> (p == </span><span class='keyword'>null</span><span>) { </span></span></li>
<li class=''><span> <span class='keyword'>this</span><span>.throwEntityMissingException(); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> List<Fruit> fruits = projectManager.getFruitsOfProject(p.getId()); </span></li>
<li class='alt'><span> req.setAttribute(<span class='string'>"fruits"</span><span>, fruits); </span></span></li>
<li class=''><span> req.setAttribute(<span class='string'>"info"</span><span>, p); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.VIEW_SUCCESS); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='comment'>/**</span> </span></li>
<li class='alt'><span><span class='comment'> * @param mapping</span> </span></li>
<li class=''><span><span class='comment'> * @param form</span> </span></li>
<li class='alt'><span><span class='comment'> * @param req</span> </span></li>
<li class=''><span><span class='comment'> * @param res</span> </span></li>
<li class='alt'><span><span class='comment'> * @return</span> </span></li>
<li class=''><span><span class='comment'> * @throws Exception</span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward audit(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> req.setAttribute(<span class='string'>"auditFlag"</span><span>, </span><span class='keyword'>new</span><span> Boolean(</span><span class='keyword'>true</span><span>)); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>.edit(mapping, form, req, res); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='comment'>/**</span> </span></li>
<li class='alt'><span><span class='comment'> * @param mapping</span> </span></li>
<li class=''><span><span class='comment'> * @param form</span> </span></li>
<li class='alt'><span><span class='comment'> * @param req</span> </span></li>
<li class=''><span><span class='comment'> * @param res</span> </span></li>
<li class='alt'><span><span class='comment'> * @return</span> </span></li>
<li class=''><span><span class='comment'> * @throws Exception</span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward goSearch(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(</span><span class='string'>"search-page"</span><span>); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/**</span> </span></li>
<li class=''><span><span class='comment'> * @param mapping</span> </span></li>
<li class='alt'><span><span class='comment'> * @param form</span> </span></li>
<li class=''><span><span class='comment'> * @param req</span> </span></li>
<li class='alt'><span><span class='comment'> * @param res</span> </span></li>
<li class=''><span><span class='comment'> * @return</span> </span></li>
<li class='alt'><span><span class='comment'> * @throws Exception</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='annotation'>@SuppressWarnings</span><span>(</span><span class='string'>"unchecked"</span><span>) </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward search(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> Map<String, String> p = <span class='keyword'>new</span><span> HashMap<String, String>(); </span></span></li>
<li class='alt'><span> <span class='keyword'>for</span><span>(Enumeration<String> e = req.getParameterNames();e.hasMoreElements();){ </span></span></li>
<li class=''><span> String key = e.nextElement(); </span></li>
<li class='alt'><span> String value = req.getParameter(key); </span></li>
<li class=''><span> <span class='keyword'>if</span><span> (value != </span><span class='keyword'>null</span><span> && !</span><span class='string'>""</span><span>.equals(value)) { </span></span></li>
<li class='alt'><span> p.put(key, Decoder.customDecode(value)); </span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> <span class='keyword'>int</span><span> pageNum = RequestUtils.getIntParameter(req, </span><span class='string'>"pageNum"</span><span>, </span><span class='number'>1</span><span>); </span></span></li>
<li class='alt'><span> <span class='keyword'>boolean</span><span> isAsc = RequestUtils.getBooleanParameter(req, </span><span class='string'>"isAsc"</span><span>, </span><span class='keyword'>false</span><span>); </span></span></li>
<li class=''><span> String orderField = RequestUtils.getStringParameter(req, <span class='string'>"orderField"</span><span>, </span></span></li>
<li class='alt'><span> <span class='string'>"project0.BEGIN_DATE"</span><span>); </span></span></li>
<li class=''><span> req.setAttribute(<span class='string'>"list"</span><span>, projectManager.search(p, pageNum, </span><span class='number'>20</span><span>, </span></span></li>
<li class='alt'><span> orderField, isAsc)); </span></li>
<li class=''><span> req.setAttribute(<span class='string'>"search"</span><span>, </span><span class='string'>"true"</span><span>); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.LIST_SUCCESS); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span>} </span></li>
</ol>
</div>
struts-config.xml 表单配置:<br/>
<div class='code_title'>xml 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-xml' start='1'>
<li class='alt'><span><span class='tag'><</span><span class='tag-name'>form-bean</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"projectForm"</span><span> </span></span></li>
<li class=''><span> <span class='attribute'>type</span><span>=</span><span class='attribute-value'>"org.apache.struts.validator.LazyValidatorForm"</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span><span class='tag'></</span><span class='tag-name'>form-bean</span><span class='tag'>></span><span> </span></span></li>
</ol>
</div>
<br/>
struts-config.xml action-mapping配置:<br/>
<div class='code_title'>xml 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-xml' start='1'>
<li class='alt'><span><span class='tag'><</span><span class='tag-name'>action</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project"</span><span> </span></span></li>
<li class=''><span> <span class='attribute'>type</span><span>=</span><span class='attribute-value'>"com.bupticet.strutsinterceptor.InterceptorActionProxy"</span><span> </span></span></li>
<li class='alt'><span> <span class='attribute'>name</span><span>=</span><span class='attribute-value'>"projectForm"</span><span> </span><span class='attribute'>parameter</span><span>=</span><span class='attribute-value'>"method"</span><span> </span><span class='attribute'>scope</span><span>=</span><span class='attribute-value'>"request"</span><span> </span></span></li>
<li class=''><span> <span class='attribute'>validate</span><span>=</span><span class='attribute-value'>"false"</span><span> </span><span class='attribute'>cancellable</span><span>=</span><span class='attribute-value'>"true"</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"add-success"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/add_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"save-success"</span><span> </span></span></li>
<li class='alt'><span> <span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project.do?method=view&amp;id="</span><span> </span><span class='attribute'>redirect</span><span>=</span><span class='attribute-value'>"true"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"save-cancel"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project.do"</span><span> </span></span></li>
<li class='alt'><span> <span class='attribute'>redirect</span><span>=</span><span class='attribute-value'>"true"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"save-failure"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/add_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"edit-success"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/edit_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"view-success"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/view_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"list-success"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/list_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"update-failure"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/edit_project.jsp"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"update-cancel"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project.do"</span><span> </span></span></li>
<li class=''><span> <span class='attribute'>redirect</span><span>=</span><span class='attribute-value'>"true"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"update-success"</span><span> </span></span></li>
<li class=''><span> <span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project.do?method=view&amp;id="</span><span> </span><span class='attribute'>redirect</span><span>=</span><span class='attribute-value'>"true"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"delete-success"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/project.do?method=list"</span><span> </span><span class='attribute'>redirect</span><span>=</span><span class='attribute-value'>"true"</span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"search-page"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/search_project.jsp"</span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span><span class='tag'></</span><span class='tag-name'>action</span><span class='tag'>></span><span> </span></span></li>
</ol>
</div>
<br/>
<br/>
页面表单:<br/>
<div class='code_title'>xml 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-xml' start='1'>
<li class='alt'><span><span class='tag'><</span><span class='tag-name'>html:form</span><span> </span><span class='attribute'>action</span><span>=</span><span class='attribute-value'>"/project?method=save"</span><span> </span><span class='attribute'>method</span><span>=</span><span class='attribute-value'>"post"</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>width</span><span>=</span><span class='attribute-value'>'10%'</span><span> nowrap </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"boxHead"</span><span class='tag'>></span><span>项目名称:</span><span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>background</span><span>=</span><span class='attribute-value'>"../images/leftbg2.gif"</span><span class='tag'>></span><span class='tag'><</span><span class='tag-name'>html:text</span><span> </span><span class='attribute'>property</span><span>=</span><span class='attribute-value'>"name"</span><span> </span><span class='attribute'>size</span><span>=</span><span class='attribute-value'>'100'</span><span> </span><span class='attribute'>maxlength</span><span>=</span><span class='attribute-value'>'100'</span><span class='tag'>/></span><span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'></</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>width</span><span>=</span><span class='attribute-value'>'10%'</span><span> nowrap </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"boxHead"</span><span class='tag'>></span><span>项目编号:</span><span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>background</span><span>=</span><span class='attribute-value'>"../images/leftbg2.gif"</span><span class='tag'>></span><span class='tag'><</span><span class='tag-name'>html:text</span><span> </span><span class='attribute'>property</span><span>=</span><span class='attribute-value'>"projectNo"</span><span> </span><span class='attribute'>size</span><span>=</span><span class='attribute-value'>'50'</span><span> </span><span class='attribute'>maxlength</span><span>=</span><span class='attribute-value'>'60'</span><span class='tag'>/></span><span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'></</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>width</span><span>=</span><span class='attribute-value'>'10%'</span><span> nowrap </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"boxHead"</span><span class='tag'>></span><span>项目类别:</span><span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>td</span><span> </span><span class='attribute'>background</span><span>=</span><span class='attribute-value'>"../images/leftbg2.gif"</span><span class='tag'>></span><span class='tag'><</span><span class='tag-name'>html:text</span><span> </span><span class='attribute'>property</span><span>=</span><span class='attribute-value'>"sort"</span><span> </span><span class='attribute'>size</span><span>=</span><span class='attribute-value'>'50'</span><span> </span><span class='attribute'>maxlength</span><span>=</span><span class='attribute-value'>'60'</span><span class='tag'>/></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span>% </span></span></li>
<li class=''><span> String[] <span class='attribute'>allExistSorts</span><span> = </span><span class='attribute-value'>com</span><span>.bupticet.research.web.collection.ProjectCollection.getExistSorts(); </span></span></li>
<li class='alt'><span> if(allExistSorts.length<span class='tag'>></span><span>0){ </span></span></li>
<li class=''><span> pageContext.setAttribute("allExistSorts", allExistSorts); </span></li>
<li class='alt'><span> %<span class='tag'>></span><span> </span></span></li>
<li class=''><span> &nbsp;&lt;==备选项:<span class='tag'><</span><span class='tag-name'>html:select</span><span> </span><span class='attribute'>property</span><span>=</span><span class='attribute-value'>"existSorts"</span><span> </span><span class='attribute'>onchange</span><span>=</span><span class='attribute-value'>"autoPopulate(this,'sort');"</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>html:option</span><span> </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"-1"</span><span class='tag'>></span><span>--- 请选择 ---</span><span class='tag'></</span><span class='tag-name'>html:option</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'><</span><span class='tag-name'>html:option</span><span> </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>""</span><span class='tag'>></span><span class='tag'></</span><span class='tag-name'>html:option</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span> <span class='tag'><</span><span class='tag-name'>html:options</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"allExistSorts"</span><span> </span><span class='attribute'>labelName</span><span>=</span><span class='attribute-value'>"allExistSorts"</span><span> </span><span class='tag'>/></span><span> </span></span></li>
<li class=''><span><span class='tag'></</span><span class='tag-name'>html:select</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span><span class='tag'><</span><span>%} %</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='tag'></</span><span class='tag-name'>td</span><span class='tag'>></span><span> </span></span></li>
<li class=''><span> <span class='tag'></</span><span class='tag-name'>tr</span><span class='tag'>></span><span> </span></span></li>
<li class='alt'><span>...... </span></li>
</ol>
</div>
<br/>
<br/>
Action代码:<br/>
<div class='code_title'>java 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-j' start='1'>
<li class='alt'><span><span class='comment'>/**</span> </span></li>
<li class=''><span><span class='comment'> * </span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span><span class='keyword'>package</span><span> com.bupticet.research.web.action; </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span><span class='keyword'>import</span><span> java.util.Enumeration; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> java.util.HashMap; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> java.util.List; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> java.util.Map; </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span><span class='keyword'>import</span><span> javax.servlet.http.HttpServletRequest; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> javax.servlet.http.HttpServletResponse; </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span><span class='keyword'>import</span><span> org.apache.commons.beanutils.BeanUtils; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> org.apache.commons.beanutils.DynaBean; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> org.apache.struts.action.ActionForm; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> org.apache.struts.action.ActionForward; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> org.apache.struts.action.ActionMapping; </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span><span class='keyword'>import</span><span> com.bupticet.base.web.struts.BaseAction; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> com.bupticet.base.web.struts.StrutsUtils; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> com.bupticet.constant.StrutsConstant; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> com.bupticet.helper.GlobalSession; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> com.bupticet.model.ClientInfo; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> com.bupticet.research.entity.Fruit; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> com.bupticet.research.entity.Project; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> com.bupticet.research.service.ProjectManager; </span></span></li>
<li class=''><span><span class='keyword'>import</span><span> com.bupticet.util.RequestUtils; </span></span></li>
<li class='alt'><span><span class='keyword'>import</span><span> com.bupticet.util.encode.Decoder; </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span><span class='comment'>/**</span> </span></li>
<li class=''><span><span class='comment'> * @author lijt</span> </span></li>
<li class='alt'><span><span class='comment'> * </span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span><span class='keyword'>public</span><span> </span><span class='keyword'>class</span><span> ProjectAction </span><span class='keyword'>extends</span><span> BaseAction { </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='keyword'>private</span><span> ProjectManager projectManager; </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/**</span> </span></li>
<li class=''><span><span class='comment'> * @param projectManager</span> </span></li>
<li class='alt'><span><span class='comment'> * the projectManager to set</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> </span><span class='keyword'>void</span><span> setProjectManager(ProjectManager projectManager) { </span></span></li>
<li class=''><span> <span class='keyword'>this</span><span>.projectManager = projectManager; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/**</span> </span></li>
<li class=''><span><span class='comment'> * </span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ProjectAction() { </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/*</span> </span></li>
<li class=''><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class='alt'><span><span class='comment'> * </span> </span></li>
<li class=''><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#delete(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class='alt'><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward delete(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> String id = req.getParameter(<span class='string'>"id"</span><span>); </span></span></li>
<li class='alt'><span> checkInputPara(<span class='keyword'>new</span><span> String[] { id }); </span></span></li>
<li class=''><span> projectManager.removeObject( id); </span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.DELETE_SUCCESS); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='comment'>/*</span> </span></li>
<li class='alt'><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class=''><span><span class='comment'> * </span> </span></li>
<li class='alt'><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#edit(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class=''><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> ActionForward edit(ActionMapping mapping, ActionForm form, </span></span></li>
<li class=''><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class='alt'><span> String id = req.getParameter(<span class='string'>"id"</span><span>); </span></span></li>
<li class=''><span> checkInputPara(<span class='keyword'>new</span><span> String[] { id }); </span></span></li>
<li class='alt'><span> Project p = projectManager.getObject( id); </span></li>
<li class=''><span> <span class='keyword'>if</span><span> (p == </span><span class='keyword'>null</span><span>) { </span></span></li>
<li class='alt'><span> <span class='keyword'>this</span><span>.throwEntityMissingException(); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> DynaBean f = (DynaBean) form; </span></li>
<li class=''><span> BeanUtils.copyProperties(f, p); </span></li>
<li class='alt'><span> saveToken(req); </span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.EDIT_SUCCESS); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/*</span> </span></li>
<li class=''><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class='alt'><span><span class='comment'> * </span> </span></li>
<li class=''><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#list(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class='alt'><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward list(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> <span class='keyword'>int</span><span> pageNum = RequestUtils.getIntParameter(req, </span><span class='string'>"pageNum"</span><span>, </span><span class='number'>1</span><span>); </span></span></li>
<li class='alt'><span> <span class='keyword'>boolean</span><span> isAsc = RequestUtils.getBooleanParameter(req, </span><span class='string'>"isAsc"</span><span>, </span><span class='keyword'>false</span><span>); </span></span></li>
<li class=''><span> String orderField = RequestUtils.getStringParameter(req, <span class='string'>"orderField"</span><span>, </span></span></li>
<li class='alt'><span> <span class='string'>"project0.BEGIN_DATE"</span><span>); </span></span></li>
<li class=''><span> req.setAttribute(<span class='string'>"list"</span><span>, projectManager.getObjectsForPage( </span></span></li>
<li class='alt'><span> pageNum, <span class='number'>20</span><span>, orderField, isAsc)); </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.LIST_SUCCESS); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/*</span> </span></li>
<li class=''><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class='alt'><span><span class='comment'> * </span> </span></li>
<li class=''><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#save(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class='alt'><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward save(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> <span class='keyword'>if</span><span> (isCancelled(req)) { </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.SAVE_CANCEL); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> checkAndClearToken(req); </span></li>
<li class=''><span> saveToken(req); </span></li>
<li class='alt'><span> <span class='keyword'>if</span><span> (!</span><span class='keyword'>this</span><span>.validateForm(mapping, form, req)) { </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.SAVE_FAILURE); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> DynaBean f = (DynaBean) form; </span></li>
<li class='alt'><span> <span class='keyword'>if</span><span> (</span><span class='keyword'>null</span><span> != projectManager.checkName((String) f.get(</span><span class='string'>"name"</span><span>))) { </span></span></li>
<li class=''><span> <span class='keyword'>this</span><span>.saveErrors(req, </span></span></li>
<li class='alt'><span> addError(<span class='string'>"projectForm.error.existSameNameProject"</span><span>)); </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.SAVE_FAILURE); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> <span class='keyword'>if</span><span> (</span><span class='keyword'>null</span><span> != projectManager.checkNo((String) f.get(</span><span class='string'>"projectNo"</span><span>))) { </span></span></li>
<li class='alt'><span> <span class='keyword'>this</span><span>.saveErrors(req, </span></span></li>
<li class=''><span> addError(<span class='string'>"projectForm.error.existSameNoProject"</span><span>)); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.SAVE_FAILURE); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> GlobalSession globalSession = (GlobalSession) req.getSession(<span class='keyword'>true</span><span>) </span></span></li>
<li class=''><span> .getAttribute(<span class='string'>"globalSession"</span><span>); </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span> Project project = <span class='keyword'>new</span><span> Project(); </span></span></li>
<li class='alt'><span> BeanUtils.copyProperties(project, f); </span></li>
<li class=''><span> project.setEnterorId(globalSession.getUserID()); </span></li>
<li class='alt'><span> projectManager.saveObject( project); </span></li>
<li class=''><span> <span class='keyword'>return</span><span> StrutsUtils.getExtForward(mapping, StrutsConstant.SAVE_SUCCESS, </span></span></li>
<li class='alt'><span> project.getId()); </span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='comment'>/*</span> </span></li>
<li class='alt'><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class=''><span><span class='comment'> * </span> </span></li>
<li class='alt'><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#update(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class=''><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> ActionForward update(ActionMapping mapping, ActionForm form, </span></span></li>
<li class=''><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class='alt'><span> <span class='keyword'>if</span><span> (isCancelled(req)) { </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.UPDATE_CANCEL); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> checkAndClearToken(req); </span></li>
<li class='alt'><span> saveToken(req); </span></li>
<li class=''><span> <span class='keyword'>if</span><span> (!</span><span class='keyword'>this</span><span>.validateForm(mapping, form, req)) { </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.UPDATE_FAILURE); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> DynaBean f = (DynaBean) form; </span></li>
<li class=''><span> String id = (String) f.get(<span class='string'>"id"</span><span>); </span></span></li>
<li class='alt'><span> String existId = projectManager.checkName((String) f.get(<span class='string'>"name"</span><span>)); </span></span></li>
<li class=''><span> <span class='keyword'>if</span><span> (existId != </span><span class='keyword'>null</span><span> && !id.equals(existId)) { </span></span></li>
<li class='alt'><span> <span class='keyword'>this</span><span>.saveErrors(req, </span></span></li>
<li class=''><span> addError(<span class='string'>"projectForm.error.existSameNameProject"</span><span>)); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.UPDATE_FAILURE); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> existId = projectManager.checkNo((String) f.get(<span class='string'>"projectNo"</span><span>)); </span></span></li>
<li class=''><span> <span class='keyword'>if</span><span> (existId != </span><span class='keyword'>null</span><span> && !id.equals(existId)) { </span></span></li>
<li class='alt'><span> <span class='keyword'>this</span><span>.saveErrors(req, </span></span></li>
<li class=''><span> addError(<span class='string'>"projectForm.error.existSameNoProject"</span><span>)); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.UPDATE_FAILURE); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> Project project = projectManager.getObject( </span></li>
<li class=''><span> (String) f.get(<span class='string'>"id"</span><span>)); </span></span></li>
<li class='alt'><span> BeanUtils.copyProperties(project, f); </span></li>
<li class=''><span> projectManager.saveObject( project); </span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> StrutsUtils.getExtForward(mapping, </span></span></li>
<li class=''><span> StrutsConstant.UPDATE_SUCCESS, project.getId()); </span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/*</span> </span></li>
<li class=''><span><span class='comment'> * (non-Javadoc)</span> </span></li>
<li class='alt'><span><span class='comment'> * </span> </span></li>
<li class=''><span><span class='comment'> * @see com.bupticet.base.web.struts.BaseAction#view(org.apache.struts.action.ActionMapping,</span> </span></li>
<li class='alt'><span><span class='comment'> * org.apache.struts.action.ActionForm,</span> </span></li>
<li class=''><span><span class='comment'> * javax.servlet.http.HttpServletRequest,</span> </span></li>
<li class='alt'><span><span class='comment'> * javax.servlet.http.HttpServletResponse)</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward view(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> String id = req.getParameter(<span class='string'>"id"</span><span>); </span></span></li>
<li class='alt'><span> checkInputPara(<span class='keyword'>new</span><span> String[] { id }); </span></span></li>
<li class=''><span> Project p = projectManager.getObject( id); </span></li>
<li class='alt'><span> <span class='keyword'>if</span><span> (p == </span><span class='keyword'>null</span><span>) { </span></span></li>
<li class=''><span> <span class='keyword'>this</span><span>.throwEntityMissingException(); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> List<Fruit> fruits = projectManager.getFruitsOfProject(p.getId()); </span></li>
<li class='alt'><span> req.setAttribute(<span class='string'>"fruits"</span><span>, fruits); </span></span></li>
<li class=''><span> req.setAttribute(<span class='string'>"info"</span><span>, p); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.VIEW_SUCCESS); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='comment'>/**</span> </span></li>
<li class='alt'><span><span class='comment'> * @param mapping</span> </span></li>
<li class=''><span><span class='comment'> * @param form</span> </span></li>
<li class='alt'><span><span class='comment'> * @param req</span> </span></li>
<li class=''><span><span class='comment'> * @param res</span> </span></li>
<li class='alt'><span><span class='comment'> * @return</span> </span></li>
<li class=''><span><span class='comment'> * @throws Exception</span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward audit(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> req.setAttribute(<span class='string'>"auditFlag"</span><span>, </span><span class='keyword'>new</span><span> Boolean(</span><span class='keyword'>true</span><span>)); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>.edit(mapping, form, req, res); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='comment'>/**</span> </span></li>
<li class='alt'><span><span class='comment'> * @param mapping</span> </span></li>
<li class=''><span><span class='comment'> * @param form</span> </span></li>
<li class='alt'><span><span class='comment'> * @param req</span> </span></li>
<li class=''><span><span class='comment'> * @param res</span> </span></li>
<li class='alt'><span><span class='comment'> * @return</span> </span></li>
<li class=''><span><span class='comment'> * @throws Exception</span> </span></li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward goSearch(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> mapping.findForward(</span><span class='string'>"search-page"</span><span>); </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='comment'>/**</span> </span></li>
<li class=''><span><span class='comment'> * @param mapping</span> </span></li>
<li class='alt'><span><span class='comment'> * @param form</span> </span></li>
<li class=''><span><span class='comment'> * @param req</span> </span></li>
<li class='alt'><span><span class='comment'> * @param res</span> </span></li>
<li class=''><span><span class='comment'> * @return</span> </span></li>
<li class='alt'><span><span class='comment'> * @throws Exception</span> </span></li>
<li class=''><span><span class='comment'> */</span><span> </span></span></li>
<li class='alt'><span> <span class='annotation'>@SuppressWarnings</span><span>(</span><span class='string'>"unchecked"</span><span>) </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> ActionForward search(ActionMapping mapping, ActionForm form, </span></span></li>
<li class='alt'><span> HttpServletRequest req, HttpServletResponse res) <span class='keyword'>throws</span><span> Exception { </span></span></li>
<li class=''><span> Map<String, String> p = <span class='keyword'>new</span><span> HashMap<String, String>(); </span></span></li>
<li class='alt'><span> <span class='keyword'>for</span><span>(Enumeration<String> e = req.getParameterNames();e.hasMoreElements();){ </span></span></li>
<li class=''><span> String key = e.nextElement(); </span></li>
<li class='alt'><span> String value = req.getParameter(key); </span></li>
<li class=''><span> <span class='keyword'>if</span><span> (value != </span><span class='keyword'>null</span><span> && !</span><span class='string'>""</span><span>.equals(value)) { </span></span></li>
<li class='alt'><span> p.put(key, Decoder.customDecode(value)); </span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> <span class='keyword'>int</span><span> pageNum = RequestUtils.getIntParameter(req, </span><span class='string'>"pageNum"</span><span>, </span><span class='number'>1</span><span>); </span></span></li>
<li class='alt'><span> <span class='keyword'>boolean</span><span> isAsc = RequestUtils.getBooleanParameter(req, </span><span class='string'>"isAsc"</span><span>, </span><span class='keyword'>false</span><span>); </span></span></li>
<li class=''><span> String orderField = RequestUtils.getStringParameter(req, <span class='string'>"orderField"</span><span>, </span></span></li>
<li class='alt'><span> <span class='string'>"project0.BEGIN_DATE"</span><span>); </span></span></li>
<li class=''><span> req.setAttribute(<span class='string'>"list"</span><span>, projectManager.search(p, pageNum, </span><span class='number'>20</span><span>, </span></span></li>
<li class='alt'><span> orderField, isAsc)); </span></li>
<li class=''><span> req.setAttribute(<span class='string'>"search"</span><span>, </span><span class='string'>"true"</span><span>); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> mapping.findForward(StrutsConstant.LIST_SUCCESS); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span>} </span></li>
</ol>
</div>
6 楼
linqing
2007-06-26
<!-- Services --> <bean id="documentManager" class="edirectory.service.impl.JpaDocumentManager" scope="singleton" autowire="byName" /> <!-- Converters --> <bean id="edirectory.web.converter.DocumentConverter" class="edirectory.web.converter.DocumentConverter" scope="singleton" autowire="byName" />
5 楼
linqing
2007-06-26
/* * DocumentConventor.java * * Created on 2007?1?3?, ??11:15 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package edirectory.web.converter; import com.opensymphony.webwork.util.WebWorkTypeConverter; import edirectory.persistence.Document; import edirectory.service.DocumentManager; import java.util.Map; import org.springframework.web.context.WebApplicationContext; /** * * @author linqing */ public class DocumentConverter extends WebWorkTypeConverter { private DocumentManager documentManager; public String convertToString(Map context, Object o) { return ((Document)o).getId().toString(); } public Object convertFromString(Map context, String[] values, Class toClass) { if(values[0].equals("") ) { return null; } Long id = Long.parseLong(values[0]); return documentManager.find(toClass, id); } public DocumentManager getDocumentManager() { return documentManager; } public void setDocumentManager(DocumentManager documentManager) { this.documentManager = documentManager; } }
4 楼
linqing
2007-06-26
如果是Webwork2和Spring结合的话,可以把Converter直接配置到spring里面,转换的时候Webwork会取到这个Bean,名字为“com.abest.common.EntityWebworkConverter”
3 楼
lllyq
2007-06-14
这个一般我是用ModelDriven(在params之前)了,getModel中去判断有id则取,否则新建实例,用ModelDriven好在validation/i18n都一并绑定了,
多个对象的情况是通过一个ModelSetable对象对多个对象的引用来实现的,也是在getModel中拿,通过action上的范型声明是否为ModelSetable判断,参数传递跟你的类似,不过是keys数组与modelSet.models数组的参数传递,如keys[0]=1,modelSet.models[0].name=1,
keys[1]=2,modelSet.models[1].name=2
多个对象的情况是通过一个ModelSetable对象对多个对象的引用来实现的,也是在getModel中拿,通过action上的范型声明是否为ModelSetable判断,参数传递跟你的类似,不过是keys数组与modelSet.models数组的参数传递,如keys[0]=1,modelSet.models[0].name=1,
keys[1]=2,modelSet.models[1].name=2
2 楼
winneryong
2007-06-12
能不能把你的代码贴全啊.包括配置文件,以及那些用ServletContextListener注入的代码
1 楼
downpour
2007-06-12
好方法!提供了我另外一个思路。
我以前一直是用拦截器+特殊命名规范来做的。比如,我规定,需要绑定持久化对象的命名必须以#结尾:foo.bar#=1。由于默认的params拦截器会把带有#符号的命名过滤掉,所以这些命名正好可以进入我自己的拦截器,截断以后拼上id,再load出来。
如果用Spring的话,我直接使用WebApplicationContextUtils中的静态方法来getBean获取Service,ServletContext则直接ServletActionContext.getServletContext()得到。其实你这里如果用Spring,也可以采取这种方式,应该不需要那个static的delegate了。
我以前一直是用拦截器+特殊命名规范来做的。比如,我规定,需要绑定持久化对象的命名必须以#结尾:foo.bar#=1。由于默认的params拦截器会把带有#符号的命名过滤掉,所以这些命名正好可以进入我自己的拦截器,截断以后拼上id,再load出来。
如果用Spring的话,我直接使用WebApplicationContextUtils中的静态方法来getBean获取Service,ServletContext则直接ServletActionContext.getServletContext()得到。其实你这里如果用Spring,也可以采取这种方式,应该不需要那个static的delegate了。
相关推荐
WebWork的优势在于其强大的类型安全参数绑定、动作结果的灵活性以及对AJAX支持的良好集成。在本项目中,WebWork将处理HTTP请求,管理应用程序流程,以及协调各组件之间的交互。 Hibernate则是一个对象关系映射(ORM...
WebWork与Hibernate的结合可以提供一个完整的MVC+ORM解决方案,让开发者更专注于业务逻辑,而不是底层的数据库交互。 在提供的文件列表中,"lib"可能是一个包含其他依赖库的文件夹,这些库可能包括Spring、...
WebWork的核心特性包括强大的数据绑定、类型安全的参数映射、异常处理和国际化支持。 Spring 是一个全面的Java企业级应用开发框架,它通过提供IoC容器和AOP功能,简化了对象的创建和依赖管理。Spring还提供了对...
8. **测试与调试**:提供关于单元测试、集成测试和调试WebWork2应用的方法,可能包括JUnit和Mockito的使用。 9. **最佳实践与性能优化**:分享一些开发WebWork2应用的最佳实践,以及如何优化应用程序性能,如减少...
3. **强大的表单绑定和类型转换**:WebWork支持字段级别的表单绑定和自动类型转换,简化了表单处理。 4. **轻量级**:WebWork的设计目标是轻量级和高效,相比于其他大型框架,它更专注于核心功能。 这两个框架虽然...
2. **强大的绑定机制**:WebWork提供了强大的数据绑定机制,可以方便地将表单字段与Action的属性进行映射,极大地简化了开发过程。 3. **强大的异常处理**:WebWork的异常处理机制允许开发者定义不同的错误页面,...
WebWork是一个轻量级的MVC(Model-View-Controller)框架,它简化了Web应用的开发,提供了强大的动作调度和数据绑定功能。Spring框架则是一个全面的企业级应用框架,它包括IOC(Inversion of Control)容器、AOP...
可能涵盖WebWork2的新版特性,如增强的类型安全参数绑定、改进的拦截器机制、新的表达式语言支持等。 5. **webworkDemo.rar**: 这是一个WebWork的示例项目,可能包含了一个简单的WebWork应用,供学习者理解和实践...
开发者只需定义实体类,配置映射文件,即可实现对象与数据库表的自动绑定。 Myeclipse是集成开发环境(IDE),在本项目中,它提供了便捷的开发、调试和部署环境,支持对WebWork和Hibernate的集成,简化了项目的构建...
WebWork的核心特性包括强大的动作映射、类型安全的参数绑定、异常处理和国际化支持。在WebWork中,一个Action类代表一个业务操作,而Struts 2后来吸收了WebWork的部分设计,形成了现在的Struts 2框架。 **Hibernate...
**WebWork** 是一个基于Action的MVC框架,它的主要特点是动作驱动和强大的表单域绑定。WebWork的核心是Action,它负责接收HTTP请求,处理业务逻辑,并将结果传递给视图层。通过使用Interceptor(拦截器)机制,...
WebWork的主要优势在于其强大的动作调度机制和类型安全的参数绑定,以及对AOP(面向切面编程)的支持,能够帮助开发者编写更简洁、可维护的代码。 **Hibernate** 是一款持久化框架,它简化了Java对象与关系数据库...
当WebWork、Spring和Hibernate结合在一起时,可以构建出高效、灵活的企业级应用。Spring作为整体的协调者,可以集成WebWork的动作映射和控制器功能,同时利用Hibernate的ORM能力进行数据操作。例如,Spring MVC可以...
WebWork提供了强大的数据绑定、类型转换和异常处理机制,使得开发者能够更专注于业务逻辑的实现。 Spring 是一个全面的企业级应用框架,它不仅支持IoC和AOP,还包含了数据访问、事务管理、远程服务、邮件服务等多种...
WebWork的强项在于其强大的类型安全的参数绑定,异常处理,以及对AJAX的支持。在`Webwork2 Guide.pdf`中,你可以了解到WebWork的配置、Action的创建、请求处理以及与视图的交互等核心概念。 **Spring** 框架则是一...
WebWork2不强制特定的数据持久化策略,可以与其他ORM框架如Hibernate、iBatis等配合使用。 **视图(Views)** 视图层通常由JSP、FreeMarker、Velocity等模板技术实现。WebWork2提供了模型数据到视图的绑定,使得...
它的主要特点是强大的动作调度、类型安全的参数绑定以及强大的拦截器机制,这些特性使得WebWork在处理用户请求时能够更加高效和安全。在本讲中,我们将学习如何创建WebWork动作类,以及如何配置Action和结果映射,...
还有Spring MVC作为Web层的解决方案,与WebWork结合使用时,可以实现更灵活的请求处理。此外,Spring还提供了对其他框架(如Hibernate)的集成支持。 3. Hibernate框架: Hibernate是一个流行的ORM工具,它将Java...
通过研究这些源码,你可以深入了解如何将WebWork的动作映射与Spring的依赖注入结合,以及如何利用Hibernate进行数据操作。 【学习价值】这个组合的学习对于Java开发者来说非常有价值,因为它涵盖了企业级应用开发的...
WebWork的核心特性包括强大的Action拦截器、类型安全的参数绑定、异常处理和强大的国际化支持。在本教程中,第五讲可能涵盖了如何创建WebWork Action、定义业务逻辑以及如何与视图层交互等内容。 其次,Spring框架...