Java 推荐的 JSF 2.0 CRUD 框架

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3180400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 17:10:37  来源:igfitidea点击:

Recommended JSF 2.0 CRUD frameworks

javajsfjsf-2crud

提问by Jan

Can somebody recommend any framework to facilitate CRUD development in JSF 2.0?

有人可以推荐任何框架来促进 JSF 2.0 中的 CRUD 开发吗?

Aspects I value most:

我最看重的方面:

  • As lightweight as possible; limiteddependencies on third party libraries
  • Support for an evolvingdomain model
  • Limited need for repetitive coding; support for scaffolding and/or metaannotations
  • 尽可能轻巧;对第三方库的依赖有限
  • 支持不断发展的领域模型
  • 对重复编码的需求有限;支持脚手架和/或元注释

Any hints highly appreciated! Yours, J.

任何提示高度赞赏!你的,J。

采纳答案by BalusC

CRUD is indeed a piece of cake using JSF 2.0 provided standard facility: a @ViewScopedbean in combination with a <h:dataTable>basically already suffices. Here's a code example which is shamelessly copied from this article.

CRUD 确实是小菜一碟,使用 JSF 2.0 提供的标准设施:一个@ViewScopedbean 结合一个<h:dataTable>基本上就已经足够了。这是从本文中无耻地复制的代码示例。

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.

}

Page:

页:

<!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>

Further, Netbeans has some useful wizardsto genreate a CRUD application based on a datamodel.

此外,Netbeans 有一些有用的向导来基于数据模型对 CRUD 应用程序进行分类。

回答by Bozho

JSF 2.0 itself. CRUD is very easy to do with JSF alone - no need for any other framework. You need

JSF 2.0 本身。CRUD 单独使用 JSF 非常容易——不需要任何其他框架。你需要

  • 1 managed bean (annotated with @ManagedBean)
  • 2 xhtml pages (facelets) - one for list and one for edit/create
  • A <h:dataTable>with aneditlink/button, by which you set the current row object in the managed bean (using action="#{bean.edit(currentRowObject)}"). (In JSF 1.2 this was achieved by <f:setPropertyActionListener>)
  • Action methods (void, with no arguments) to handle the operations
  • @PostConstructto load the data initially.
  • 1 个托管 bean(用 注释@ManagedBean
  • 2 个 xhtml 页面(facelets)——一个用于列表,一个用于编辑/创建
  • <h:dataTable>带有edit链接/按钮的A ,您可以通过它在托管 bean 中设置当前行对象(使用action="#{bean.edit(currentRowObject)}")。(在 JSF 1.2 中,这是通过 实现的<f:setPropertyActionListener>
  • 处理操作的操作方法(void,不带参数)
  • @PostConstruct最初加载数据。

回答by Jan

I found this article useful as well:

我发现这篇文章也很有用:

Conversational CRUD in Java EE 6

Java EE 6 中的会话 CRUD

http://www.andygibson.net/blog/tutorial/pattern-for-conversational-crud-in-java-ee-6/

http://www.andygibson.net/blog/tutorial/pattern-for-conversational-crud-in-java-ee-6/

By Andy Gibson

安迪·吉布森

回答by Michael Leitner

I had the same problem as described: Creating as-fast-as-possible CRUD-App in JEE6.

我遇到了与描述相同的问题:在 JEE6 中创建尽可能快的 CRUD-App。

Beautiful Generator found at: http://sourceforge.net/projects/jbizmo/

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

After defining (Graph-Editor!) your Business-Model/Domain-Model, JBizMo creates the database and a whole CRUD-App out of the Box.

在定义(Graph-Editor!)您的业务模型/领域模型之后,JBizMo 创建了数据库和一个开箱即用的完整 CRUD 应用程序。

  • i18n, JAAS, also supported
  • Views and Menus are generated
  • ... a bunch of parameters to define ...
  • 也支持 i18n、JAAS
  • 生成视图和菜单
  • ...一堆参数来定义...

回答by Ignas

I created this one to speed up process of jsf crud application creation: https://github.com/ignl/happyfacescrudOut of box search, lazy data table, viewing/editing, custom components that reduces code dramatically and of course flexible.

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

回答by Sam

I found an opensource crud generator for JSF+Primefaces

我找到了一个用于 JSF+Primefaces 的开源 crud 生成器

http://minuteproject.wikispaces.com/Primefaces

http://minuteproject.wikispaces.com/Primefaces

And also it generate crud for most of the frameworks http://minuteproject.wikispaces.com/

并且它还为大多数框架http://minuteproject.wikispaces.com/生成 crud