JSFログインページでスタックしました。助けてください。
login.jsp
<f:view>
<h:messages style="color: red"
showDetail="true"/>
<h:form id="login">
<h:panelGrid columns="2" border="0">
Username: <h:inputText id="nip"
value="#{peg.nip}"/>
Password: <h:inputSecret id="passwd"
value="#{peg.passwd}"/>
</h:panelGrid>
<h:commandButton id="submit"
value="Login"
action="#{peg.login}"/>
<br>
</h:form>
</f:view>
pegawai.java
@Entity
@Table(name = "pegawai")
@NamedQueries({
@NamedQuery(name = "Pegawai.findAll", query = "SELECT p FROM Pegawai p"),
@NamedQuery(name = "Pegawai.findById", query = "SELECT p FROM Pegawai p WHERE p.id = :id"),
@NamedQuery(name = "Pegawai.findByOtoritasId", query = "SELECT p FROM Pegawai p WHERE p.otoritasId = :otoritasId")})
public class Pegawai implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@Lob
@Column(name = "nip")
private String nip;
@Basic(optional = false)
@Lob
@Column(name = "nama_depan")
private String namaDepan;
@Lob
@Column(name = "nama_tengah")
private String namaTengah;
@Lob
@Column(name = "nama_belakang")
private String namaBelakang;
@Basic(optional = false)
@Column(name = "otoritas_id")
private int otoritasId;
@Basic(optional = false)
@Lob
@Column(name = "passwd")
private String passwd;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "pegawai")
private Collection<Assets> assetsCollection;
@JoinColumn(name = "jabatan_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Jabatan jabatan;
@JoinColumn(name = "dept_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Department department;
public Pegawai() {
}
public Pegawai(Integer id) {
this.id = id;
}
public Pegawai(Integer id, String nip, String namaDepan, int otoritasId, String passwd) {
this.id = id;
this.nip = nip;
this.namaDepan = namaDepan;
this.otoritasId = otoritasId;
this.passwd = passwd;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNip() {
return nip;
}
public void setNip(String nip) {
this.nip = nip;
}
public String getNamaDepan() {
return namaDepan;
}
public void setNamaDepan(String namaDepan) {
this.namaDepan = namaDepan;
}
public String getNamaTengah() {
return namaTengah;
}
public void setNamaTengah(String namaTengah) {
this.namaTengah = namaTengah;
}
public String getNamaBelakang() {
return namaBelakang;
}
public void setNamaBelakang(String namaBelakang) {
this.namaBelakang = namaBelakang;
}
public int getOtoritasId() {
return otoritasId;
}
public void setOtoritasId(int otoritasId) {
this.otoritasId = otoritasId;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
public Collection<Assets> getAssetsCollection() {
return assetsCollection;
}
public void setAssetsCollection(Collection<Assets> assetsCollection) {
this.assetsCollection = assetsCollection;
}
public Jabatan getJabatan() {
return jabatan;
}
public void setJabatan(Jabatan jabatan) {
this.jabatan = jabatan;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Pegawai)) {
return false;
}
Pegawai other = (Pegawai) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "Assets.Entities.Pegawai[id=" + id + "]";
}
pegawaimanager.java
public class PegawaiManager{
private Integer id;
@PersistenceContext
private EntityManager em;
private Department department;
private String nip;
private String namaDepan;
private String namaTengah;
private String namaBelakang;
private int otoritasId;
private String passwd;
private Jabatan jabatan;
private Collection<Assets> assetsCollection;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNip() {
return nip;
}
public void setNip(String nip) {
this.nip = nip;
}
public String getNamaDepan() {
return namaDepan;
}
public void setNamaDepan(String namaDepan) {
this.namaDepan = namaDepan;
}
public String getNamaTengah() {
return namaTengah;
}
public void setNamaTengah(String namaTengah) {
this.namaTengah = namaTengah;
}
public String getNamaBelakang() {
return namaBelakang;
}
public void setNamaBelakang(String namaBelakang) {
this.namaBelakang = namaBelakang;
}
public int getOtoritasId() {
return otoritasId;
}
public void setOtoritasId(int otoritasId) {
this.otoritasId = otoritasId;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
public Collection<Assets> getAssetsCollection() {
return assetsCollection;
}
public void setAssetsCollection(Collection<Assets> assetsCollection) {
this.assetsCollection = assetsCollection;
}
public Jabatan getJabatan() {
return jabatan;
}
public void setJabatan(Jabatan jabatan) {
this.jabatan = jabatan;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
public String login()
{
Pegawai q = (Pegawai) em.createQuery("SELECT p FROM Pegawai p").getSingleResult();
//Query q = em.createQuery("select object(p) from Pegawai as p");
/*if(!q.isEmpty()){
return "app-main";
}else{
return "app-error";
}*/
//em.close();
return "app-main";
}
そしてこのface-config.xml
<navigation-rule>
<from-view-id>/login.jsp</from-view-id>
<navigation-case>
<from-outcome>app-main</from-outcome>
<to-view-id>/index.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>app-error</from-outcome>
<to-view-id>/error.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>peg</managed-bean-name>
<managed-bean-class>Assets.Entities.PegawaiManager</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
web.xml
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/login.jsp</welcome-file>
</welcome-file-list>
ログインボタンを押すと、ページの例外
javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:775)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1267)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
at Assets.Entities.PegawaiManager.login(PegawaiManager.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
助けてください、なぜ私がQueryメソッドを実行したときに常に例外が発生するのですか?apache tomcatとmysqlを使用してデプロイしましたが、mysqlコネクタがライブラリフォルダに追加されました