我想问一下netbeans 8.0中的jsf primefaces 我做了一张桌子,我想输入到桌子上。 当我点击保存按钮时,为什么会显示消息警告,例如"交易标记为回滚"。
这是我的代码
创建
<p:dialog id="UsersCreateDlg" widgetVar="UsersCreateDialog" modal="true" resizable="false" appendTo="@(body)" header="#{bundle.CreateUsersTitle}">
<h:form id="UsersCreateForm">
<h:panelGroup id="display">
<p:panelGrid columns="2" rendered="#{usersController.selected != null}">
<p:outputLabel value="#{bundle.CreateUsersLabel_id}" for="id" />
<p:inputText id="id" value="#{usersController.selected.id}" title="#{bundle.CreateUsersTitle_id}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_id}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_userLevelId}" for="userLevelId" />
<p:inputText id="userLevelId" value="#{usersController.selected.userLevelId}" title="#{bundle.CreateUsersTitle_userLevelId}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_userLevelId}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_email}" for="email" />
<p:inputText id="email" value="#{usersController.selected.email}" title="#{bundle.CreateUsersTitle_email}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_email}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_username}" for="username" />
<p:inputText id="username" value="#{usersController.selected.username}" title="#{bundle.CreateUsersTitle_username}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_username}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_realname}" for="realname" />
<p:inputText id="realname" value="#{usersController.selected.realname}" title="#{bundle.CreateUsersTitle_realname}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_realname}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_agreeTimestamp}" for="agreeTimestamp" />
<p:inputText id="agreeTimestamp" value="#{usersController.selected.agreeTimestamp}" title="#{bundle.CreateUsersTitle_agreeTimestamp}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_agreeTimestamp}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_password}" for="password" />
<p:inputText id="password" value="#{usersController.selected.password}" title="#{bundle.CreateUsersTitle_password}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_password}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_passwordMd5}" for="passwordMd5" />
<p:inputText id="passwordMd5" value="#{usersController.selected.passwordMd5}" title="#{bundle.CreateUsersTitle_passwordMd5}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_passwordMd5}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_logins}" for="logins" />
<p:inputText id="logins" value="#{usersController.selected.logins}" title="#{bundle.CreateUsersTitle_logins}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_logins}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_lastLogin}" for="lastLogin" />
<p:inputText id="lastLogin" value="#{usersController.selected.lastLogin}" title="#{bundle.CreateUsersTitle_lastLogin}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_lastLogin}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_status}" for="status" />
<p:inputText id="status" value="#{usersController.selected.status}" title="#{bundle.CreateUsersTitle_status}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_status}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_created}" for="created" />
<p:inputText id="created" value="#{usersController.selected.created}" title="#{bundle.CreateUsersTitle_created}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_created}"/>
<p:outputLabel value="#{bundle.CreateUsersLabel_modified}" for="modified" />
<p:inputText id="modified" value="#{usersController.selected.modified}" title="#{bundle.CreateUsersTitle_modified}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_modified}"/>
</p:panelGrid>
<p:commandButton actionListener="#{usersController.create}" value="#{bundle.Save}" update="display,:UsersListForm:datalist,:growl" oncomplete="handleSubmit(args,'UsersCreateDialog');"/>
<p:commandButton value="#{bundle.Cancel}" onclick="UsersCreateDialog.hide()"/>
</h:panelGroup>
</h:form>
</p:dialog>
2.userscontroller.java
@Named("usersController")
@SessionScoped
public class UsersController implements Serializable {
@EJB
private com.nop.mavenproject5.UsersFacade ejbFacade;
private List<Users> items = null;
private Users selected;
public UsersController() {
}
public Users getSelected() {
return selected;
}
public void setSelected(Users selected) {
this.selected = selected;
}
protected void setEmbeddableKeys() {
}
protected void initializeEmbeddableKey() {
}
private UsersFacade getFacade() {
return ejbFacade;
}
public Users prepareCreate() {
selected = new Users();
initializeEmbeddableKey();
return selected;
}
public void create() {
persist(PersistAction.CREATE, ResourceBundle.getBundle("/Bundle").getString("UsersCreated"));
if (!JsfUtil.isValidationFailed()) {
items = null; // Invalidate list of items to trigger re-query.
}
}
public void update() {
persist(PersistAction.UPDATE, ResourceBundle.getBundle("/Bundle").getString("UsersUpdated"));
}
public void destroy() {
persist(PersistAction.DELETE, ResourceBundle.getBundle("/Bundle").getString("UsersDeleted"));
if (!JsfUtil.isValidationFailed()) {
selected = null; // Remove selection
items = null; // Invalidate list of items to trigger re-query.
}
}
public List<Users> getItems() {
if (items == null) {
items = getFacade().findAll();
}
return items;
}
private void persist(PersistAction persistAction, String successMessage) {
if (selected != null) {
setEmbeddableKeys();
try {
if (persistAction != PersistAction.DELETE) {
getFacade().edit(selected);
} else {
getFacade().remove(selected);
}
JsfUtil.addSuccessMessage(successMessage);
} catch (EJBException ex) {
String msg = "";
Throwable cause = ex.getCause();
if (cause != null) {
msg = cause.getLocalizedMessage();
}
if (msg.length() > 0) {
JsfUtil.addErrorMessage(msg);
} else {
JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
}
} catch (Exception ex) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
}
}
}
public Users getUsers(java.lang.Integer id) {
return getFacade().find(id);
}
public List<Users> getItemsAvailableSelectMany() {
return getFacade().findAll();
}
public List<Users> getItemsAvailableSelectOne() {
return getFacade().findAll();
}
@FacesConverter(forClass = Users.class)
public static class UsersControllerConverter implements Converter {
@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
UsersController controller = (UsersController) facesContext.getApplication().getELResolver().
getValue(facesContext.getELContext(), null, "usersController");
return controller.getUsers(getKey(value));
}
java.lang.Integer getKey(String value) {
java.lang.Integer key;
key = Integer.valueOf(value);
return key;
}
String getStringKey(java.lang.Integer value) {
StringBuilder sb = new StringBuilder();
sb.append(value);
return sb.toString();
}
@Override
public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
if (object == null) {
return null;
}
if (object instanceof Users) {
Users o = (Users) object;
return getStringKey(o.getId());
} else {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "object {0} is of type {1}; expected type: {2}", new Object[]{object, object.getClass().getName(), Users.class.getName()});
return null;
}
}
}
}
任何人都可以帮助我吗?
答案 0 :(得分:0)
有时候如果你用
标记一个类 @Transactional(noRollbackFor = Exception.class)
您可以阻止回滚。