aspose file tools*
The moose likes JSF and the fly likes jsf/ jpa login application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "jsf/ jpa login application " Watch "jsf/ jpa login application " New topic
Author

jsf/ jpa login application

Indran Govender
Greenhorn

Joined: Jan 25, 2009
Posts: 1
Hello all,

I am new to Java ee, and I am trying to develop a login/user registration application with much frustration. I am hoping that someone on this forum might help me.

My problem is I don't understand how to "call" the createOrUpdate method from my controller within my jsf backing bean.

This is what I have thus far:

UserBean.java

@Entity


public class UserBean implements Serializable {

@Id
@GeneratedValue
private Integer user_id;

private String msisdn;
private String password;
private String fname;
private String lname;
private String gender;
private String status;


public UserBean(){

}

public String getFname() {
return fname;
}

public void setFname(String fname) {
this.fname = fname;
}

public String getGender() {
return gender;
}

public void setGender(String gender) {
this.gender = gender;
}

public String getLname() {
return lname;
}

public void setLname(String lname) {
this.lname = lname;
}

public String getMsisdn() {
return msisdn;
}

public void setMsisdn(String msisdn) {
this.msisdn = msisdn;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public Integer getUser_id() {
return user_id;
}

public void setUser_id(Integer user_id) {
this.user_id = user_id;
}

}


UserServiceBean.java

@Stateless

public class UserServiceBean implements UserService {

@PersistenceContext
private EntityManager em;


public UserBean createOrUpdate(UserBean user){
return em.merge(user);
}

public void remove(UserBean user) {
em.remove(em.merge(user));
}

public UserBean find(Object user_id){
return em.find(com.ericsson.portal.entity.UserBean.class, user_id);
}

}


UserService.java

@Local
public interface UserService {

UserBean createOrUpdate(UserBean user);
void remove(UserBean user);
UserBean find(Object user_id);

}


JSF Backing Bean:

UserManagedBean.java



public class UserManagedBean {

private String msisdn;
private String password;

public String getMsisdn() {
return msisdn;
}

public void setMsisdn(String msisdn) {
this.msisdn = msisdn;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}



@EJB
private UserServiceBean userServiceBean;
private UserBean userBean;



public String create() {


userBean.createOrUpdate(userBean);
return null;
}
}


JSP:

<jsp:root version="2.1" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:webuijsf="http://www.sun.com/webui/webuijsf">
<jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
<f:view>
<h:form id="register">
<h:panelGrid columns="3">
<hutputLabel value="Mobile Number" for="msisdn" styleClass="text" />
<h:inputText id="msisdn" value="#{userManagedBean.msisdn}" required="true" styleClass="input" />

<hutputLabel value="Password" for="password" styleClass="text" />
<h:inputText id="password" value="#{userManagedBean.password}" required="true" styleClass="input" />
</h:panelGrid>

<h:panelGroup>
<h:commandButton id="registerButton" action="#{userManagedBean.create}" value="Register" styleClass="button" />
</h:panelGroup>
</h:form>
</f:view>
</jsp:root>



Now, when I enter the msisdn and password I get the following error:

Description: An unhandled exception occurred during the execution of the web application. Please review the following stack trace for more information regarding the error.

Exception Details: java.lang.NullPointerException
null
Possible Source of Error:
Class Name: portal.managedBeans.UserManagedBean
File Name: UserManagedBean.java
Method Name: create
Line Number: 58

Source not available. Information regarding the location of the exception can be identified using the exception stack trace below.

Stack Trace:

portal.managedBeans.UserManagedBean.create(UserManagedBean.java:58)
sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.sun.el.parser.AstValue.invoke(AstValue.java:187)
com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
com.sun.rave.web.ui.appbase.faces.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
javax.faces.component.UICommand.broadcast(UICommand.java:383)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:447)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
com.sun.faces.extensions.avatar.lifecycle.PartialTraversalLifecycle.execute(PartialTraversalLifecycle.java:94)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:267)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)


Help would be really appreciated.

-Idg


Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
I haven't looked at your unformatted code closely, but I spotted a "NullPointerException" message at top of your stacktrace. This simply means that some object reference at the mentioned line, inside the mentioned method of the mentioned class is null while your code is trying to access/invoke it.

Just make sure that it is not null.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

Welcome to the JavaRanch, Indran!

If my blurry little eyes don't (again) deceive me, you're trying to invoke a method on an object that doesn't exist. Hint: there's a "Code" button on the message editor. Use it to generate tags that will display your code better.

JSF will construct JavaBeans for you, but only if you define them as managed beans in the faces-config file. Apparently you did not do that for userManagedBean .

Good practice in JEE would be that the backing bean would be a managed bean and it would talk to a DAO/service object which would handle the persistence-related functions. The JEE framework would inject the persistence manager (EntityManager).

As far as it goes, I've got a VERY long list of why webapps should generally NOT have their own login code, but instead use the security system that Sun created for J2EE wherever possible.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsf/ jpa login application