这里我试图使用Hibernate会话工厂将角色插入到数据库中, 现在我的问题是当我试图插入数据时,它说错误
错误:
WARNING: /role.xhtml @20,63 value="#{roleBean.rolepojo.role}": Target Unreachable, 'rolepojo' returned null
javax.el.PropertyNotFoundException: /role.xhtml @20,63 value="#{roleBean.rolepojo.role}": Target Unreachable, 'rolepojo' returned null
我已经实现了所有属性,任何人都可以在我出错的地方提供帮助。
PrimeFaces代码:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
template="/WEB-INF/template.xhtml">
<ui:define name="implementation">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container-fluid ui-fluid">
<h:form id="roleUpdateForm" >
<p:messages id="msgs" />
<p:panelGrid columns="2" cellpadding="5" styleClass="ui-responsive" id="roleData">
<h:outputLabel value="Roles : *" />
<p:inputText value="#{roleBean.rolepojo.role}" />
<h:outputLabel value="Role Description : *" />
<p:inputTextarea rows="6" cols="33" value="#{roleBean.rolepojo.description}"/>
<h:outputLabel value="Start Date : *" />
<p:calendar styleClass="start-emp" value="#{roleBean.rolepojo.startDate}" timeZone="IST" pattern="dd/MM/yyyy" requiredMessage="Pls Enter Start Date"/>
<h:outputLabel value="End Date : *" />
<p:calendar styleClass="start-emp" value="#{roleBean.rolepojo.endDate}" timeZone="IST" pattern="dd/MM/yyyy" requiredMessage="Pls Enter End Date"/>
<f:facet name="footer">
<p:commandButton value="Save"
actionListener="#{roleBean.saveRole}"
icon="ui-icon-check"
rendered="#{empty roleBean.rolepojo.id}"
update=":roleUpdateForm:role"/>
<p:commandButton value="Update" actionListener="#{roleBean.updateRole}" icon="ui-icon-check" rendered="#{0 lt roleBean.rolepojo.id}" update=":roleUpdateForm:role"/>
<p:commandButton value="New" actionListener="#{roleBean.newRole}" icon="ui-icon-check" rendered="#{0 lt roleBean.rolepojo.id}" update=":roleUpdateForm:roleData"/>
</f:facet>
</p:panelGrid>
<p:growl id="msges" showDetail="true"/>
<p:dataTable id="role" var="roleListStack" value="#{roleBean.roleList}" style="margin:20px auto;width:400px;"
selectionMode="single" selection="#{roleBean.rolepojo}" rowKey="#{roleListStack.id}">
<f:facet name="header">
Role Listing
</f:facet>
<p:ajax event="rowSelect" update=":roleUpdateForm:roleData" />
<p:ajax event="rowUnselect" update=":roleUpdateForm:roleData" />
<p:column headerText="S.No" >
<h:outputText value="#{roleListStack.id}" />
</p:column>
<p:column headerText="Role Name" >
<h:outputText value="#{roleListStack.role}" />
</p:column>
<p:column headerText="Role Description" >
<h:outputText value="#{roleListStack.description}" />
</p:column>
<p:column headerText="Role Start Date" >
<h:outputText value="#{roleListStack.startDate}" />
</p:column>
<p:column headerText="Role End Date" >
<h:outputText value="#{roleListStack.endDate}" />
</p:column>
</p:dataTable>
</h:form>
</div>
</ui:define>
RoleBean代码:
package com.ihub.beans;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.context.RequestContext;
import org.primefaces.event.SelectEvent;
import org.primefaces.event.UnselectEvent;
import com.ihub.pojo.Organization;
import com.ihub.pojo.Role;
import com.ihub.service.RoleService;
@ManagedBean
@SessionScoped
public class RoleBean {
@ManagedProperty("#{roleService}")
private RoleService roleService;
private List<Role> roleList;
private Role rolepojo;
@PostConstruct
public void init(){
//System.out.println("in bean init");
rolepojo = new Role();
roleList = roleService.getList(Role.class);
//System.out.println(rolepojo.getId()+ " rolepojo.getId()");
}
public void saveRole(ActionEvent event){
System.out.println(" in Role save func");
//System.out.println(rolepojo.getRole());
roleService.saveRoleService(rolepojo);
// System.out.println("Role save"+rolepojo.getRole());
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Role","Role Created Successfully"));
}
public void updateRole(ActionEvent event){
System.out.println("action event");
roleService.updateRole(rolepojo);
}
public void newRole(ActionEvent event){
RequestContext.getCurrentInstance().reset("roleUpdateForm:roleData");
}
public Role getRolepojo() {
return rolepojo;
}
public void setRolepojo(Role rolepojo) {
this.rolepojo = rolepojo;
}
public List<Role> getRoleList() {
return roleList;
}
public void setRoleList(List<Role> roleList) {
this.roleList = roleList;
}
public RoleService getRoleService() {
return roleService;
}
public void setRoleService(RoleService roleService) {
this.roleService = roleService;
}
}
Pojo课程:
package com.ihub.pojo;
import java.util.Date;
public class Role {
private int id;
private String role;
private String description;
private Date startDate;
private Date endDate;
public Role(int id, String role, String description) {
super();
this.id = id;
this.role = role;
this.description = description;
}
public Role(String role, String description) {
super();
this.role = role;
this.description = description;
}
public Role() {
// TODO Auto-generated constructor stub
}
public int getId() {
//System.out.println("from role id"+ id);
return id;
}
public void setId(int id) {
this.id = id;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
}