Managed bean instance variable gives exceptions when JSF file is executed [duplicate] - jsf

I have results from
Query query = session.createQuery("From Pool as p left join fetch p.poolQuestion as s");
query and I would like to display it on JSP.
I have loop:
<c:forEach items="${pools}" var="pool">
<p>${pool.name}</p>
</c:forEach>
and I would like to display results from poolQuestion table (which is Join table). The value that i want to display is 'answer'.
How can I do it?
<c:forEach items="${pools}" var="pool">
<p>${pool.answer}</p>
<p>${pool.name}</p>
</c:forEach>
The above code doesn't works.
The error is:
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/home.jsp at line 21
18: <c:forEach items="${pools}" var="pool">
19:
20: <p>${pool.name}</p>
21: <c:out value="${pool.poolQuestion.answer}"/>
22:
23: </c:forEach>
24:
SEVERE: Servlet.service() for servlet appServlet threw exception
javax.el.PropertyNotFoundException: Property 'answer' not found on type com.pool.app.domain.Pool
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:214)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:191)
at javax.el.BeanELResolver.property(BeanELResolver.java:300)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:81)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:938)
at org.apache.jsp.WEB_002dINF.views.home_jsp._jspx_meth_c_005fforEach_005f0(home_jsp.java:119)
at org.apache.jsp.WEB_002dINF.views.home_jsp._jspService(home_jsp.java:78)
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:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:574)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
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.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java: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:680)
The model is:
public List<Pool> getAll(){
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery("From Pool as p left join fetch p.poolQuestions as s");
return query.list();
The controller is:
List<Pool> pool = poolService.getAll();
model.addAttribute("pools", pool);
And the View is:
<c:forEach items="${pools}" var="pool">
<p>${pool.name}</p>
<c:out value="${pool.answer}"/>
</c:forEach>
PS. the ${pool.name} is displayed properly

javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean
This literally means that the mentioned class com.example.Bean doesn't have a public (non-static!) getter method for the mentioned property foo. Note that the field itself is irrelevant here!
The public getter method name must start with get, followed by the property name which is capitalized at only the first letter of the property name as in Foo.
public Foo getFoo() {
return foo;
}
You thus need to make sure that there is a getter method matching exactly the property name, and that the method is public (non-static) and that the method does not take any arguments and that it returns non-void. If you have one and it still doesn't work, then chances are that you were busy editing code forth and back without firmly cleaning the build, rebuilding the code and redeploying/restarting the application. You need to make sure that you have done so.
For boolean (not Boolean!) properties, the getter method name must start with is instead of get.
public boolean isFoo() {
return foo;
}
Regardless of the type, the presence of the foo field itself is thus not relevant. It can have a different name, or be completely absent, or even be static. All of below should still be accessible by ${bean.foo}.
public Foo getFoo() {
return bar;
}
public Foo getFoo() {
return new Foo("foo");
}
public Foo getFoo() {
return FOO_CONSTANT;
}
You see, the field is not what counts, but the getter method itself. Note that the property name itself should not be capitalized in EL. In other words, ${bean.Foo} won't ever work, it should be ${bean.foo}.
See also:
javax.el.PropertyNotFoundException: Property 'foo' not readable on type java.lang.Boolean
How does Java expression language resolve boolean attributes? (in JSF 1.2)
Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
Outcommented Facelets code still invokes EL expressions like #{bean.action()} and causes javax.el.PropertyNotFoundException on #{bean.action}

I believe the id accessors don't match the bean naming conventions and that's why the exception is thrown. They should be as follows:
public Integer getId() { return id; }
public void setId(Integer i){ id= i; }

Check the items in forEach
<c:forEach items="${pools}" var="pool">
${pool.name}
</c:forEach>
Some times items="${pools}" has an extra space or it acts like string, retyping it should solve the issue.

EL interprets ${class.name} as described - the name becomes getName() on the assumption you are using explicit or implicit methods of generating getter/setters
You can override this behavior by explicitly identifying the name as a function:
${class.name()} This calls the function name() directly without modification.

I get the same error on my JSP and the bad rated answer was correct
I had the folowing line:
<c:forEach var="agent" items=" ${userList}" varStatus="rowCounter">
and get the folowing error:
javax.el.PropertyNotFoundException: Property 'agent' not found on type
java.lang.String
deleting the space before ${userList} solved my problem
If some have the same problem, he will find quickly this post and does not waste 3 days in googeling to find help.

I was facing the similar type of issue:
Code Snippet :
<c:forEach items="${orderList}" var="xx">
${xx.id} <br>
</c:forEach>
There was a space after orderlist like this : "${orderList} "
because of which the xx variable was getting coverted into String and was not able to call xx.id.
So make sure about space. They play crucial role sometimes. :p

Related

Programatically Set Attribute with a Value Expression when component is within JSTL forEach loop

First time asking a question so please bear with me.
I have a pure Java custom component that extends UIInput (JSF 2.2, Mojarra) and I am using it like so:
<c:forEach items="#{bean.items}" var="item">
<my:component item="#{item}" />
</c:forEach>
I am trying to avoid unnecessarily specifying the 'value', 'valueChangeListener' and 'validator' attributes on the tag in the .xhtml file.
In my custom component I have overridden the setValueExpression method like so:
#Override
public void setValueExpression(String name, ValueExpression expression) {
super.setValueExpression(name, expression);
if ("item".equals(name)) {
this.setValue(Components.createValueExpression("#{item.myValue}", MyValue.class));
this.addValueChangeListener(new MethodExpressionValueChangeListener(Components.createVoidMethodExpression("#{item.myValueChanged}", ValueChangeEvent.class)));
this.addValidator(new MethodExpressionValidator(Components.createVoidMethodExpression("#{item.validateMyValue}", FacesContext.class, UIComponent.class, Object.class)));
}
}
I'm using OmniFaces there with its Components utility to reduce boilerplate code.
When it comes time to act on any of those three (validate on submit, for example) it results in:
javax.faces.FacesException: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'item' resolved to null
I am pretty sure I know why, I just don't know what to do about it.
I believe when it comes time for the three expressions I am trying to set programatically to be resolved it's trying to find a bean in some scope by the name, 'item' however that doesn't exist since 'item' was a point in time variable within a JSTL forEach loop.
I think there's a special deferred kind of expression that Weld is using for item itself (which I can kinda see when I debug that setValueExpression method) that is aware or otherwise has references to that point in time variable but I'm not doing the same thing when I set up those three expressions and therefore there's no handle to that later on when it comes time for them to be resolved.
I am sure there is a way to wire this together I'm just not seeing it.
Additionally, I know I could just put the three attributes on the tag in the .xhtml like this:
<my:component item="#{item}" value="#{item.myValue}" valueChangeListener="#{item.myValueChanged}" validator="#{item.validateMyValue}" />
Then they would get their special deferred expressions just like item itself does (and indeed everything works as expected this way) but I'd rather not - it's something I'd have to repeat a lot and it just seems like there should be a way to do what I am trying above.
I believe I found the answer.
What I kept seeing in the debugger kept nagging at me, I just wasn't sure how to wire up the same scenario manually, then I found a Stack Overflow post with the following code snip at the very bottom:
VariableMapper varMapper = new DefaultVariableMapper();
varMapper.setVariable(mappingName, component.getValueExpression(mappedAttributeName));
return new ValueExpressionImpl(expression, null, null, varMapper, expectedType);
That was enough to point me in the right direction of re-using the incoming value expression for item itself in a VariableMapper instance which is in turn used to create the three value/method expressions so they each now have a handle & can resolve 'item' later on, when it comes time:
#Override
public void setValueExpression(String name, ValueExpression expression) {
super.setValueExpression(name, expression);
if ("item".equals(name)) {
VariableMapper varMapper = new DefaultVariableMapper();
varMapper.setVariable("item", expression);
ValueExpressionImpl valExprImpl = new ValueExpressionImpl("#{item.myValue}", null, null, varMapper, MyValue.class);
super.setValueExpression("value", valExprImpl);
MethodExpressionImpl meExprImpl = new MethodExpressionImpl("#{item.myValueChanged}", null, null, varMapper, Void.class, new Class<?>[] {ValueChangeEvent.class});
MethodExpressionValueChangeListener mevcl = new MethodExpressionValueChangeListener(meExprImpl);
this.addValueChangeListener(mevcl);
meExprImpl = new MethodExpressionImpl("#{item.validateMyValue}", null, null, varMapper, Void.class, new Class<?>[] {FacesContext.class, UIComponent.class, Object.class});
MethodExpressionValidator mev = new MethodExpressionValidator(meExprImpl);
this.addValidator(mev);
}
}
That seems to have done the trick (and looks so simple now...).

Calling setter from JSF page which was declared with different parameter from variable itself

I'm using an External lib which has many classes with variables declared like that:
private String testBigDecimal;
public String getTestBigDecimal() {
return this.testBigDecimal;
}
public void setTestBigDecimal(BigDecimal testBigDecimal) {
this.testBigDecimal = BigDecimalValidador.validationXpto( testBigDecimal); //return String
}
Note that setter() method receives a BigDecimal value due to some validation process and return a String value. When those are called from server side everything is OK! ...but when called from view side (JSF page) with proper BigDecimalConverter I'm getting this Error:
javax.faces.component.UpdateModelException: javax.el.PropertyNotWritableException: ... Property [testBigDecimal] not writable on type ....
After Converter is correctly invoked, the code fails because it is still expecting for a setTestBigDecimal(Srting testBigDecimal) metohd.
My JSF Page: <h:inputText value="#{fooBean.testBigDecimal}" converter="bigDecimalConverter" />
Is there a way to ensure JSF can call the declared setter (which was in a "non standard way")?
In a local tests I changed 'String testBigDecimal' to 'BigDecimal testBigDecimal' type and everything works fine, but I can't change the Lib Source and Extend all this classes will be painful.
Anyone can help?

The class 'com.abank.pojo.MenuItem' does not have the property 'Menutext' [duplicate]

I have results from
Query query = session.createQuery("From Pool as p left join fetch p.poolQuestion as s");
query and I would like to display it on JSP.
I have loop:
<c:forEach items="${pools}" var="pool">
<p>${pool.name}</p>
</c:forEach>
and I would like to display results from poolQuestion table (which is Join table). The value that i want to display is 'answer'.
How can I do it?
<c:forEach items="${pools}" var="pool">
<p>${pool.answer}</p>
<p>${pool.name}</p>
</c:forEach>
The above code doesn't works.
The error is:
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/home.jsp at line 21
18: <c:forEach items="${pools}" var="pool">
19:
20: <p>${pool.name}</p>
21: <c:out value="${pool.poolQuestion.answer}"/>
22:
23: </c:forEach>
24:
SEVERE: Servlet.service() for servlet appServlet threw exception
javax.el.PropertyNotFoundException: Property 'answer' not found on type com.pool.app.domain.Pool
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:214)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:191)
at javax.el.BeanELResolver.property(BeanELResolver.java:300)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:81)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:938)
at org.apache.jsp.WEB_002dINF.views.home_jsp._jspx_meth_c_005fforEach_005f0(home_jsp.java:119)
at org.apache.jsp.WEB_002dINF.views.home_jsp._jspService(home_jsp.java:78)
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:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:574)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
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.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java: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:680)
The model is:
public List<Pool> getAll(){
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery("From Pool as p left join fetch p.poolQuestions as s");
return query.list();
The controller is:
List<Pool> pool = poolService.getAll();
model.addAttribute("pools", pool);
And the View is:
<c:forEach items="${pools}" var="pool">
<p>${pool.name}</p>
<c:out value="${pool.answer}"/>
</c:forEach>
PS. the ${pool.name} is displayed properly
javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean
This literally means that the mentioned class com.example.Bean doesn't have a public (non-static!) getter method for the mentioned property foo. Note that the field itself is irrelevant here!
The public getter method name must start with get, followed by the property name which is capitalized at only the first letter of the property name as in Foo.
public Foo getFoo() {
return foo;
}
You thus need to make sure that there is a getter method matching exactly the property name, and that the method is public (non-static) and that the method does not take any arguments and that it returns non-void. If you have one and it still doesn't work, then chances are that you were busy editing code forth and back without firmly cleaning the build, rebuilding the code and redeploying/restarting the application. You need to make sure that you have done so.
For boolean (not Boolean!) properties, the getter method name must start with is instead of get.
public boolean isFoo() {
return foo;
}
Regardless of the type, the presence of the foo field itself is thus not relevant. It can have a different name, or be completely absent, or even be static. All of below should still be accessible by ${bean.foo}.
public Foo getFoo() {
return bar;
}
public Foo getFoo() {
return new Foo("foo");
}
public Foo getFoo() {
return FOO_CONSTANT;
}
You see, the field is not what counts, but the getter method itself. Note that the property name itself should not be capitalized in EL. In other words, ${bean.Foo} won't ever work, it should be ${bean.foo}.
See also:
javax.el.PropertyNotFoundException: Property 'foo' not readable on type java.lang.Boolean
How does Java expression language resolve boolean attributes? (in JSF 1.2)
Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
Outcommented Facelets code still invokes EL expressions like #{bean.action()} and causes javax.el.PropertyNotFoundException on #{bean.action}
I believe the id accessors don't match the bean naming conventions and that's why the exception is thrown. They should be as follows:
public Integer getId() { return id; }
public void setId(Integer i){ id= i; }
Check the items in forEach
<c:forEach items="${pools}" var="pool">
${pool.name}
</c:forEach>
Some times items="${pools}" has an extra space or it acts like string, retyping it should solve the issue.
EL interprets ${class.name} as described - the name becomes getName() on the assumption you are using explicit or implicit methods of generating getter/setters
You can override this behavior by explicitly identifying the name as a function:
${class.name()} This calls the function name() directly without modification.
I get the same error on my JSP and the bad rated answer was correct
I had the folowing line:
<c:forEach var="agent" items=" ${userList}" varStatus="rowCounter">
and get the folowing error:
javax.el.PropertyNotFoundException: Property 'agent' not found on type
java.lang.String
deleting the space before ${userList} solved my problem
If some have the same problem, he will find quickly this post and does not waste 3 days in googeling to find help.
I was facing the similar type of issue:
Code Snippet :
<c:forEach items="${orderList}" var="xx">
${xx.id} <br>
</c:forEach>
There was a space after orderlist like this : "${orderList} "
because of which the xx variable was getting coverted into String and was not able to call xx.id.
So make sure about space. They play crucial role sometimes. :p

javax.el.PropertyNotFoundException: Property 'displayOrder' not found on type tn.ccs.evoice.entity.TicketSubject [duplicate]

I have results from
Query query = session.createQuery("From Pool as p left join fetch p.poolQuestion as s");
query and I would like to display it on JSP.
I have loop:
<c:forEach items="${pools}" var="pool">
<p>${pool.name}</p>
</c:forEach>
and I would like to display results from poolQuestion table (which is Join table). The value that i want to display is 'answer'.
How can I do it?
<c:forEach items="${pools}" var="pool">
<p>${pool.answer}</p>
<p>${pool.name}</p>
</c:forEach>
The above code doesn't works.
The error is:
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/home.jsp at line 21
18: <c:forEach items="${pools}" var="pool">
19:
20: <p>${pool.name}</p>
21: <c:out value="${pool.poolQuestion.answer}"/>
22:
23: </c:forEach>
24:
SEVERE: Servlet.service() for servlet appServlet threw exception
javax.el.PropertyNotFoundException: Property 'answer' not found on type com.pool.app.domain.Pool
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:214)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:191)
at javax.el.BeanELResolver.property(BeanELResolver.java:300)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:81)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:938)
at org.apache.jsp.WEB_002dINF.views.home_jsp._jspx_meth_c_005fforEach_005f0(home_jsp.java:119)
at org.apache.jsp.WEB_002dINF.views.home_jsp._jspService(home_jsp.java:78)
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:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:574)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
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.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java: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:680)
The model is:
public List<Pool> getAll(){
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery("From Pool as p left join fetch p.poolQuestions as s");
return query.list();
The controller is:
List<Pool> pool = poolService.getAll();
model.addAttribute("pools", pool);
And the View is:
<c:forEach items="${pools}" var="pool">
<p>${pool.name}</p>
<c:out value="${pool.answer}"/>
</c:forEach>
PS. the ${pool.name} is displayed properly
javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean
This literally means that the mentioned class com.example.Bean doesn't have a public (non-static!) getter method for the mentioned property foo. Note that the field itself is irrelevant here!
The public getter method name must start with get, followed by the property name which is capitalized at only the first letter of the property name as in Foo.
public Foo getFoo() {
return foo;
}
You thus need to make sure that there is a getter method matching exactly the property name, and that the method is public (non-static) and that the method does not take any arguments and that it returns non-void. If you have one and it still doesn't work, then chances are that you were busy editing code forth and back without firmly cleaning the build, rebuilding the code and redeploying/restarting the application. You need to make sure that you have done so.
For boolean (not Boolean!) properties, the getter method name must start with is instead of get.
public boolean isFoo() {
return foo;
}
Regardless of the type, the presence of the foo field itself is thus not relevant. It can have a different name, or be completely absent, or even be static. All of below should still be accessible by ${bean.foo}.
public Foo getFoo() {
return bar;
}
public Foo getFoo() {
return new Foo("foo");
}
public Foo getFoo() {
return FOO_CONSTANT;
}
You see, the field is not what counts, but the getter method itself. Note that the property name itself should not be capitalized in EL. In other words, ${bean.Foo} won't ever work, it should be ${bean.foo}.
See also:
javax.el.PropertyNotFoundException: Property 'foo' not readable on type java.lang.Boolean
How does Java expression language resolve boolean attributes? (in JSF 1.2)
Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
Outcommented Facelets code still invokes EL expressions like #{bean.action()} and causes javax.el.PropertyNotFoundException on #{bean.action}
I believe the id accessors don't match the bean naming conventions and that's why the exception is thrown. They should be as follows:
public Integer getId() { return id; }
public void setId(Integer i){ id= i; }
Check the items in forEach
<c:forEach items="${pools}" var="pool">
${pool.name}
</c:forEach>
Some times items="${pools}" has an extra space or it acts like string, retyping it should solve the issue.
EL interprets ${class.name} as described - the name becomes getName() on the assumption you are using explicit or implicit methods of generating getter/setters
You can override this behavior by explicitly identifying the name as a function:
${class.name()} This calls the function name() directly without modification.
I get the same error on my JSP and the bad rated answer was correct
I had the folowing line:
<c:forEach var="agent" items=" ${userList}" varStatus="rowCounter">
and get the folowing error:
javax.el.PropertyNotFoundException: Property 'agent' not found on type
java.lang.String
deleting the space before ${userList} solved my problem
If some have the same problem, he will find quickly this post and does not waste 3 days in googeling to find help.
I was facing the similar type of issue:
Code Snippet :
<c:forEach items="${orderList}" var="xx">
${xx.id} <br>
</c:forEach>
There was a space after orderlist like this : "${orderList} "
because of which the xx variable was getting coverted into String and was not able to call xx.id.
So make sure about space. They play crucial role sometimes. :p

Is it possible to debug for duplicate Ids?

I'm getting a duplicate id error but I can't figure out which element is meant.
java.lang.IllegalStateException: duplicate Id for a component pb_1_WAR_TEST_INSTANCE_1234_:_viewRoot:mainForm:tableOverview:j_id66
I know it has to be in tableOverview but the element with the ID:
j_id66 can not be found. When I search for it in my browser, I can only find elements with higher Id's like,
pb_1_WAR_TEST_INSTANCE_1234_:_viewRoot:mainForm:tableOverview:j_id67
Is there any way to find out which one is meant?
It's most likely a <h:column> or <rich:column>.
Quick way to find out the exact component is findComponent():
UIComponent component = context.getViewRoot().findComponent("pb_1_WAR_TEST_INSTANCE_1234_:_viewRoot:mainForm:tableOverview:j_id66");
System.out.println(component); // HtmlColumn?
Alternatively, just print out the JSF component tree. JSF 2.x offers <ui:debug> for this, in JSF 1.x you have to write custom code which traverses and prints UIViewRoot and all its children recursively. Here's a kickoff example:
public static void print(UIComponent component) {
System.out.println(component.getId() + " = " + component.getClass());
for (UIComponent child : component.getChildren()) {
print(child);
}
}
print(context.getViewRoot());
As to your concrete problem, it's most likely caused by binding a component to a bean which is not in the request scope. Don't do that.
See also:
How does the 'binding' attribute work in JSF? When and how should it be used?
Binding attribute causes duplicate component ID found in the view

Resources