在JBoss Seam中使用GWT

这几天在JBoss Seam集成GWT,试了很多时间,总结出一些问题:

JBoss Seam版本:2.1.0.SP1

Google Web Toolkit版本:1.5.3

  1. gwt-servlet.jar版本问题:Seam中自带的gwt-servlet.jar版本可能和你使用的GWT版本不一致,如果你编译GWT程序的版本与Seam中gwt-servlet.jar版本不一致,可能会出现一些奇怪的问题,最好的办法是将Seam中的gwt-servlet.jar换成GWT中带的jar。
  2. Seam Resource Servlet的配置和GWT程序中Service Entry Point的设置:Seam中的默认url pattern是/seam/resource/*,所以Seam会把对/seam/resource/gwt/*的请求发送给org.jboss.seam.remoting.gwt.GWT14Service处理,GWTService才会根据GWT客户端发送的请求类和方法来进行调用。需要注意的是,根据跟踪Seam的GWTService发现,客户端发送的请求类似于“5|0|6|http://127.0.0.1:8080/SeamGWT/|5BA8A5B3E35F40698BB0BF65F390BCF2|com.tiandinet.gwt.hello.client.HelloService|sayHello|java.lang.String|your name|1|2|3|4|1|5|6|”,而Seam的GWTService.getResource会根据com.tiandinet.gwt.hello.client.HelloService名称查找Seam组件,此组件即为GWT中的远程服务接口的Seam实现,所以在设置此实现类的@Name属性时,需要将其设置为GWT中远程服务接口的类名。
    所以,对于Service Entry Point的设置,只要URL能匹配到/seam/resource/gwt/即可,而Seam Reference示例中的String endpointURL = GWT.getModuleBaseURL() + “seam/resource/gwt”;可能不一定正确,因为根据GWT编译后页面路径在Seam应用中所处的位置不同,GWT.getModuleBaseURL()返回的路径可能就不能匹配到/seam/resource/gwt。
  3. Seam Resource Servlet映射
    /web=org.jboss.seam.ui.resource.WebResource
    /captcha=org.jboss.seam.captcha.CaptchaImage
    /remoting=org.jboss.seam.remoting.Remoting
    /gwt=org.jboss.seam.remoting.gwt.GWT14Service
    /graphicImage=org.jboss.seam.ui.graphicImage.GraphicImageResource

JSF Converter in JBoss Seam

折腾了两天,终于在JBoss Seam中搞定了JSF Converter。

在这个程序中,产品(Product)和分类(Category)是多对多的关系,关系维护方为产品,在创建产品时,允许选择多个分类,因为Product.categories是一个List属性,同时产品选择<select />标签也是由从Action中查询出来的所有Category的List,所以在页面上,需要在页面渲染、用户提交后的category进行转换。

显示时,我们以Category.id为<option />的value值,而Category.title为label。

Entity如下(省略setter和getter):

Category.java

@Entity
@Table(name = "category")
public class Category extends BaseEntity {
 
	@Id
	@GeneratedValue
	@Column(name = "id", unique = true, nullable = false, length = 10)
	private Integer id;
 
	@Column(name = "title")
	@NotNull
	@Length(min = 4, max = 64, message = "{invalid.length}")
	private String title;
 
	@ManyToMany(mappedBy = "categories")
	private List<product> products = new ArrayList</product><product>();
}
</product>

继续阅读“JSF Converter in JBoss Seam”