合并不了,最简单的就是在actionForm中声明一个实体bean的变量,顺便要进行初始化
public class XxxForm{
private User user;
{
user = new User();
}
......
}
public class XxxForm{
private User user;
{
user = new User();
}
......
}
解决方案 »
- 如何让一个功能在 5 秒内完成,否则就自动停止?
- 在事务中删除表能回滚吗?
- enterprise application工程部署报错,Failed to locate remote EJB
- Ibatis往Oracle中插入字符串的时候提示插入的值对于列过大
- 一个bmp的问题,一个cmp的问题
- 求代码,不够还加100哦!
- request如何set parameter的值?
- VO,PO,DTO Struts+Hibernate开发在各层中应该使用哪些数据传递对象??
- 【j2nix】连接池经典文章和代码共享
- jsp下<s:property>里两数值相乘多出来一个尾巴000000000005
- linux/unix下tomcat的控制台信息如何查看
- struts做上传,一直没搞定,头大得很现在
在XML里再配置一下..不过这样不好吧.结合的就紧密了
赞成,actionForm一直以来就是争论的焦点,也是struts1的诟病,还是用struts2吧,架构在webwork上,很好的解决了formbean 和实体bean的关系。
我做过不过也许不太好import java.lang.reflect.Method;
import java.util.Hashtable;
import java.util.Iterator;import org.apache.struts.action.ActionForm;/**
* @author Flying11 E-mail:[email protected]
* Apr 14, 2008 10:51:52 PM
*/public class BeanToForm<T extends Object, F extends ActionForm> implements Cloneable{
/**
* the method base on the fact that the bean's all methods is strictly observe java beans agreement
* @param f the source bean
* @param t the objective bean
* @return if they are successfully transformed,return true;else false
*/
private static boolean transform(Object f, Object t) {
try {
// put f to hashtable
Method[] temp = Class.forName(f.getClass().getName()).getMethods();
Hashtable<String, Method> from = new Hashtable<String, Method>(); for (int len = 0; len < temp.length; len++) {
if (temp[len].getName().startsWith("get")
&& temp[len].getParameterTypes().length == 0) {
from.put(temp[len].getName().substring(1), temp[len]);
}
}
// put t to hashtable
temp = Class.forName(t.getClass().getName()).getMethods();
Hashtable<String, Method> to = new Hashtable<String, Method>();
for (int len = 0; len < temp.length; len++) {
if (temp[len].getName().startsWith("set")
&& temp[len].getParameterTypes().length == 1) {
to.put(temp[len].getName().substring(1), temp[len]);
}
}
Iterator<String> it = from.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
if (to.containsKey(key)
&& to.get(key).getParameterTypes()[0].equals(from.get(
key).getReturnType())) {
to.get(key).invoke(t, from.get(key).invoke(f));
}
}
return true;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* the method base on the fact that the bean's all methods is strictly observe sun javabean agreement
* @param <AF> extends org.apache.struts.action.ActionForm
* @param <O> extends java.lang.Object
* @param bean bean to transform
* @param form transformed bean
* @return if they are successfully transformed,return true;else false
*/
public static <AF extends ActionForm, O extends Object> boolean Bean2Form(
O bean, AF form) {
return transform(bean, form);
}
/**
* the method base on the fact that the bean's all methods is strictly observe sun javabean agreement
* @param <AF> extends org.apache.struts.action.ActionForm
* @param <O> extends java.lang.Object
* @param form transformed bean
* @param bean bean to transform
* @return if they are successfully transformed,return true;else false
*/
public static <AF extends ActionForm, O extends Object> boolean Form2Bean(
AF form, O bean) {
return transform(form, bean);
}
}
private User user = new User();
//setter
//getter
}
Jsp<html:text size="10" property="user.name"></html:text>
你看看下面的介绍
http://blog.csdn.net/guoquanyou/archive/2008/09/02/2866201.aspx
http://blog.csdn.net/guoquanyou/archive/2008/09/06/2891477.aspx
actionForm可以是动态的也可以是静态的,如果是静态的那么你别忘了从这个bean中取出
表单值后还要放到Hibernate生成的bean中