推荐的JSF 2.0 CRUD框架 [英] Recommended JSF 2.0 CRUD frameworks
本文介绍了推荐的JSF 2.0 CRUD框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以推荐任何框架来促进JSF 2.0中的CRUD开发吗?
Can somebody recommend any framework to facilitate CRUD development in JSF 2.0?
方面我最重视:
- 尽可能轻量级; 有限的对第三方库的依赖
- 支持不断发展的域模型
- 有限的需求用于重复编码;支持脚手架和/或元注释
- As lightweight as possible; limited dependencies on third party libraries
- Support for an evolving domain model
- Limited need for repetitive coding; support for scaffolding and/or metaannotations
任何提示都非常感谢!
你的,
J。
Any hints highly appreciated! Yours, J.
推荐答案
使用JSF 2.0提供的标准设施CRUD确实是小菜一碟: @ViewScoped
bean与 < h:dataTable>
基本上已经足够了。这是一个代码示例,可以从这篇文章中无耻地复制。
CRUD is indeed a piece of cake using JSF 2.0 provided standard facility: a @ViewScoped
bean in combination with a <h:dataTable>
basically already suffices. Here's a code example which is shamelessly copied from this article.
Bean:
package com.example;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class Bean implements Serializable {
private List<Item> list;
private Item item = new Item();
private boolean edit;
@PostConstruct
public void init() {
// list = dao.list();
// Actually, you should retrieve the list from DAO. This is just for demo.
list = new ArrayList<Item>();
list.add(new Item(1L, "item1"));
list.add(new Item(2L, "item2"));
list.add(new Item(3L, "item3"));
}
public void add() {
// dao.create(item);
// Actually, the DAO should already have set the ID from DB. This is just for demo.
item.setId(list.isEmpty() ? 1 : list.get(list.size() - 1).getId() + 1);
list.add(item);
item = new Item(); // Reset placeholder.
}
public void edit(Item item) {
this.item = item;
edit = true;
}
public void save() {
// dao.update(item);
item = new Item(); // Reset placeholder.
edit = false;
}
public void delete(Item item) {
// dao.delete(item);
list.remove(item);
}
public List<Item> getList() {
return list;
}
public Item getItem() {
return item;
}
public boolean isEdit() {
return edit;
}
// Other getters/setters are actually unnecessary. Feel free to add them though.
}
页面:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Really simple CRUD</title>
</h:head>
<h:body>
<h3>List items</h3>
<h:form rendered="#{not empty bean.list}">
<h:dataTable value="#{bean.list}" var="item">
<h:column><f:facet name="header">ID</f:facet>#{item.id}</h:column>
<h:column><f:facet name="header">Value</f:facet>#{item.value}</h:column>
<h:column><h:commandButton value="edit" action="#{bean.edit(item)}" /></h:column>
<h:column><h:commandButton value="delete" action="#{bean.delete(item)}" /></h:column>
</h:dataTable>
</h:form>
<h:panelGroup rendered="#{empty bean.list}">
<p>Table is empty! Please add new items.</p>
</h:panelGroup>
<h:panelGroup rendered="#{!bean.edit}">
<h3>Add item</h3>
<h:form>
<p>Value: <h:inputText value="#{bean.item.value}" /></p>
<p><h:commandButton value="add" action="#{bean.add}" /></p>
</h:form>
</h:panelGroup>
<h:panelGroup rendered="#{bean.edit}">
<h3>Edit item #{bean.item.id}</h3>
<h:form>
<p>Value: <h:inputText value="#{bean.item.value}" /></p>
<p><h:commandButton value="save" action="#{bean.save}" /></p>
</h:form>
</h:panelGroup>
</h:body>
</html>
此外,Netbeans 一些有用的向导基于数据模型创建CRUD应用程序。
Further, Netbeans has some useful wizards to genreate a CRUD application based on a datamodel.
这篇关于推荐的JSF 2.0 CRUD框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文