I'm creating an web application, using JSF (2.0).
It has "ViewProducts.xhtml" to view Product with page. Each time this page loaded, if parameter has some thing (Eg: page=1 (ViewProduct.xhtml?page=1)), it's will automatically set the id to setPage property in that Bean.
But, i'm keeping getting this error:
Unable to create managed bean categories. The following problems were found: - Bean or property class bean.Categories for managed bean categories cannot be found.
Here is my code (Categories act like a product container):
faces-config.xml:
<faces-config version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<navigation-rule>
<from-view-id>/template/header.xhtml</from-view-id>
<navigation-case>
<from-outcome>ViewCategories</from-outcome>
<to-view-id>/ViewCategories.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>categories</managed-bean-name>
<managed-bean-class>bean.Categories</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
ViewProducts.xhtml
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
<f:metadata>
<f:viewParam name="page" value="#{categories.page}"/>
</f:metadata>
<h:dataTable value="#{categories.listProduct}" var="cus">
<h:column>
<f:facet name="header">Name</f:facet>
<h:outputText value ="#{cus.name}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">Price</f:facet>
<h:outputText value ="#{cus.price}"></h:outputText>
</h:column>
</h:dataTable>
Categories.java (ManagedBean)
public class Categories implements Serializable {
/** Creates a new instance of categories */
public Categories() {
}
private int page = 0;
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public List<Product> listProduct = null;
public List<Product> getListProduct() {
if (listProduct != null) {
return listProduct;
} else {
listProduct = dataAccess.DataAccess.getCategories(this.page);
return listProduct;
}
}
public void setListProduct(List<Product> listProduct) {
this.listProduct = listProduct;
}
}
Stack trace:
com.sun.faces.mgbean.ManagedBeanCreationException: Unable to create managed bean categories. The following problems were found:
- Bean or property class bean.Categories for managed bean categories cannot be found.
- Bean or property class bean.Categories for managed bean categories cannot be found.
- Bean or property class bean.Categories for managed bean categories cannot be found.
- Bean or property class bean.Categories for managed bean categories cannot be found.
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:263)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:69)
at org.apache.el.parser.AstValue.getValue(AstValue.java:112)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
at javax.faces.component.UIData.getValue(UIData.java:554)
at javax.faces.component.UIData.getDataModel(UIData.java:1248)
at javax.faces.component.UIData.setRowIndex(UIData.java:447)
at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:81)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:823)
at javax.faces.component.UIData.encodeBegin(UIData.java:937)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1611)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
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.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
There are at least 3 problems:
The bean class bean.Categories is not in the classpath.
You cannot have a managed property which is of a narrower scope than the managed bean.
You're duplicating the managed property with <f:viewParam>.
Ensure that the bean class is in the classpath and that you didn't typo'ed the managed bean class. You also need to get rid of the <managed-property>, you don't need it if you're already using <f:viewParam>.
Not related to the problem, but as you're already on JSF2, I'd also suggest to use annotations instead of the faces-config.xml.
Related
I am working with spring webflow
My jsp page is
<!-- header -->
<%#include file="../shared/flows-header.jsp"%>
<div class = "container">
<div class = "row">
<div class = col-sm-6>
<div class = "panel panel-primary">
<div class = "panel-heading">
<h4>Personal Details</h4>
</div>
<div class = "panel-body">
<!-- to display personal details -->
<div class="text-center">
<h3>Name : <strong>${registerModel.user.firstname} ${registerModel.user.lastname}</strong></h3>
<h4>Email : <strong>${registerModel.user.email}</strong></h4>
<h4>Contact : <strong>${registerModel.user.contactNumber}</strong></h4>
<h4>Role : <strong>${registerModel.user.role}</strong></h4>
</div>
<!-- anchor tag to move to personal details page to edit -->
<p>
Edit
</p>
</div>
</div>
</div>
<div class = col-sm-6>
<div class = "panel panel-primary">
<div class = "panel-heading">
<h4>Billing Address</h4>
</div>
<div class = "panel-body">
<!-- to display billing address -->
<div class="text-center">
<p>${registerModel.billing.addressLineOne}, </p>
<p>${registerModel.billing.addressLineTwo}, </p>
<p>${registerModel.billing.city} - ${registerModel.billing.postalCode}, </p>
<p>${registerModel.billing.state}</p>
<p>${registerModel.billing.country}</p>
</div>
<!-- anchor tag to move to billing address page to edit -->
<p>
Edit
</p>
</div>
</div>
</div>
<div class = "row">
<div class = "col-sm-4 col-sm-offset-4">
<div class = "text-center">
<!-- anchor tag to move to success page -->
Confirm Submission
</div>
</div>
</div>
</div>
</div>
<!-- footer -->
<%#include file="../shared/flows-footer.jsp"%>
My signup-flow.xml page is
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow.xsd">
<var name = "user" class = "model.entity.User" />
<var name = "billing" class = "model.entity.Address" />
<on-start>
<evaluate expression="'registerHandler.init()'" result = "flowScope.registerModel" />
</on-start>
<!-- start state -->
<view-state id = "personal" view = "flows/register/signup-personal" model = "'user'"><!-- model value is used as modelAttribute in spring form -->
<transition on = "billing" to = "billing" /><!-- to billing view state -->
<on-exit>
<evaluate expression="'registerHandler.addUser(flowScope.registerModel , user)'" />
</on-exit>
</view-state>
<view-state id = "billing" view = "flows/register/signup-billing" model = "'billing'">
<transition on = "personal" to = "personal" />
<transition on = "confirm" to = "confirm" />
<on-exit>
<evaluate expression="'registerHandler.addBilling(flowScope.registerModel , billing)'" />
</on-exit>
</view-state>
<view-state id = "confirm" view = "flows/register/signup-confirm" model = "flowScope.registerModel">
<transition on = "personal" to = "personal" />
<transition on = "billing" to = "billing" />
<transition on = "submit" to = "submit" />
</view-state>
<action-state id="submit">
<evaluate expression="'registerHandler.saveAll(flowScope.registerModel)'" />
<transition on = "success" to = "success" />
</action-state>
<!-- end state -->
<end-state id = "home" view = "externalRedirect:contextRelative:/" />
<end-state id = "success" view = "flows/register/signup-success" />
<!-- global transition -->
<global-transitions>
<transition on = "home" to = "home"/>
</global-transitions>
</flow>
**The error stack trace is **
ERROR [io.undertow.request] (default task-5) UT005023: Exception
handling request to
/OnlineShoppingFE/views/flows/register/signup-confirm.jsp:
org.springframework.web.util.NestedServletException: Request
processing failed; nested exception is
org.springframework.webflow.execution.FlowExecutionException:
Exception thrown in state 'confirm' of flow 'register' at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:890)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) at
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at
io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
at
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
at
io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at
io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at
io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at
io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at
io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at
io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at
io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at
io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at
io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at
io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at
io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at
org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at
org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
at
org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
at
org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
at
org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1514)
at
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at
io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at
io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at
io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)
at
io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
at
org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at
org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at
org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at
org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
at java.lang.Thread.run(Unknown Source) Caused by:
org.springframework.webflow.execution.FlowExecutionException:
Exception thrown in state 'confirm' of flow 'register' at
org.springframework.webflow.engine.impl.FlowExecutionImpl.wrap(FlowExecutionImpl.java:573)
at
org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:263)
at
org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169)
at
org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:253)
at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998)
... 45 more Caused by: java.lang.IllegalStateException: Exception
occurred rendering view org.springframework.web.servlet.view.JstlView:
name 'flows/register/signup-confirm'; URL
[/views/flows/register/signup-confirm.jsp] at
org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:200)
at
org.springframework.webflow.engine.ViewState.render(ViewState.java:293)
at
org.springframework.webflow.engine.ViewState.refresh(ViewState.java:242)
at
org.springframework.webflow.engine.ViewState.resume(ViewState.java:220)
at org.springframework.webflow.engine.Flow.resume(Flow.java:537) at
org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:259)
... 50 more Caused by: org.apache.jasper.JasperException:
javax.el.PropertyNotFoundException: The class 'java.lang.String' does
not have the property 'user'. at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:473)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at
io.undertow.jsp.JspFileHandler.handleRequest(JspFileHandler.java:32)
at
io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
at
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:274)
at
io.undertow.servlet.handlers.ServletInitialHandler.dispatchToPath(ServletInitialHandler.java:209)
at
io.undertow.servlet.spec.RequestDispatcherImpl.forwardImpl(RequestDispatcherImpl.java:221)
at
io.undertow.servlet.spec.RequestDispatcherImpl.forwardImplSetup(RequestDispatcherImpl.java:147)
at
io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:111)
at
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:170)
at
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316)
at
org.springframework.webflow.mvc.servlet.ServletMvcView.doRender(ServletMvcView.java:55)
at
org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:196)
... 55 more Caused by: javax.el.PropertyNotFoundException: The class
'java.lang.String' does not have the property 'user'. at
javax.el.BeanELResolver.getBeanProperty(BeanELResolver.java:568) at
javax.el.BeanELResolver.getValue(BeanELResolver.java:229) at
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
at com.sun.el.parser.AstValue.getValue(AstValue.java:139) at
com.sun.el.parser.AstValue.getValue(AstValue.java:203) at
com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:917)
at
org.apache.jsp.views.flows.register.signup_002dconfirm_jsp._jspService(signup_002dconfirm_jsp.java:230)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
... 75 more
RegisterModel class is
package flow.model;
import java.io.Serializable;
import model.entity.Address;
import model.entity.User;
public class RegisterModel implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private User user;
private Address billing;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Address getBilling() {
return billing;
}
public void setBilling(Address billing) {
this.billing = billing;
}
}
RegisterHandler class
package handler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import flow.model.RegisterModel;
import model.dao.IUserDAO;
import model.entity.Address;
import model.entity.Cart;
import model.entity.User;
#Component
public class RegisterHandler {
#Autowired
private IUserDAO userDAO;
public RegisterModel init()
{
System.out.println(new RegisterModel().toString());
return (new RegisterModel());
}
public void addUser(RegisterModel registerModel,User user)
{
registerModel.setUser(user);
}
public void addBilling(RegisterModel registerModel,Address billing)
{
registerModel.setBilling(billing);
}
public String saveAll(RegisterModel model)
{
String transitionValue = "success";
//fetch user
User user = model.getUser();
if(user.getRole().equals("ROLE"))
{
Cart cart = new Cart();
cart.setUser(user);
user.setCart(cart);
}
//save user
userDAO.addUser(user);
//get address
Address billing = model.getBilling();
billing.setUserId(user.getId());
billing.setBilling(true);
//save the address
userDAO.addAddress(billing);
return transitionValue;
}
}
I see several possible misunderstandings there, but I think the main one is that you're using single quotes around attributes that you should not. The one causing this particular problem is:
<evaluate expression="'registerHandler.init()'" result = "flowScope.registerModel" />
You're putting into flowScope.registerModel, the String value "registerHandler.init()", not the results of calling registerHandler.init().
Instead, remove the single quotes like this:
<evaluate expression="registerHandler.init()" result = "flowScope.registerModel" />
Same for the later references like:
<view-state id = "billing" view = "flows/register/signup-billing" model = "'billing'">
This should also not have the single quotes around "billing":
<view-state id = "billing" view = "flows/register/signup-billing" model = "billing">
(Also, by declaring <var>s "user" and "billing", those are automatically put on flow scope, so you can refer to them in JSPs directly like ${user.firstname}.)
This question already has an answer here:
Caused by: javax.naming.NameNotFoundException - Name [Class/object] is not bound in this Context
(1 answer)
Closed 9 years ago.
I'm designing a JSF application with managed beans.
For the moment, I've only been trying to create a simple login page (username and password are hard-coded for the moment) :
<h:form class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2><hr />
<input name="username" type="text" class="input-block-level" placeholder="Username" />
<input name="password" type="password" class="input-block-level" placeholder="Password" />
<h:commandButton action="#{userController.login}" class="btn btn-block btn-primary" type="submit" value="Sign in" />
</h:form>
Here is the controller (UserController.java) :
#ManagedBean(name="userController")
#ApplicationScoped
public class UserController {
#EJB
private UserService userService;
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
public UserController() {
}
public void login() throws IOException {
Boolean login = userService.login("admin", "p4ssw0rd");
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
if (login == true) {
externalContext.redirect("dashboard.xhtml");
} else {
externalContext.redirect("login.xhtml");
}
}
}
And this is the UserService.java file :
#Stateless
public class UserService {
#PersistenceContext
private EntityManager em;
public static String md5(String input) {
// Removed for clarity...
}
public Boolean login(String username, String password) {
//String hash = md5(password);
return Boolean.TRUE; // As you can see, nothing can fail for the moment
}
}
When I submit the login form, a NullPointerException shows up :
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:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
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:409)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at com.myname.myproject.managedbean.UserController.login(UserController.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 24 more
In UserController.java, if I replace this line :
Boolean login = userService.login("admin", "p4ssw0rd");
By this one :
Boolean login = true; // Or false (I've tested twice)
Everything works OK, so it seems like Java fails to find the UserService...
Thanks for your help, I'm completely lost.
Did you check putting getters and setters in your managed bean called UserController?
If you did not, even if the code compiles correctly, dependency injection would not be held correctly.
I believe that the problem is the EJB. It should be annotated #LocalBean if it is no-interface bean or implement an interface otherwise. Try something like this:
#Stateless
public class UserService implements UserServiceLocal {
#Override
public boolean login () {
//dummy implementation
return true;
}
}
where UserServiceLocal is:
#Local
public interface UserServiceLocal {
public boolean login();
}
Usage:
#ManagedBean(name="userController")
#ApplicationScoped
public class UserController {
#EJB
private UserServiceLocal userService;
public void login() {
userService.login();
}
}
Regarding your question about why it should implement an interface, please see EJB's - when to use Remote and/or local interfaces?. An EJB (enterprise java bean) can have an interface (which can be annotated with #Remote, meaning that the bean who implements it runs in a distributed environment, or annotated with #Local meaning the bean runs inside the same JVM. In contrast, a no-interface bean is a bean that does not implements any interface. Therefore, you should instruct JVM to treat it as a bean instead of a POJO (plain old java object); this can be accomplished by adding #LocalBean annotation on the class that it is supposed to be your bean /EJB.
I have a DataTable with a <h:column> as <h:selectBooleanCheckbox>. Both the facet header and the DataTable rows content for that <h:column> are <h:selectBooleanCheckbox>. Below is the code I used:
<h:form>
<h:dataTable
value="#{employeeService.employeeList }"
var="empl"
binding="#{employeeService.dataTablebinding }">
......
......
......
<h:column>
<f:facet name="header">
<h:selectBooleanCheckbox id="chkBoxAll" value="#{empl.checked }" valueChangeListener="#{employeeService.checkAll }" onclick="submit()"></h:selectBooleanCheckbox>
</f:facet>
<h:selectBooleanCheckbox id="tableChkBox" value="#{empl.checked }" valueChangeListener="#{employeeService.getCheckChanged }" onclick="submit()"></h:selectBooleanCheckbox>
</h:column>
</h:dataTable>
</h:form>
When I click the facet header checkbox, I want all the rows checkbox to be checked and the same for unchecked also. This is the code I have for the ValueChangeListener of that facet header checkbox:
public void checkAll(ValueChangeEvent event){
for(Employee empl : employeeList){
employeeList.remove(empl);
empl.setChecked(true);
employeeList.add(empl);
}
}
I am getting the below excception:
SEVERE: AbortProcessingException thrown when processing event of type 'javax.faces.component.WrapperEvent' during phase 'PROCESS_VALIDATIONS 3' for component with ID or Client ID of 'j_id7'
27 Apr, 2013 8:20:38 PM javax.faces.component.UIViewRoot broadcastEvents
SEVERE: javax.faces.event.AbortProcessingException: java.util.ConcurrentModificationException
javax.faces.event.AbortProcessingException: java.util.ConcurrentModificationException
at javax.faces.event.MethodExpressionValueChangeListener.processValueChange(MethodExpressionValueChangeListener.java:93)
at javax.faces.event.ValueChangeEvent.processListener(ValueChangeEvent.java:134)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:771)
at javax.faces.component.UIData.broadcast(UIData.java:943)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:444)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:701)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:18)
at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(ReceiveSendUpdates.java:132)
at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:74)
at com.icesoft.faces.webapp.http.core.RequestVerifier.service(RequestVerifier.java:31)
at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:24)
at com.icesoft.faces.webapp.http.servlet.BasicAdaptingServlet.service(BasicAdaptingServlet.java:16)
at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:53)
at com.icesoft.faces.webapp.http.servlet.SessionVerifier.service(SessionVerifier.java:26)
at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:131)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:56)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
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:291)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at com.infy.service.DataTableService.checkAll(DataTableService.java:66)
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 javax.faces.event.MethodExpressionValueChangeListener.processValueChange(MethodExpressionValueChangeListener.java:91)
... 33 more
Please let me know the reason for this ConcurrentModificationException.
for(Employee empl : employeeList){
empl.setChecked(true);
}
As Luigi stated, you don't need to remove the employee from the list.
It is because while looping over the list you are modifying it:
for(Employee empl : employeeList){
employeeList.remove(empl);
empl.setChecked(true);
employeeList.add(empl);
}
You need to use iterator.
for(Employee empl : employeeList){
// employeeList.remove(empl); //Not required
empl.setChecked(true);
//employeeList.add(empl); //Not required
}
Update As mentioned by Luiggi Mendoza, you don't need to remove and add the element back to the list to alter it. Just take the reference and modify it.
It's not a problem about jsf 1.2. The problem here is that you can't modify a Collection while you are iterating over it.
I think you get the same behaviour doing this:
public void checkAll(ValueChangeEvent event){
for(Employee empl : employeeList){
empl.setChecked(true);
}
}
I am trying to set up CDI (for #ConversationScoped) within an app using JSF/Primefaces and deployed on Jetty. I am receiving this exception with (what I believe is) a very basic ConversationScoped bean. Have combed through all relevant search results I can find and come up with nothing, so will appreciate any advice.
#Named
#ConversationScoped
public class RegisterBean implements Serializable {
...
private #Inject Conversation conversation;
...
public String doSubmitBasicInfo() {
conversation.begin();
if(accountType == null)
return null;
if(accountType.equals("seller_account"))
return "register_seller_1?faces-redirect=true";
else if(accountType.equals("buyer_account"))
return "register_buyer_1?faces-redirect=true";
return null;
}
...
The relevant portion of the JSF page is:
<div style="text-align:center;" class="noBorder autoMargin">
<p:commandButton type="submit" action="#{registerBean.doSubmitBasicInfo}" ajax="false" value="Submit" styleClass="autoMargin"></p:commandButton>
</div>
The exception is:
javax.enterprise.context.ContextNotActiveException: Conversation Context not active when method called on conversation Conversation with id: 1
at org.jboss.weld.context.conversation.ConversationImpl.verifyConversationContextActive(ConversationImpl.java:197)
at org.jboss.weld.context.conversation.ConversationImpl.getLastUsed(ConversationImpl.java:154)
at org.jboss.weld.context.AbstractConversationContext.isExpired(AbstractConversationContext.java:337)
at org.jboss.weld.context.AbstractConversationContext.invalidate(AbstractConversationContext.java:285)
at org.jboss.weld.jsf.WeldPhaseListener.deactivateConversations(WeldPhaseListener.java:146)
at org.jboss.weld.jsf.WeldPhaseListener.afterPhase(WeldPhaseListener.java:91)
at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:107)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
at org.eclipse.jetty.server.Server.handle(Server.java:350)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:890)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:944)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:630)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:606)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538)
at java.lang.Thread.run(Thread.java:722)
I am new to STRUTS and am trying to work out simple example . When I execute the example I get the following error on the internet browser..
<< javax.servlet.ServletException: javax.servlet.jsp.JspException: Exception creating bean of class com.example.LoginForm >>
and in the Eclipse console see a similar error with additional line on Null pointer exception
<< SEVERE: Error creating form bean of class com.example.LoginForm
java.lang.NullPointerException >>
Listed below is part of my struts-config.xml
struts-config.xml - Extract
<struts-config>
< form-beans>
< form-bean name="loginRequest" type="com.example.LoginForm" />
</form-bean>
< /form-beans>
< !-- =========================================== Global Forward Definitions -->
< global-forwards>
< forward
name="welcome"
path="/Welcome.do"/>
< /global-forwards>
< !-- =========================================== Action Mapping Definitions -->
< action-mappings>
< action path="/login"
name="loginRequest"
type="com.example.LoginAction">
< forward name="success"
path="/success.jsp">
< /forward>
< forward name="failure"
path="/login.jsp">
< /forward>
</action>
<action path="/Welcome"
forward="/pages/Welcome.jsp"/>
< /action-mappings>
< !-- ======================================== Message Resources Definitions -->
< message-resources parameter="MessageResources" />
< /struts-config>
My JSP login.jsp
< %# taglib prefix="bean" uri="/WEB-INF/struts-bean.tld" %>
< %# taglib prefix="html" uri="/WEB-INF/struts-html.tld" %>
< bean:message key="title" />
< html:form action="login">
<bean:message key="login.username"/>
<html:text property="username"></html:text>
<br>
<bean:message key="login.password"/>
<html:text property="password"></html:text>
<br>
<html:submit>
<bean:message key="login.submit"/>
</html:submit>
< /html:form>
The LoginForm class
package com.example;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm
{
private String username;
private String password;
public LoginForm()
{
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
The LoginAction class
package com.example;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class LoginAction extends Action
{
#Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
LoginForm login = (LoginForm)form;
String name = login.getUsername();
String pass = login.getPassword();
if(name.equals("hello") && pass.equals("hello"))
return mapping.findForward("success");
else
return mapping.findForward("failure");
}
}
The MessageResources.properties class
title=Welcome
login.username=Username
loguin.password=Password
login.submit=Submit
Stack Trace
org.apache.struts.util.RequestUtils createActionForm
SEVERE: Error creating form bean of class com.example.LoginForm
java.lang.NullPointerException
=========== ======================
at org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:289)
at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:259)
at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:213)
at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:526)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:503)
at org.apache.jsp.login_jsp._jspx_meth_html_005fform_005f0(login_jsp.java:122)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:79)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
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:128)
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:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)
Jun 23, 2011 12:56:47 PM org.apache.struts.util.PropertyMessageResources loadLocale
WARNING: Resource org/apache/struts/taglib/html/LocalStrings_en_US.properties Not Found.
Jun 23, 2011 12:56:47 PM org.apache.struts.util.PropertyMessageResources loadLocale
WARNING: Resource org/apache/struts/taglib/html/LocalStrings_en.properties Not Found.
Jun 23, 2011 12:56:47 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception <br/><br/>
javax.servlet.jsp.JspException: Exception creating bean of class com.example.LoginForm under form name loginRequest
at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:536)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:503)
at org.apache.jsp.login_jsp._jspx_meth_html_005fform_005f0(login_jsp.java:122)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:79)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
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:128)
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:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)
Can anyone figure out what I am doing wrong and why this error is occuring.
Thanks,
Ankit
You forgot a / in your action on html:form.
This is how you should call your action in the form.
<html:form action="/login">
Update, Make sure you clean all your XML documents including your JSP's
The following (examples) were not allowed in the XML validator:
< form-beans>
< /struts-config>
XML doesn't allow spaces inside the <></>, </> tags. This also applies to the tags too.
Update, I found the correct problem. It's your declaration for form beans in your struts-config.xml.
You have:
<form-beans>
<form-bean name="loginRequest" type="com.example.LoginForm" />
</form-bean>
</form-beans>
You're closing your <form-bean> twice.
Solution:
< form-beans>
<form-bean name="loginRequest" type="com.example.LoginForm" />
</form-beans>
Now, this must work. :-) (Sorry for the late reply, work demands me.)
Also, I suggest using an IDE such as Eclipse or NetBeans to do your Struts project (and not do this by hand-typing) especially for your XML declarations.
Check Your jsp.Its using login as action form instead of LoginForm.
Well that error is because of you have not configure you Struts-config.xml properly.
you have to give particular Form-Bean name when action of the Form is called Accordingly.
now look at you code you have give action like this.
< action path="/login" name="loginRequest" type="com.example.LoginAction">
< forward name="success" path="/success.jsp">< /forward>
but while u are calling POJO also together but you have to call that bean before you make POST action for putting any data into the user interaction.
so make one new action which can call bean class before you main action is called.
for example:
< action path="/loginPre" name="loginRequest" forward="/youloginformname.jsp">
</action>
that way problem will get solved.