i'm trying to create basic crud operations using JSF 2.2,Spring 4.01 and Hibernate.
From register.xhtml,if I click register button,it should save firstname(as of now) in the db.
I have
1. registration page(register.xhtml)
2.RegistrationAction(Controller)
3.RegistrationEntity(Entity class which has only one field,firstName, as of now)
4.LoginRegistrationServiceImpl(service class)--I have interface (LoginRegistrationService)
In the controller class(RegistrationAction),when deploying,im getting the service class object,after I clicked the register button,it becomes null.
Below is my code:
RegistrationAction:
@ManagedBean(name="register")
@Controller
public class RegistrationAction implements Serializable{
private RegistrationEntity regEntity=new RegistrationEntity();
private LoginRegistrationService lrInterfcae;
public LoginRegistrationService getLrInterfcae() {
return lrInterfcae;
}
@Autowired
public void setLrInterfcae(LoginRegistrationService lrInterfcae) {
this.lrInterfcae = lrInterfcae;
System.out.println("Interface Obj--"+lrInterfcae);
}
public String registerUser(){
System.out.println("Interface Obj--"+lrInterfcae);
return "/login";
}
public RegistrationEntity getRegEntity() {
return regEntity;
}
public void setRegEntity(RegistrationEntity regEntity) {
this.regEntity = regEntity;
}
}
----------------------------------------------
SERVICE CLASS-LOGINREGISTRATIONSERIMPL
@Service
public class LoginRegistrationSerImpl implements LoginRegistrationService{
}
-------------------------------------------------------------
SPRING-CONFIG.xml
<beans ....>
<context:component-scan base-package = "Controllers,Serviceimplementations,DAOImplementations" />
<!--<bean id="registerController" class="Controllers.RegistrationAction"/>-->
</beans>
-------------------------------------------------------------------
OUTPUT:
After deploymenent:
05-Jul-2019 02:52:58.387 INFO [http-nio-8084-exec-3] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
05-Jul-2019 02:52:58.564 INFO [http-nio-8084-exec-3] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization completed in 615 ms
05-Jul-2019 02:52:58.709 INFO [http-nio-8084-exec-3] com.sun.faces.config.ConfigureListener.contextInitialized Initializing Mojarra 2.2.7 ( 20140610-1547 https://svn.java.net/svn/mojarra~svn/tags/2.2.7@13362) for context '/matrimony'
05-Jul-2019 02:52:58.993 INFO [http-nio-8084-exec-3] com.sun.faces.spi.InjectionProviderFactory.createInstance JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
05-Jul-2019 02:53:00.211 INFO [http-nio-8084-exec-3] org.springframework.web.servlet.FrameworkServlet.initServletBean FrameworkServlet 'dispatcher': initialization started
05-Jul-2019 02:53:00.222 INFO [http-nio-8084-exec-3] org.springframework.context.support.AbstractApplicationContext.prepareRefresh Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Fri Jul 05 02:53:00 IST 2019]; parent: Root WebApplicationContext
05-Jul-2019 02:53:00.224 INFO [http-nio-8084-exec-3] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/springConf/newSpringXMLConfig.xml]
Interface Obj--Serviceimplementations.LoginRegistrationSerImpl@38635264
05-Jul-2019 02:53:01.239 INFO [http-nio-8084-exec-3] org.springframework.web.servlet.FrameworkServlet.initServletBean FrameworkServlet 'dispatcher': initialization completed in 1028 ms
05-Jul-2019 02:53:01.242 INFO [http-nio-8084-exec-3] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/matrimony] is completed
AFTER CLICKING THE REGISTER BUTTON:(IT BECOMES NULL)
05-Jul-2019 02:53:01.242 INFO [http-nio-8084-exec-3] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/matrimony] is completed
Interface Obj--null
-------------------------------------
NOTE:I have tried all scopes. and also tried by keeping @ManagedBean and @Controller (classes) separately.
Register.xhtml:
inputText:firstname
commandbutton:Register,in action attribute I called registerUser method of RegistrationAction class.