Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf commandButton actionListener不在primeFaces积垢生成器netbeans插件nbpfcrudgen-0.15.2-7.3.1impl.nbm上工作_Jsf_Jakarta Ee_Primefaces_Ejb_Netbeans Plugins - Fatal编程技术网

Jsf commandButton actionListener不在primeFaces积垢生成器netbeans插件nbpfcrudgen-0.15.2-7.3.1impl.nbm上工作

Jsf commandButton actionListener不在primeFaces积垢生成器netbeans插件nbpfcrudgen-0.15.2-7.3.1impl.nbm上工作,jsf,jakarta-ee,primefaces,ejb,netbeans-plugins,Jsf,Jakarta Ee,Primefaces,Ejb,Netbeans Plugins,我正在netbeans上测试primeFaces积垢生成器 当您按下Create.xhtml页面的save按钮时,actionListener不工作。 编辑行时也会发生同样的情况。Glassfish错误日志中没有任何内容,firebug上也没有任何内容 测试日期: 插件版本:nbpfcrudgen-0.15.2-7.3.1impl.nbm Ubuntu 12.04 64位 Netbeans Netbeans IDE 7.3 Primefaces 3.5 GlassFish服务器开源版本4.0

我正在netbeans上测试primeFaces积垢生成器

当您按下Create.xhtml页面的save按钮时,actionListener不工作。 编辑行时也会发生同样的情况。Glassfish错误日志中没有任何内容,firebug上也没有任何内容

测试日期:

  • 插件版本:nbpfcrudgen-0.15.2-7.3.1impl.nbm
  • Ubuntu 12.04 64位
  • Netbeans Netbeans IDE 7.3
  • Primefaces 3.5
  • GlassFish服务器开源版本4.0
  • Mozilla Firefox 22.0
  • MySql 5.6.11
您可以观看测试视频:

下载源代码:

按钮:

p:commandButton actionListener="#{countryController.saveNew}" value="#{myBundle.Save}" update="display,:CountryListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,CountryCreateDialog);"/>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:p="http://primefaces.org/ui">

<ui:composition>

    <p:dialog id="CountryCreateDlg" widgetVar="CountryCreateDialog" modal="true" resizable="false" appendToBody="true" header="#{myBundle.CreateCountryTitle}">

        <h:form id="CountryCreateForm">

            <h:panelGroup id="display">
                <p:panelGrid columns="2" rendered="#{countryController.selected != null}">

                    <p:outputLabel value="#{myBundle.CreateCountryLabel_name}" for="name" />
                    <p:inputText id="name" value="#{countryController.selected.name}" title="#{myBundle.CreateCountryTitle_name}" required="true" requiredMessage="#{myBundle.CreateCountryRequiredMessage_name}"/>
                </p:panelGrid>
                <p:commandButton actionListener="#{countryController.saveNew}" value="#{myBundle.Save}" update="display,:CountryListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,CountryCreateDialog);"/>
                <p:commandButton value="#{myBundle.Cancel}" onclick="CountryCreateDialog.hide()"/>
            </h:panelGroup>

        </h:form>

    </p:dialog>

</ui:composition>

</html>
@Entity
@Table(name = "country")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = Country.FIND_ALL, query = "SELECT c FROM Country c"),
@NamedQuery(name = Country.FIND_BY_ID, query = "SELECT c FROM Country c WHERE c.id = :id"),
@NamedQuery(name = Country.FIND_BY_NAME, query = "SELECT c FROM Country c WHERE c.name = :name")})
public class Country implements Serializable, Comparable<Country> {

private static final long serialVersionUID = 1L;

public static final String FIND_ALL = "Country.findAll";
public static final String FIND_BY_ID = "Country.findById";
public static final String FIND_BY_NAME = "Country.findBySubtag";

@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "seqCountry")
@TableGenerator(name = "seqCountry", initialValue = 10000)
@Basic(optional = false)
@Column(name = "id", unique = true, updatable = false)
private Long id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "name", unique = true, updatable = false)
private String name;
...
import org.primefaces.test.crud.bean.AbstractFacade;
import org.primefaces.test.crud.controller.util.JsfUtil;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.event.ActionEvent;

import java.util.ResourceBundle;
import javax.ejb.EJBException;

/**
 * Represents an abstract shell of to be used as JSF Controller to be used in
 * AJAX-enabled applications. No outcomes will be generated from its methods
 * since handling is designed to be done inside one page.
 */
public abstract class AbstractController<T> {

private AbstractFacade<T> ejbFacade;
private Class<T> itemClass;
private T selected;
private List<T> items;

private enum PersistAction {

    CREATE,
    DELETE,
    UPDATE
}

public AbstractController() {
}

public AbstractController(Class<T> itemClass) {
    this.itemClass = itemClass;
}

protected AbstractFacade<T> getFacade() {
    return ejbFacade;
}

protected void setFacade(AbstractFacade<T> ejbFacade) {
    this.ejbFacade = ejbFacade;
}

public T getSelected() {
    return selected;
}

public void setSelected(T selected) {
    this.selected = selected;
}

protected void setEmbeddableKeys() {
    // Nothing to do if entity does not have any embeddable key.
}

;

protected void initializeEmbeddableKey() {
    // Nothing to do if entity does not have any embeddable key.
}

/**
 * Returns all items in a List object
 *
 * @return
 */
public List<T> getItems() {
    if (items == null) {
        items = this.ejbFacade.findAll();
    }
    return items;
}

public void save(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Updated");
    persist(PersistAction.UPDATE, msg);
}

public void saveNew(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Created");
    persist(PersistAction.CREATE, msg);
    if (!isValidationFailed()) {
        items = null; // Invalidate list of items to trigger re-query.
    }
}

public void delete(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Deleted");
    persist(PersistAction.DELETE, msg);
    if (!isValidationFailed()) {
        selected = null; // Remove selection
        items = null; // Invalidate list of items to trigger re-query.
    }
}

private void persist(PersistAction persistAction, String successMessage) {
    if (selected != null) {
        this.setEmbeddableKeys();
        try {
            if (persistAction != PersistAction.DELETE) {
                this.ejbFacade.edit(selected);
            } else {
                this.ejbFacade.remove(selected);
            }
            JsfUtil.addSuccessMessage(successMessage);
        } catch (EJBException ex) {
            String msg = "";
            Throwable cause = JsfUtil.getRootCause(ex.getCause());
            if (cause != null) {
                msg = cause.getLocalizedMessage();
            }
            if (msg.length() > 0) {
                JsfUtil.addErrorMessage(msg);
            } else {
                JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/MyBundle").getString("PersistenceErrorOccured"));
            }
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
            JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/MyBundle").getString("PersistenceErrorOccured"));
        }
    }
}

/**
 * Creates a new instance of an underlying entity and assigns it to Selected
 * property.
 *
 * @return
 */
public T prepareCreate(ActionEvent event) {
    T newItem;
    try {
        newItem = itemClass.newInstance();
        this.selected = newItem;
        initializeEmbeddableKey();
        return newItem;
    } catch (InstantiationException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

public boolean isValidationFailed() {
    return JsfUtil.isValidationFailed();
}
}
Page Create.xhtml(使用页面进入template.xhtml,编辑.xhtml列表.xhtml视图.xhtml):

p:commandButton actionListener="#{countryController.saveNew}" value="#{myBundle.Save}" update="display,:CountryListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,CountryCreateDialog);"/>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:p="http://primefaces.org/ui">

<ui:composition>

    <p:dialog id="CountryCreateDlg" widgetVar="CountryCreateDialog" modal="true" resizable="false" appendToBody="true" header="#{myBundle.CreateCountryTitle}">

        <h:form id="CountryCreateForm">

            <h:panelGroup id="display">
                <p:panelGrid columns="2" rendered="#{countryController.selected != null}">

                    <p:outputLabel value="#{myBundle.CreateCountryLabel_name}" for="name" />
                    <p:inputText id="name" value="#{countryController.selected.name}" title="#{myBundle.CreateCountryTitle_name}" required="true" requiredMessage="#{myBundle.CreateCountryRequiredMessage_name}"/>
                </p:panelGrid>
                <p:commandButton actionListener="#{countryController.saveNew}" value="#{myBundle.Save}" update="display,:CountryListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,CountryCreateDialog);"/>
                <p:commandButton value="#{myBundle.Cancel}" onclick="CountryCreateDialog.hide()"/>
            </h:panelGroup>

        </h:form>

    </p:dialog>

</ui:composition>

</html>
@Entity
@Table(name = "country")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = Country.FIND_ALL, query = "SELECT c FROM Country c"),
@NamedQuery(name = Country.FIND_BY_ID, query = "SELECT c FROM Country c WHERE c.id = :id"),
@NamedQuery(name = Country.FIND_BY_NAME, query = "SELECT c FROM Country c WHERE c.name = :name")})
public class Country implements Serializable, Comparable<Country> {

private static final long serialVersionUID = 1L;

public static final String FIND_ALL = "Country.findAll";
public static final String FIND_BY_ID = "Country.findById";
public static final String FIND_BY_NAME = "Country.findBySubtag";

@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "seqCountry")
@TableGenerator(name = "seqCountry", initialValue = 10000)
@Basic(optional = false)
@Column(name = "id", unique = true, updatable = false)
private Long id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "name", unique = true, updatable = false)
private String name;
...
import org.primefaces.test.crud.bean.AbstractFacade;
import org.primefaces.test.crud.controller.util.JsfUtil;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.event.ActionEvent;

import java.util.ResourceBundle;
import javax.ejb.EJBException;

/**
 * Represents an abstract shell of to be used as JSF Controller to be used in
 * AJAX-enabled applications. No outcomes will be generated from its methods
 * since handling is designed to be done inside one page.
 */
public abstract class AbstractController<T> {

private AbstractFacade<T> ejbFacade;
private Class<T> itemClass;
private T selected;
private List<T> items;

private enum PersistAction {

    CREATE,
    DELETE,
    UPDATE
}

public AbstractController() {
}

public AbstractController(Class<T> itemClass) {
    this.itemClass = itemClass;
}

protected AbstractFacade<T> getFacade() {
    return ejbFacade;
}

protected void setFacade(AbstractFacade<T> ejbFacade) {
    this.ejbFacade = ejbFacade;
}

public T getSelected() {
    return selected;
}

public void setSelected(T selected) {
    this.selected = selected;
}

protected void setEmbeddableKeys() {
    // Nothing to do if entity does not have any embeddable key.
}

;

protected void initializeEmbeddableKey() {
    // Nothing to do if entity does not have any embeddable key.
}

/**
 * Returns all items in a List object
 *
 * @return
 */
public List<T> getItems() {
    if (items == null) {
        items = this.ejbFacade.findAll();
    }
    return items;
}

public void save(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Updated");
    persist(PersistAction.UPDATE, msg);
}

public void saveNew(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Created");
    persist(PersistAction.CREATE, msg);
    if (!isValidationFailed()) {
        items = null; // Invalidate list of items to trigger re-query.
    }
}

public void delete(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Deleted");
    persist(PersistAction.DELETE, msg);
    if (!isValidationFailed()) {
        selected = null; // Remove selection
        items = null; // Invalidate list of items to trigger re-query.
    }
}

private void persist(PersistAction persistAction, String successMessage) {
    if (selected != null) {
        this.setEmbeddableKeys();
        try {
            if (persistAction != PersistAction.DELETE) {
                this.ejbFacade.edit(selected);
            } else {
                this.ejbFacade.remove(selected);
            }
            JsfUtil.addSuccessMessage(successMessage);
        } catch (EJBException ex) {
            String msg = "";
            Throwable cause = JsfUtil.getRootCause(ex.getCause());
            if (cause != null) {
                msg = cause.getLocalizedMessage();
            }
            if (msg.length() > 0) {
                JsfUtil.addErrorMessage(msg);
            } else {
                JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/MyBundle").getString("PersistenceErrorOccured"));
            }
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
            JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/MyBundle").getString("PersistenceErrorOccured"));
        }
    }
}

/**
 * Creates a new instance of an underlying entity and assigns it to Selected
 * property.
 *
 * @return
 */
public T prepareCreate(ActionEvent event) {
    T newItem;
    try {
        newItem = itemClass.newInstance();
        this.selected = newItem;
        initializeEmbeddableKey();
        return newItem;
    } catch (InstantiationException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

public boolean isValidationFailed() {
    return JsfUtil.isValidationFailed();
}
}

实体:

p:commandButton actionListener="#{countryController.saveNew}" value="#{myBundle.Save}" update="display,:CountryListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,CountryCreateDialog);"/>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:p="http://primefaces.org/ui">

<ui:composition>

    <p:dialog id="CountryCreateDlg" widgetVar="CountryCreateDialog" modal="true" resizable="false" appendToBody="true" header="#{myBundle.CreateCountryTitle}">

        <h:form id="CountryCreateForm">

            <h:panelGroup id="display">
                <p:panelGrid columns="2" rendered="#{countryController.selected != null}">

                    <p:outputLabel value="#{myBundle.CreateCountryLabel_name}" for="name" />
                    <p:inputText id="name" value="#{countryController.selected.name}" title="#{myBundle.CreateCountryTitle_name}" required="true" requiredMessage="#{myBundle.CreateCountryRequiredMessage_name}"/>
                </p:panelGrid>
                <p:commandButton actionListener="#{countryController.saveNew}" value="#{myBundle.Save}" update="display,:CountryListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,CountryCreateDialog);"/>
                <p:commandButton value="#{myBundle.Cancel}" onclick="CountryCreateDialog.hide()"/>
            </h:panelGroup>

        </h:form>

    </p:dialog>

</ui:composition>

</html>
@Entity
@Table(name = "country")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = Country.FIND_ALL, query = "SELECT c FROM Country c"),
@NamedQuery(name = Country.FIND_BY_ID, query = "SELECT c FROM Country c WHERE c.id = :id"),
@NamedQuery(name = Country.FIND_BY_NAME, query = "SELECT c FROM Country c WHERE c.name = :name")})
public class Country implements Serializable, Comparable<Country> {

private static final long serialVersionUID = 1L;

public static final String FIND_ALL = "Country.findAll";
public static final String FIND_BY_ID = "Country.findById";
public static final String FIND_BY_NAME = "Country.findBySubtag";

@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "seqCountry")
@TableGenerator(name = "seqCountry", initialValue = 10000)
@Basic(optional = false)
@Column(name = "id", unique = true, updatable = false)
private Long id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "name", unique = true, updatable = false)
private String name;
...
import org.primefaces.test.crud.bean.AbstractFacade;
import org.primefaces.test.crud.controller.util.JsfUtil;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.event.ActionEvent;

import java.util.ResourceBundle;
import javax.ejb.EJBException;

/**
 * Represents an abstract shell of to be used as JSF Controller to be used in
 * AJAX-enabled applications. No outcomes will be generated from its methods
 * since handling is designed to be done inside one page.
 */
public abstract class AbstractController<T> {

private AbstractFacade<T> ejbFacade;
private Class<T> itemClass;
private T selected;
private List<T> items;

private enum PersistAction {

    CREATE,
    DELETE,
    UPDATE
}

public AbstractController() {
}

public AbstractController(Class<T> itemClass) {
    this.itemClass = itemClass;
}

protected AbstractFacade<T> getFacade() {
    return ejbFacade;
}

protected void setFacade(AbstractFacade<T> ejbFacade) {
    this.ejbFacade = ejbFacade;
}

public T getSelected() {
    return selected;
}

public void setSelected(T selected) {
    this.selected = selected;
}

protected void setEmbeddableKeys() {
    // Nothing to do if entity does not have any embeddable key.
}

;

protected void initializeEmbeddableKey() {
    // Nothing to do if entity does not have any embeddable key.
}

/**
 * Returns all items in a List object
 *
 * @return
 */
public List<T> getItems() {
    if (items == null) {
        items = this.ejbFacade.findAll();
    }
    return items;
}

public void save(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Updated");
    persist(PersistAction.UPDATE, msg);
}

public void saveNew(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Created");
    persist(PersistAction.CREATE, msg);
    if (!isValidationFailed()) {
        items = null; // Invalidate list of items to trigger re-query.
    }
}

public void delete(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Deleted");
    persist(PersistAction.DELETE, msg);
    if (!isValidationFailed()) {
        selected = null; // Remove selection
        items = null; // Invalidate list of items to trigger re-query.
    }
}

private void persist(PersistAction persistAction, String successMessage) {
    if (selected != null) {
        this.setEmbeddableKeys();
        try {
            if (persistAction != PersistAction.DELETE) {
                this.ejbFacade.edit(selected);
            } else {
                this.ejbFacade.remove(selected);
            }
            JsfUtil.addSuccessMessage(successMessage);
        } catch (EJBException ex) {
            String msg = "";
            Throwable cause = JsfUtil.getRootCause(ex.getCause());
            if (cause != null) {
                msg = cause.getLocalizedMessage();
            }
            if (msg.length() > 0) {
                JsfUtil.addErrorMessage(msg);
            } else {
                JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/MyBundle").getString("PersistenceErrorOccured"));
            }
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
            JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/MyBundle").getString("PersistenceErrorOccured"));
        }
    }
}

/**
 * Creates a new instance of an underlying entity and assigns it to Selected
 * property.
 *
 * @return
 */
public T prepareCreate(ActionEvent event) {
    T newItem;
    try {
        newItem = itemClass.newInstance();
        this.selected = newItem;
        initializeEmbeddableKey();
        return newItem;
    } catch (InstantiationException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

public boolean isValidationFailed() {
    return JsfUtil.isValidationFailed();
}
}
@实体
@表(name=“country”)
@XmlRootElement
@命名查询({
@NamedQuery(name=Country.FIND_ALL,query=“从国家c中选择c”),
@NamedQuery(name=Country.FIND_BY_ID,query=“从国家c中选择c,其中c.ID=:ID”),
@NamedQuery(name=Country.FIND_BY_name,query=“从国家c中选择c,其中c.name=:name”)}
公共类国家/地区实现可序列化、可比较{
私有静态最终长serialVersionUID=1L;
公共静态最终字符串FIND_ALL=“Country.findAll”;
公共静态最终字符串FIND_BY_ID=“Country.findById”;
公共静态最终字符串FIND_BY_NAME=“Country.findBySubtag”;
@身份证
@GeneratedValue(策略=GenerationType.TABLE,generator=“seqCountry”)
@TableGenerator(name=“seqCountry”,initialValue=10000)
@基本(可选=假)
@列(name=“id”,unique=true,updateable=false)
私人长id;
@基本(可选=假)
@NotNull
@尺寸(最小值=1,最大值=255)
@列(name=“name”,unique=true,updateable=false)
私有字符串名称;
...
抽象控制器:

p:commandButton actionListener="#{countryController.saveNew}" value="#{myBundle.Save}" update="display,:CountryListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,CountryCreateDialog);"/>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:p="http://primefaces.org/ui">

<ui:composition>

    <p:dialog id="CountryCreateDlg" widgetVar="CountryCreateDialog" modal="true" resizable="false" appendToBody="true" header="#{myBundle.CreateCountryTitle}">

        <h:form id="CountryCreateForm">

            <h:panelGroup id="display">
                <p:panelGrid columns="2" rendered="#{countryController.selected != null}">

                    <p:outputLabel value="#{myBundle.CreateCountryLabel_name}" for="name" />
                    <p:inputText id="name" value="#{countryController.selected.name}" title="#{myBundle.CreateCountryTitle_name}" required="true" requiredMessage="#{myBundle.CreateCountryRequiredMessage_name}"/>
                </p:panelGrid>
                <p:commandButton actionListener="#{countryController.saveNew}" value="#{myBundle.Save}" update="display,:CountryListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,CountryCreateDialog);"/>
                <p:commandButton value="#{myBundle.Cancel}" onclick="CountryCreateDialog.hide()"/>
            </h:panelGroup>

        </h:form>

    </p:dialog>

</ui:composition>

</html>
@Entity
@Table(name = "country")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = Country.FIND_ALL, query = "SELECT c FROM Country c"),
@NamedQuery(name = Country.FIND_BY_ID, query = "SELECT c FROM Country c WHERE c.id = :id"),
@NamedQuery(name = Country.FIND_BY_NAME, query = "SELECT c FROM Country c WHERE c.name = :name")})
public class Country implements Serializable, Comparable<Country> {

private static final long serialVersionUID = 1L;

public static final String FIND_ALL = "Country.findAll";
public static final String FIND_BY_ID = "Country.findById";
public static final String FIND_BY_NAME = "Country.findBySubtag";

@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "seqCountry")
@TableGenerator(name = "seqCountry", initialValue = 10000)
@Basic(optional = false)
@Column(name = "id", unique = true, updatable = false)
private Long id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "name", unique = true, updatable = false)
private String name;
...
import org.primefaces.test.crud.bean.AbstractFacade;
import org.primefaces.test.crud.controller.util.JsfUtil;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.event.ActionEvent;

import java.util.ResourceBundle;
import javax.ejb.EJBException;

/**
 * Represents an abstract shell of to be used as JSF Controller to be used in
 * AJAX-enabled applications. No outcomes will be generated from its methods
 * since handling is designed to be done inside one page.
 */
public abstract class AbstractController<T> {

private AbstractFacade<T> ejbFacade;
private Class<T> itemClass;
private T selected;
private List<T> items;

private enum PersistAction {

    CREATE,
    DELETE,
    UPDATE
}

public AbstractController() {
}

public AbstractController(Class<T> itemClass) {
    this.itemClass = itemClass;
}

protected AbstractFacade<T> getFacade() {
    return ejbFacade;
}

protected void setFacade(AbstractFacade<T> ejbFacade) {
    this.ejbFacade = ejbFacade;
}

public T getSelected() {
    return selected;
}

public void setSelected(T selected) {
    this.selected = selected;
}

protected void setEmbeddableKeys() {
    // Nothing to do if entity does not have any embeddable key.
}

;

protected void initializeEmbeddableKey() {
    // Nothing to do if entity does not have any embeddable key.
}

/**
 * Returns all items in a List object
 *
 * @return
 */
public List<T> getItems() {
    if (items == null) {
        items = this.ejbFacade.findAll();
    }
    return items;
}

public void save(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Updated");
    persist(PersistAction.UPDATE, msg);
}

public void saveNew(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Created");
    persist(PersistAction.CREATE, msg);
    if (!isValidationFailed()) {
        items = null; // Invalidate list of items to trigger re-query.
    }
}

public void delete(ActionEvent event) {
    String msg = ResourceBundle.getBundle("/MyBundle").getString(itemClass.getSimpleName() + "Deleted");
    persist(PersistAction.DELETE, msg);
    if (!isValidationFailed()) {
        selected = null; // Remove selection
        items = null; // Invalidate list of items to trigger re-query.
    }
}

private void persist(PersistAction persistAction, String successMessage) {
    if (selected != null) {
        this.setEmbeddableKeys();
        try {
            if (persistAction != PersistAction.DELETE) {
                this.ejbFacade.edit(selected);
            } else {
                this.ejbFacade.remove(selected);
            }
            JsfUtil.addSuccessMessage(successMessage);
        } catch (EJBException ex) {
            String msg = "";
            Throwable cause = JsfUtil.getRootCause(ex.getCause());
            if (cause != null) {
                msg = cause.getLocalizedMessage();
            }
            if (msg.length() > 0) {
                JsfUtil.addErrorMessage(msg);
            } else {
                JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/MyBundle").getString("PersistenceErrorOccured"));
            }
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
            JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/MyBundle").getString("PersistenceErrorOccured"));
        }
    }
}

/**
 * Creates a new instance of an underlying entity and assigns it to Selected
 * property.
 *
 * @return
 */
public T prepareCreate(ActionEvent event) {
    T newItem;
    try {
        newItem = itemClass.newInstance();
        this.selected = newItem;
        initializeEmbeddableKey();
        return newItem;
    } catch (InstantiationException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

public boolean isValidationFailed() {
    return JsfUtil.isValidationFailed();
}
}
import org.primefaces.test.crud.bean.AbstractFacade;
导入org.primefaces.test.crud.controller.util.JsfUtil;
导入java.util.List;
导入java.util.logging.Level;
导入java.util.logging.Logger;
导入javax.faces.event.ActionEvent;
导入java.util.ResourceBundle;
导入javax.ejb.EJBException;
/**
*表示要用作中使用的JSF控制器的抽象shell
*支持AJAX的应用程序。其方法不会产生任何结果
*因为处理是在一页内完成的。
*/
公共抽象类抽象控制器{
私人学院;
私有类itemClass;
选择私人T;
私人清单项目;
私有枚举持久化操作{
创造,,
删除,
更新
}
公共控制器(){
}
公共抽象控制器(类itemClass){
this.itemClass=itemClass;
}
受保护的AbstractFacade getFacade(){
返回ejbFacade;
}
受保护的void setFacade(AbstractFacade ejbFacade){
this.ejbFacade=ejbFacade;
}
公共T getSelected(){
返回选中的;
}
已选定的公用事业单位(T已选定){
this.selected=selected;
}
受保护的void setEmbeddedBleKeys(){
//如果实体没有任何可嵌入密钥,则无需执行任何操作。
}
;
受保护的void initializeEmbeddableKey(){
//如果实体没有任何可嵌入密钥,则无需执行任何操作。
}
/**
*返回列表对象中的所有项
*
*@返回
*/
公共列表getItems(){
if(items==null){
items=this.ejbFacade.findAll();
}
退货项目;
}
公共作废保存(ActionEvent事件){
String msg=ResourceBundle.getBundle(“/MyBundle”).getString(itemClass.getSimpleName()+“已更新”);
persist(PersistAction.UPDATE,msg);
}
public void saveNew(ActionEvent事件){
String msg=ResourceBundle.getBundle(“/MyBundle”).getString(itemClass.getSimpleName()+“已创建”);
persist(PersistAction.CREATE,msg);
如果(!isValidationFailed()){
items=null;//使要触发重新查询的项列表无效。
}
}
公共作废删除(ActionEvent事件){
String msg=ResourceBundle.getBundle(“/MyBundle”).getString(itemClass.getSimpleName()+“已删除”);
persist(PersistAction.DELETE,msg);
如果(!isValidationFailed()){
selected=null;//删除所选内容
items=null;//使要触发重新查询的项列表无效。
}
}
私有void persist(PersistAction PersistAction,String successMessage){
如果(已选择!=null){
这个.setEmbeddableKeys();
试一试{
if(persistAction!=persistAction.DELETE){
this.ejbFacade.edit(选中);
}否则{
this.ejbFacade.remove(选中);
}
JsfUtil.addSuccessMessage(successMessage);
}捕获(EJBException ex){
字符串msg=“”;
Throwable cause=JsfUtil.getRootCause(例如getCause());
如果(原因!=null){
msg=cause.getLocalizedMessage();
}
如果(msg.length()>0){
JsfUtil.addErrorMessage(msg);
}否则{
JsfUtil.addErrorMessage(例如,ResourceBundle.getBundle(“/MyBundle”).getString(“persistenceErrorOccursed”);
}
}捕获(例外情况除外){
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE,null,ex);
JsfUtil.addErrorMessage(例如,ResourceBundle.getBundle(“/MyBundle”).getString(“persistenceErrorOccursed”);
}
}
}
/**
*创建基础实体的新实例并将其指定给选定实体
*财产。
*
*@返回
*/
公共T准备创建(ActionEvent事件){
T新项目;
试一试{
newItem=itemClass.newInstance();
this.selected=newItem;
初始化embeddablekey();
返回新项目;
}catch(实例化异常){