论坛首页 Java企业应用论坛

xyz,pojo的mvc框架,替代webwork一Action多CURD操作干净实现

浏览 27472 次
该帖已经被评为良好帖
作者 正文
   发表时间:2006-11-09  
downpour 写道
忘了提一句,ModelDriven的问题已经被讨论了好多回了,不晓得你如此喜欢ModelDriven,哪能白相嵌套对象的赋值?OGNL在哪里用到?

用到ognl的地方在
这几个类到http://sourceforge.net/projects/jxyz上拿吧,都帖到这里,网页都打不开了,sorry
0 请登录后投票
   发表时间:2006-11-09  
MultiParaLogic!showTest.ok.jsp的page source是:
<form action="MultiParaLogic!showTest.xyz">
     Type your first test parameter:<input name="test"/><br>
     Type your second test parameter:<input name="test"/>
     <input type=submit />
</form>
<br>

<%
     String[] test=(String[])request.getAttribute("test");
     for(int i=0,len=test.length;i<len;i++){
%>
     You type test:<font color=red><%=test[i]%></font><br>
<%}%>


调用:/sample/logic/MultiParaLogic!showTest.xyz
0 请登录后投票
   发表时间:2006-11-09  
讲到ModelDriven,我的理解和xwok的定义不太一样,我认为对于一个复杂对象a,他有两个以上属性c,d
我们用url这样?c=xxx&d=xxx而不是?a.c=xxx&a.d=xxx,在form中的写法就免了:
这样,webwork确实最多支持一个Model,而xyz可以支持多个,不过我这个例子,也只是一个
/**
*this is a logic to read a domain:user's parameter from request
*and then fill user attribute then put user into request attribute
*/
package sample.logic;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import sample.domain.User;

import xyz.frame.annotations.Out;
import xyz.frame.annotations.Read;

public class ModelLogic {
	private static final Log LOG = LogFactory.getLog(ModelLogic.class);

	@Read
	@Out
	private User user;
	
	public void showUser(){
		LOG.debug("user is:"+user);
	}
}
0 请登录后投票
   发表时间:2006-11-09  
/sample/logic/ModelLogic!showUser.ok.jsp的页面source
<form action="ModelLogic!showUser.xyz">
     Type your user name:<input name="name"/><br>
     Type your user passwd:<input type=password name="passwd"/>
     <input type=submit />
</form>
<br>

<%
    sample.domain.User user=(sample.domain.User)request.getAttribute("user");
%>
User name:<%=user.getName()%><br>
User passwd:<%=user.getPasswd()%>


调用:/sample/logic/ModelLogic!showUser.xyz
0 请登录后投票
   发表时间:2006-11-09  
对不起,不是说你的框架不好,而是偶这个人比较偏执。如果一个方法超过了100行,或者一个方法里面出现一排if,else,一般都将这种代码称为垃圾。

可能你写的比较符合你的开发思路,不过偶还是比较喜欢setter,getter方法。喜欢通过实现接口来完成偶要的功能,你这个东西只能等偶空下来慢慢再研究其中的精华之处了。
0 请登录后投票
   发表时间:2006-11-10  
downpour说:
对不起,不是说你的框架不好,而是偶这个人比较偏执。如果一个方法超过了100行,或者一个方法里面出现一排if,else,一般都将这种代码称为垃圾。
quote]
看到这些,我只能说你没有读过xwork的源码,我的这几个类都是在com.opensymphony.xwork.util里面几个ognl的处理类的基础上改的,同时,是由于不满xwork的做法才改写的,而且,我这几个类都比较小,除了 DefaultLogicInvocation以外,可惜的是,我的 DefaultLogicInvocation是在xwork的 DefaultActionInvocation的基础上改写的,同时,不满xwork文件过大,不好改写其实现,已经使用hiveMind作为ioc容器对他改写了,当然,由于第一版是直接将xwork的Action改成Logic的,然后根据tapestry的思路改写,所以改写的还不十分完全,但是下一个版本肯定会将 DefaultLogicInvocation的更多实现使用hivemind注入的。这样, DefaultLogicInvocation本身就会更小,所以,如果我的 DefaultLogicInvocation是垃圾,那么xwork的 DefaultActionInvocation岂不是垃圾的平方。还有,对于那些if,不妨看看hibernate的源码,他的session的实现,那里就大量的用到了if else对类型进行判断,不知有没有人说hibernate是垃圾。
更何况,一个mvc框架做的好坏的关键不是他自己的设计思路好坏,而是他好不好用,方不方便开发,如果讲究思路,xwork和tapestry相比,无疑差一个档次,可是tapestry不好使用,我就认为他做的不好,对于你一定想使用set/get而不使用注解简化操作,这种抱残守缺的做法,我也不好多说:
但是:我如果这样
public void showUser(@Read @Out(key="user")User user){...}
public void updateUser(@Read @Out(key="user")User user){...}

这样一个类中两个方法,你用set/get是做不来的,即使做了,也会混乱不清的,
private User user;
     public void setUser(...
     public User getUser(...
public void showUser(User user){...}
private User user;
     public void setUser(...
     public User getUser(...
public void updateUser(User user){...}

如果不改名,你根本没法分清那个user是那个方法的,即使改名,也是混淆不清,我的框架最大的好处不是改set为@Read,get为@Out,而是提供方法参数读写来分清不同操作,这是我自己推荐的做法,至于以field传参,那是一个糟糕的做法,struts,xwork,tapestry都是这样做的,所以,我才做了xyz
0 请登录后投票
   发表时间:2006-11-10  
在刚刚的讨论中已经提到了使用方法参数传递上下文参数在xyz中的重要性,这里不重复,给出一个例子:
/**
 * a simple logic,like the first logic,but use method parameter to replace the logic field 
 * then can include multi method in a logic
 */
package sample.logic;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import xyz.frame.annotations.Out;
import xyz.frame.annotations.Read;

public class ParaMethodLogic {
	private static final Log LOG = LogFactory.getLog(ParaMethodLogic.class);
	
	public void showTest(@Read(key = "test") @Out(key = "test")String test){
		LOG.debug("test:"+test);
	}

}
0 请登录后投票
   发表时间:2006-11-10  
/sample/logic/ParaMethodLogic!showTest.ok.jsp 的jsp源码:
<form action="ParaMethodLogic!showTest.xyz">
     Type your method parameter:<input name="test"/>
     <input type=submit />
</form>
<br>

method Parameter test=<font color=red><%=request.getAttribute("test")%></font>


调用:/sample/logic/ParaMethodLogic!showTest.xyz?test=test
0 请登录后投票
   发表时间:2006-11-10  
前几个Logic的方法都是返回void,对应的jsp页面是XXXLogic!xxxMethod.ok.jsp,如果想将ok换成别的,或者一个Logic对应多个页面,怎么办,这么办
/**
 * the other logic return void,then the result jsp is XXXLogic!xxxMethod.ok.jsp
 * but this logic's showTest method return "success",then the result jsp is
 * NoOkResultLogic!shTest.success.jsp
 */
package sample.logic;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class NoOkResultLogic {
	private static final Log LOG = LogFactory.getLog(NoOkResultLogic.class);
	
	public String showTest(){
		return "success";
	}

}

对应的/sample/logic/NoOkResultLogic!showTest.success.jsp
result not ok but success!
0 请登录后投票
   发表时间:2006-11-10  
前面所举的例子要么返回void,要么返回string确定result的名字,但是,许多的业务逻辑方法是返回其他类型的,我们想把方法的返回值输出到上下文中,能够吗?可以的!
/**
 * the other logic method either return void or return string to define result
 * but I want the method return List and put the list into request attribute,
 * Yes,I can
 */
package sample.logic;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import xyz.frame.annotations.Out;

public class ReturnLogic {
	private static final Log LOG = LogFactory.getLog(ReturnLogic.class);
	
	@Out(key="showList")
	public List showList(){
		List list=new ArrayList();
		LOG.debug("begin fill list");
		list.add("first object");
		list.add("second object");
		list.add("third object");
		LOG.debug("end fill list");
		return list;
	}
}

他的jsp页面/sample/logic/ReturnLogic!showList.ok.jsp
The List is:<br>
<%
    java.util.List showList=(java.util.List)request.getAttribute("showList");
    for(int i=0,len=showList.size();i<len;i++){
%>
      showList[<%=i%>]=<%=showList.get(i)%><br>
<%}%>
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics