I am using PrimeFaces 4.0, NetBeans associated with two xhtml pages. The xhtml renders a select one radio menu from which the user may select an experiment about which they'd like more information. When they do, I'd like for the xhtml to pass the experiment back to java as a string. After the user hits submit, I'd like another xhtml page to open from which the user can further narrow their search criteria. As of right now, when the user clicks submit, there is a null pointer exception. Also, using System.out.println(), I can see that java is not getting the string back from the web page as my Glassfish server output prints (in part) : "Info: nullaaaaaaaaaaaaaaaaaaaaa". It doesn't print the other println() at all.
XHTML portion
<h:form>
<h:panelGrid>
<p:selectOneRadio id="Test" value="Please Selecte a Test">
<p:ajax update="Test" partialSubmit="#{targetBeantFranz.selectedNameOfExperiments}"/>
<f:selectItems value="#{targetBeantFranz.nameofexperiments}" />
</p:selectOneRadio>
<h:commandButton value="Select" action="open" />
</h:panelGrid>
</h:form>
and here are the affected Java methods (The entire JAVA file is much, much longer than this):
#ManagedBean(name = "targetBeantFranz", eager = true)
#SessionScoped
public class TargetBeanFranz implements Serializable {
public String selectedNameOfExperiments;
private final Map<String, String> nameofexperiments;
public TargetBeanFranz() throws SQLException {
nameofexperiments = new HashMap<String, String>();
XYexpdataServiceAdapter xydata = new XYexpdataServiceAdapterImpl();
List<String> dbnameofexperiments = xydata.getNameofexperiments();
for (String ta : dbnameofexperiments) {
nameofexperiments.put(ta, ta);
}
}
public String getSelectedNameOfExperiments() {
System.out.println(selectedNameOfExperiments + "aaaaaaaaaaaaaaaaaaaaa");
return selectedNameOfExperiments;
}
public void setSelectedNameOfExperiments(String selectedNameOfExperiments) {
System.out.println(selectedNameOfExperiments + "bbbbbbbbbbbbbbbbbbbbbbbbb");
this.selectedNameOfExperiments = selectedNameOfExperiments;
}
}
public Map<String, String> getNameofexperiments() {
return nameofexperiments;
}
}
ETA: My stacktrace looks like this:
java.lang.NullPointerException
at javax.faces.component.SelectItemsIterator$MapIterator.next(SelectItemsIterator.java:346)
at javax.faces.component.SelectItemsIterator$MapIterator.next(SelectItemsIterator.java:315)
at javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:155)
at javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:64)
at javax.faces.component.SelectUtils.matchValue(SelectUtils.java:86)
at javax.faces.component.UISelectOne.validateValue(UISelectOne.java:153)
at javax.faces.component.UIInput.validate(UIInput.java:983)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at org.primefaces.component.layout.Layout.processValidators(Layout.java:233)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)
Check this article for further info about JSF UI component <h:selectOneMenu> .
it might be the case that u need to initialize in the bean's constructor: selectedNameOfExperiments
Related
I'm pretty new to programming and i encountered this problem i have search internet and couldn't find the answer i was looking for. Hope you can help me here. Thanks!
I'm trying to pass 2 variables which is the name and custid.
(i'm using mysql workbench as my database).
I'm guessing my error is something to do with.
String email=request.getParameter("email");
String password=request.getParameter("password");
here's my code:
#WebServlet("/login")
public class loginServlet extends HttpServlet{
#Resource(name="jdbc/eg3752")
private DataSource usercatalogue;
#Override
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
String email=request.getParameter("email");
String password=request.getParameter("password");
Connection connection=null;
Statement statement=null;
ResultSet resultset=null;
String login="SELECT * FROM customer where email='"+email+"'";
try
{
connection=usercatalogue.getConnection();
statement=connection.createStatement();
resultset=statement.executeQuery(login);
while(resultset.next())
{
// check if password is same in the database
if(password.equals(resultset.getString("password")))
{
HttpSession session =request.getSession();
session.setAttribute("name", resultset.getString("fullname"));
session.setAttribute("custid", resultset.getString("customerId"));
response.sendRedirect(this.getServletContext().getContextPath()+"/search.html");
}
else
{
response.sendRedirect(this.getServletContext().getContextPath() + "/login.html");
}
}
}
catch(Exception e)
{
e.printStackTrace();
System.err.println(e.getMessage());
}
}
}
and this is the error on the GlassFish Server 4
Severe: java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:518)
at com.aleksi.loginServlet.doPost(loginServlet.java:58)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)
You did not include the "caused by" sections of the stack trace, which are the important part.
An IllegalStateException on a sendRedirect() has to do with the HTTP protocol and occurs when the response to the client has already been committed. This will usually happen when either the response buffer has reached max size or someone has called flush() explicitly or written something to the output stream and caused the response to be committed.
After calling sendRedirect() add return; and then try.
i have to try add into cart tbl but all values are go in function addcart()
but still throw exception javax.faces.el.EvaluationException: java.lang.NullPointerException.
please give me solution i tryed alot all value are goes but last give a exception how can fix this error i develop the ecommerce website
for detail page
public String singledispp(int pid)
{
ProductTbl p=ad.searchproduct(pid);
product_id=p.getProductId();
price=p.getFinalPrice();
HttpSession session=(HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true);
session.setAttribute("product_id",product_id);
session.setAttribute("price",price);
return "/client/single.xhtml?faces-redirect=true&product_id="+product_id;
}
//for display product id wise
public Collection<ProductTbl> getproductbyid()
{
HttpServletRequest request=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession session = request.getSession(true);
int cat = (int)session.getAttribute("product_id");
return ad.getAllProductByProductid(cat);
}
public void addcart()
{
// id,productid,qty.price,total;
HttpServletRequest request=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession session = request.getSession(true);
id = (int)session.getAttribute("id");
product_id=(int)session.getAttribute("product_id");
price=(int)session.getAttribute("price");
total=p1*qty;
cl.addIntoCart(id,product_id, qty,price, total);
}
following Exception is there
javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at com.sun.faces.facelets.component.UIRepeat.broadcast(UIRepeat.java:927)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
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:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at JsfAdminbean.ProductBean.addcart(ProductBean.java:647)
at JsfAdminbean.ProductBean$Proxy$_$$_WeldClientProxy.addcart(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at javax.el.ELUtil.invokeMethod(ELUtil.java:326)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:536)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
at com.sun.el.parser.AstValue.invoke(AstValue.java:269)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 36 more
Successfully deploy to Glassfish. Go to run it and
com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class com.wellpoint.mobility.aggregation.admin.HomeServlet
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:329)
at com.sun.enterprise.web.WebContainer.createServletInstance(WebContainer.java:983)
at com.sun.enterprise.web.WebModule.createServletInstance(WebModule.java:2130)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1404)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1211)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:237)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Env-Prop: com.wellpoint.mobility.aggregation.admin.FireboltServlet/entityManager#Field-Injectable Resource. Class name = com.wellpoint.mobility.aggregation.admin.FireboltServlet Field name=entityManager#java.lang.String### into class com.wellpoint.mobility.aggregation.admin.FireboltServlet: Can not set javax.persistence.EntityManager field com.wellpoint.mobility.aggregation.admin.FireboltServlet.entityManager to com.wellpoint.mobility.aggregation.admin.HomeServlet
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:717)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:484)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:141)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:127)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:324)
... 30 more
Caused by: java.lang.IllegalArgumentException: Can not set javax.persistence.EntityManager field com.wellpoint.mobility.aggregation.admin.FireboltServlet.entityManager to com.wellpoint.mobility.aggregation.admin.HomeServlet
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:75)
at java.lang.reflect.Field.set(Field.java:741)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:665)
... 34 more
FireboltServlet is our implementation of HttpServlet, all of our Servlets extend that class. It has a field entityManager
#PersistenceContext(unitName = "persistenceUnit", type = PersistenceContextType.TRANSACTION)
private EntityManager entityManager;
...
public EntityManager getEntityManager()
{
if (entityManager == null)
{
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("persistenceUnit");
entityManager = entityManagerFactory.createEntityManager();
}
return entityManager;
}
public void setEntityManager(EntityManager entityManager)
{
this.entityManager = entityManager;
}
But I can't find anything attempting to map HomeServlet to that field, nor can I imagine why it would. This exception seems to have popped up out of nowhere, I haven't made any recent changes that I can imagine causing this. Thanks for your help!
Sometimes the server freezes objects mainly the latter, as it does not recognize it, what I do is create a phantom method to lock and release that I need to compile and recognized.
That I do when I do not recognize some method.
First of all: sorry for my english, I'll try to do my best :)
I have a Java EE application, with javabeans providing the logic via remote interfaces and a primefaces interface with his baking beans. For example I have this in my ejb project:
#Stateless
#LocalBean
public class reporteService implements reporteServiceRemote {
[...]
public LinkedList<LineaBalanceteSaldosClientesTransport> balanceteSaldosClientes(...parameters...) {
LinkedList<LineaBalanceteSaldosClientesTransport> lineas = new LinkedList<>();
// execute a native query and return the results
// the query return about 6/700 rows
List results = this.balanceteSaldosClientes(...parameters...);
Iterator it = results.iterator();
while (it.hasNext()) {
Object[] result = (Object[])it.next();
String codigoCliente = (String) result[0];
Integer idCliente = (Integer) result[1];
Integer nombreCliente = (String) result[2];
// generate new line
linea = new LineaBalanceteSaldosClientesTransport();
linea.setIdCliente(idCliente);
linea.setCodigoCliente(codigoCliente);
linea.setNombreCliente(nombreCliente);
lineas.add(linea);
}
return lineas;
}
[...]
}
#Remote
public interface ReporteServiceRemote {
[...]
public LinkedList<LineaBalanceteSaldosClientesTransport> balanceteSaldosClientes(...parameters...);
[...]
}
This works fine, I've tried outputting the lines and the final linkedlist in the log and the method ends fine. The point is calling the method from the war, using his remote interface. This is the baking bean for a primefaces page that is supposed to show the results:
#ManagedBean
#ViewScoped
public class ReporteBean implements Serializable {
[...]
#EJB
private ReporteServicesRemote reporteServices;
[...]
public LinkedList<LineaBalanceteSaldosClientesTransport> obtenerBalanceteSaldosClientes() {
try {
LinkedList<LineaBalanceteSaldosClientesTransport> lbsct = reporteServices.balanceteSaldosClientes(
this.getFechaSaldo(),
this.getIdsMonedas(),
cliente != null ? cliente.idCliente : null
);
return lbsct;
} catch (Exception ex) {
LOG.log(Level.SEVERE, "ERROR", ex);
this.messagesBean.message(FacesMessage.SEVERITY_ERROR, "ERROR", "Error al intentar generar Balancete de Saldos: " + ex.getLocalizedMessage());
}
return null;
}
[...]
}
when it call the method reporteServices.balanceteSaldosClientes it ends fine, but (I think) the serialization of the resulting object fail, throwing this exception:
javax.ejb.EJBException: java.rmi.ServerError: Error occurred in server thread; nested exception is:
java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.pfl.dynamic.copyobject.impl.Exceptions
at com.myproject.services.reportes._ReporteServicesRemote_Wrapper.balanceteSaldosClientes(com/myproject/services/reportes/_ReporteServicesRemote_Wrapper.java)
at com.tecytal.utils.servlets.testServlet.processRequest(testServlet.java:124)
at com.tecytal.utils.servlets.testServlet.doGet(testServlet.java:158)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Unknown Source)
Caused by: java.rmi.ServerError: Error occurred in server thread; nested exception is:
java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.pfl.dynamic.copyobject.impl.Exceptions
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.wrapException(Util.java:699)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:257)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:150)
at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:226)
at com.myproject.services.reportes.__ReporteServicesRemote_Remote_DynamicStub.balanceteSaldosClientes(com/myproject/services/reportes/__ReporteServicesRemote_Remote_DynamicStub.java)
... 32 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.pfl.dynamic.copyobject.impl.Exceptions
at org.glassfish.pfl.dynamic.copyobject.impl.ClassCopierBase.copy(ClassCopierBase.java:131)
at org.glassfish.pfl.dynamic.copyobject.impl.ClassCopierOrdinaryImpl$ClassFieldCopierUnsafeImpl$17.copy(ClassCopierOrdinaryImpl.java:810)
at org.glassfish.pfl.dynamic.copyobject.impl.ClassCopierOrdinaryImpl$ClassFieldCopierUnsafeImpl.copy(ClassCopierOrdinaryImpl.java:1008)
at org.glassfish.pfl.dynamic.copyobject.impl.ClassCopierOrdinaryImpl.doCopy(ClassCopierOrdinaryImpl.java:1128)
at org.glassfish.pfl.dynamic.copyobject.impl.ClassCopierBase.copy(ClassCopierBase.java:129)
at org.glassfish.pfl.dynamic.copyobject.impl.ClassCopierOrdinaryImpl$ClassFieldCopierUnsafeImpl$17.copy(ClassCopierOrdinaryImpl.java:810)
at org.glassfish.pfl.dynamic.copyobject.impl.ClassCopierOrdinaryImpl$ClassFieldCopierUnsafeImpl.copy(ClassCopierOrdinaryImpl.java:1008)
at org.glassfish.pfl.dynamic.copyobject.impl.ClassCopierOrdinaryImpl.doCopy(ClassCopierOrdinaryImpl.java:1128)
at org.glassfish.pfl.dynamic.copyobject.impl.ClassCopierBase.copy(ClassCopierBase.java:129)
[...]
(lot of similar lines repeated)
Someone pointed me to a memory problem, but in this case java was running with 8GB of dedicated memory (Xmx8192m, Xms8192m, MaxPermSize=4096m) and the linkedlist in this case contains only 600/700 objects. If I put i.e. a LIMIT 100 in the native query that returns the first list of results I get no exception and all works flawlessy.
I'm doing it wrong? Is there a more efficient way to pass datas between beans? Or there's another bug I cannot see?
Thank you for every suggestion.
This problem can be resolved using the Value List Handler pattern, more informations and working examples can be found here
Core J2EE Patterns - Value List Handler -
http://www.oracle.com/technetwork/java/valuelisthandler-142464.html
EJB 3.0 Stateful Session Bean Example -
http://www.go4expert.com/articles/ejb-30-stateful-session-bean-example-t4212/
Hope this can help someone.
I already typed the value within the brackets ('06717-100'), and the method is working, but I don't know how to pass the value of that same component as a parameter. I want the user to type a zipcode in a p:inputMask, and when focus is lost (or - would be better - when the maximum length of the field is reached) the method for searching it in the database is called.
<h:form id="frm">
<h:panelGrid>
<p:outputPanel autoUpdate="true"
id="pnl">
<p:inputMask id="txtCep"
mask="99999-999"
placeholder="Digite o CEP"
value="#{cepMB.cep.cep}">
<p:ajax event="blur"
listener="#{cepMB.busca('06717-100')}"
process="#this"
update="frm:pnl" />
</p:inputMask>
And below is the code of method busca:
public void busca(String cep) {
Cep c = this.cepRepository.findByCep(cep);
if(c.getId() != null) {
this.cep = c;
}
}
I'm using JSF 2.2, PrimeFaces 4.0, GlassFish 4.0 and Hibernate 4.3.1 with JPA 2.1.
Stacktrace:
AdvertĂȘncia: javax.el.PropertyNotFoundException: /principal.xhtml #59,31 value="#{cepMB.cep.cep}": Target Unreachable, 'null' returned null
javax.faces.FacesException: javax.el.PropertyNotFoundException: /principal.xhtml #59,31 value="#{cepMB.cep.cep}": Target Unreachable, 'null' returned null
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:270)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1193)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:744)
Caused by: javax.el.PropertyNotFoundException: /principal.xhtml #59,31 value="#{cepMB.cep.cep}": Target Unreachable, 'null' returned null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:124)
at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:183)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)
at javax.faces.component.UIInput.validate(UIInput.java:976)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:552)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIForm.visitTree(UIForm.java:371)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:399)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:263)
... 33 more
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, 'null' returned null
at com.sun.el.parser.AstValue.getTarget(AstValue.java:192)
at com.sun.el.parser.AstValue.getType(AstValue.java:86)
at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
... 50 more
#{cepMB.cep} refers to entity Cep, and #{cepMB.cep.cep} refers to public String getCep() of Cep.
Change your JSF code to:
<p:inputMask id="txtCep"
mask="99999-999"
placeholder="Digite o CEP"
value="#{cepMB.cep.cep}">
<p:ajax event="blur"
listener="#{cepMB.busca(cepMB.cep.cep)}"
process="#this"
update="frm:pnl" />
</p:inputMask>
Also, make sure your cep field in your cepMB is always initialized with a right not null value:
#ManagedBean
#ViewScoped
public class CepMB {
Cep cep;
#PostConstruct
public void init() {
cep = new Cep();
}
//rest of your getters, setters, code...
}