代码之家  ›  专栏  ›  技术社区  ›  Jan

推荐的JSF2.0 CRUD框架[关闭]

  •  30
  • Jan  · 技术社区  · 15 年前

    有人能推荐一些框架来促进jsf2.0中的CRUD开发吗?

    我最看重的方面:

    • 尽可能轻; 对第三方库的依赖性
    • 域模型
    • 对重复编码的需求有限;支持脚手架和/或元注释

    你的,

    6 回复  |  直到 14 年前
        1
  •  47
  •   BalusC    12 年前

    使用jsf2.0提供的标准工具,CRUD确实是小菜一碟:a @ViewScoped <h:dataTable> 基本上已经足够了。下面是一个代码示例,它是从 this article .

    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>
    

    some useful wizards 基于数据模型生成CRUD应用程序。

        2
  •  7
  •   Bozho    15 年前

    • 1个托管bean(用 @ManagedBean )
    • 2个xhtml页面(facelet)-一个用于列表,一个用于编辑/创建
    • <h:dataTable> 带着一个 edit link/button,通过它可以设置托管bean中的当前行对象(使用 action="#{bean.edit(currentRowObject)}" ). (在jsf1.2中,这是通过 <f:setPropertyActionListener> )
    • 行动方法( void ,没有参数)来处理操作
    • @PostConstruct 最初加载数据。
        3
  •  5
  •   Enrique San Martín    9 年前

    我创建这个是为了加快jsf crud应用程序的创建过程: https://github.com/ignl/happyfacescrud 开箱即用的搜索,惰性数据表,查看/编辑,自定义组件,大大减少了代码,当然也很灵活。

        4
  •  2
  •   Jan    14 年前
        5
  •  2
  •   Jav_Rock Rahul N    12 年前

    我也遇到了同样的问题:在JEE6中创建尽可能快的CRUD应用程序。

    美丽的发电机发现于: http://sourceforge.net/projects/jbizmo/

    定义后(曲线图编辑器!)你的业务模型/领域模型,JBizMo创建数据库和一个现成的CRUD应用程序。

    • 生成视图和菜单
    • ... 一堆要定义的参数。。。
        6
  •  1
  •   Sam    11 年前