I am creating a web page that get an id from a previous page using getSessionMap() in FacesUtils. If the page did not get the id, it should be redirected to other page, in this case draft.jsf. Here is the code:
if ((FacesUtils.getSessionMap().get("id") == null)) {
try {
FacesUtils.getResponse().sendRedirect("draft.jsf");
return;
} catch (Exception e) {
e.printStackTrace();
}
} else {
id = Long.valueOf(String.valueOf(FacesUtils.getSessionMap().get("id")));
}
But I always get java.lang.IllegalStateException: Committed when the id was null, and the page was not redirected to draft.jsf. What is wrong with my code? Any help would be really appreciated.
Here is the stacktrace:
java.lang.IllegalStateException: Committed
at org.mortbay.jetty.Response.resetBuffer(Response.java:1023)
at org.mortbay.jetty.Response.sendRedirect(Response.java:428)
at org.jleaf.erp.inv.controller.EditAssemblyController.init(EditAssemblyController.java:58)
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.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:340)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:293)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:130)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:393)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1415)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:331)
at org.jlego.web.jsf.ViewScope.get(ViewScope.java:20)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:327)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
at org.jlego.baseweb.PieceletELResolver.getValue(PieceletELResolver.java:65)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:99)
at com.sun.el.parser.AstValue.getValue(AstValue.java:158)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
at org.primefaces.util.ComponentUtils.getValueToRender(ComponentUtils.java:69)
at org.primefaces.component.inputtext.InputTextRenderer.encodeMarkup(InputTextRenderer.java:79)
at org.primefaces.component.inputtext.InputTextRenderer.encodeEnd(InputTextRenderer.java:50)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:55)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43)
at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:191)
at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:114)
at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:55)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
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:594)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)
at org.jlego.web.WebLoginSessionFilter.doFilter(WebLoginSessionFilter.java:95)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
It's likely because you're redirecting by plain servlet HttpServletResponse#sendRedirect() instead of JSF own ExternalContext#redirect() which is implicitly performing a FacesContext#responseComplete() call afterwards which instructs JSF to not perform the render response which would fill the HTTP response with the output of the target view.
E.g.
public void someMethod() throws IOException {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
Long id = (Long) ec.getSessionMap().get("id");
if (id == null) {
ec.redirect("draft.jsf");
return;
}
// ... ?
}
(note that I simplified some clumsiness (massaging long<-->string) and carelessness (swallowing exception) in your code as well; using #ManagedProperty("#{id}") to inject the property is after all probably yet easier)
Whenever you import something from javax.servlet inside a JSF artifact, you should stop developing and look around in ExternalContext class and think twice if you're really doing things the right way. Further, JSF utility library OmniFaces has a handy Faces utility class, removing the need to reinvent the FacesUtils wheel.
Update: Given the stack trace, another probable cause is that you're attempting to send a redirect in midst of rendering the response. It's not possible to take the already sent bytes of the rendered response back from the client in order to change the response. You should be performing the redirect job before the first byte of the response is ever sent to the client. E.g. in a pre render view listener method instead of bean's (post)constructor or even getter method.
<f:event type="preRenderView" listener="#{bean.someMethod}" />
I ran into this problem before where somewhere else in my code there was a redirect being sent within the same request.
Double check that you don't have any filters trying to do a redirect as well.
Related
I have the following:
public class EnvWebEndpointExtensionEnvironmentPostProcessorTests {
#Rule
public ExpectedException thrown = ExpectedException.none();
#Rule
public MockitoRule rule = MockitoJUnit.rule();
final EnvWebEndpointExtensionEnvironmentPostProcessor postProcessor = new EnvWebEndpointExtensionEnvironmentPostProcessor();
#Mock
ConfigurableEnvironment environmentMock;
#Mock
MutablePropertySources propertySourcesMock;
#Test
public void shouldAddPropertySource() {
final MutablePropertySources propertySources = new MutablePropertySources();
doReturn(propertySources) // line 40
.when(environmentMock).getPropertySources();
postProcessor.postProcessEnvironment(environmentMock, null);
assertNotNull(propertySources.get("actuators-defaults"));
}
#Test
public void shouldThrowExceptionOnFailingToAddLaptopPropertySource() {
thrown.expect(RuntimeException.class);
final MutablePropertySources propertySourcesReal = new MutablePropertySources();
doReturn(propertySourcesReal)
.when(environmentMock).getPropertySources();
doReturn(true)
.when(environmentMock).acceptsProfiles("laptop");
doReturn(propertySourcesMock)
.when(environmentMock).getPropertySources();
doThrow(IOException.class) // line 61
.when(propertySourcesMock).addBefore("actuators-defaults", any(ResourcePropertySource.class));
postProcessor.postProcessEnvironment(environmentMock, null);
}
}
When the tests are run individually, they pass but when they're both run, shouldAddPropertySource fails with:
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at com.netflix.springboot.actuators.EnvWebEndpointExtensionEnvironmentPostProcessorTests.shouldThrowExceptionOnFailingToAddLaptopPropertySource(EnvWebEndpointExtensionEnvironmentPostProcessorTests.java:61)
E.g. thenReturn() may be missing.
Examples of correct stubbing:
when(mock.isOk()).thenReturn(true);
when(mock.isOk()).thenThrow(exception);
doThrow(exception).when(mock).someVoidMethod();
Hints:
1. missing thenReturn()
2. you are trying to stub a final method, which is not supported
3: you are stubbing the behaviour of another mock inside before 'thenReturn' instruction if completed
at com.netflix.springboot.actuators.EnvWebEndpointExtensionEnvironmentPostProcessorTests.shouldAddPropertySource(EnvWebEndpointExtensionEnvironmentPostProcessorTests.java:40)
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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.mockito.internal.junit.JUnitRule$1.evaluateSafely(JUnitRule.java:52)
at org.mockito.internal.junit.JUnitRule$1.evaluate(JUnitRule.java:43)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Considering the information I've found and the behavior above, Mockito is storing some static state but the level of my understanding isn't deep enough to figure out a fix for the above. What's the right fix and, in addition, the explanation for the fix?
If you use a matcher as an argument of a stubbed method call, all arguments must be matchers. So you need to replace "actuators-defaults" by eq("actuators-defaults").
I'm not sure why that throws that exception, though.
JB Nizet correctly diagnosed the root cause in his answer: When you use matchers for one argument, you have to use matchers for all arguments.
My hunch is that Mockito is correctly throwing InvalidUseOfMatchersException, which descends from RuntimeException, so your test erroneously passes without exercising your system-under-test. This is an important reason not to catch RuntimeException indiscriminately, especially at the top of a test method. This may also be a reason to use assertThrows or a try { methodUnderTest(); fail(); } catch (YourSpecificException expected) {} idiom.
If that's the case, you're seeing that specific exception because your test runner is calling your tests in shouldThrow, shouldAdd order in the same VM and Mockito keeps its matcher state in a static ThreadLocal that may survive between tests. If that theory is correct, then the InvalidUseOfMatchersException happens before Mockito can store the expectation from line 61, leaving the stubbing on line 61 technically unfinished. Because Mockito doesn't know when one test ends and another begins, it can't reset its state, so Mockito can only detect this case the next time you interact with Mockito (on line 40).
You could improve your experience by calling Mockito.validateMockitoUsage() in an #After method (or by using MockitoRule or MockitoJUnitRunner).
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
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
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
Referring to Question:
Unable to get document page name for
I have tried the solution given by Sven, but we still getting same error.
Applications are access via browsers only.
12/14/15 2:30 PM: Exception Thrown
Context Path: /db/common/itrs.nsf
com.ibm.xsp.FacesExceptionEx: Unable to get document page name for C8AF761CF554445D48257CC90007D9AD
at com.ibm.xsp.model.domino.DominoDocumentPageTransformer.transformPageName(DominoDocumentPageTransformer.java:69)
at com.ibm.xsp.application.ViewHandlerExImpl.convertVirtualPage(ViewHandlerExImpl.java:690)
at com.ibm.xsp.application.ViewHandlerExImpl._createViewRoot(ViewHandlerExImpl.java:490)
at com.ibm.xsp.application.ViewHandlerExImpl.createViewRoot(ViewHandlerExImpl.java:567)
at com.ibm.xsp.application.ViewHandlerExImpl.doCreateView(ViewHandlerExImpl.java:142)
at com.ibm.xsp.application.ViewHandlerEx.createView(ViewHandlerEx.java:90)
at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:251)
at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157)
at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:853)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1319)
at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662)
at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:357)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:313)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
Caused by: com.ibm.xsp.FacesExceptionEx: Error while computing document form
at com.ibm.xsp.model.domino.DominoUtils.getXPagesForDocument(DominoUtils.java:603)
at com.ibm.xsp.model.domino.DominoDocumentPageTransformer.transformPageName(DominoDocumentPageTransformer.java:53)
... 21 more
Caused by: com.ibm.designer.domino.napi.NotesAPIException: Error finding special ID, Database=700 Special database object cannot be located
at com.ibm.designer.domino.napi.NotesDatabase.NGetSpecialNoteID(Native Method)
at com.ibm.designer.domino.napi.NotesDatabase.getSpecialNoteID(NotesDatabase.java:600)
at com.ibm.xsp.model.domino.DominoUtils.getXPagesForDocument(DominoUtils.java:540)
... 22 more
Thank you in anticipation.
The DominoDocumentPageTransformer doesn't fetch some errors, e.g. if the document does not exist or is not readable for the current user. Because the transformation happens during the page convertion (the XPages engine tries to interpret the URL and seeks for the XPage to open), you receive an error.
As far as I know you can overwrite the existing PageTransformer and catch the error for yourself.
package ch.hasselba.factory;
import com.ibm.xsp.model.domino.DominoDocumentPageTransformer;
import com.ibm.xsp.page.VirtualPageTransformer;
import javax.faces.context.FacesContext;
public class PageTransformer implements VirtualPageTransformer {
public boolean isVirtualPage(FacesContext fc, String pageName) {
return "/$$OpenDominoDocument.xsp".equals(pageName);
}
public String transformPageName(FacesContext fc, String pageName) {
String xspPage = "/ErrorPage.xsp";
try {
DominoDocumentPageTransformer transformer = new DominoDocumentPageTransformer();
xspPage = transformer.transformPageName(fc, pageName);
} catch (Exception e) {}
return xspPage;
}
}
This opens the XPages ErrorPage.xsp when the transformation fails.
To activate the Transformer, you have to create the file
/WEB_INF/com.ibm.xsp.factories.properties
and add the line
PageTransformer=ch.hasselba.factory.PageTransformer
see here: http://hasselba.ch/blog/?p=1028
I know that you've probably solved the problem you had by now! But I've had the same issue and was hunting around trying to find the solution, so wanted to add my findings to this thread.
The reason I saw this error was because users were trying to open a document from a doc link within an email and there was no default form specified in that database.