0

I'm trying to create a menaged bean in my JSF application.

I'm not sure whether it is related to my problem but I use primefaces 4.0 and some themes of that. I added all jar files that I need with maven.

Primefaces uses managed beans for theme but it works well.

Here is my bean :

package Beans;

@ManagedBean
@SessionScoped
public class QueryBean implements Serializable {

    private String name;

    public QueryBean() {
        name = "Maozturk";
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

In XHTML file, I'm trying to use this bean like this :

<h:outputText value="#{queryBean.name}" />

Whatever I tried to access name variable, I couldn't, I tried @PostConstruct to give an initial value also I had the same problem.

Here is error that I got :

SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/RIA] threw exception [/index2.xhtml @296,48 value="#{queryBean.name}": Property 'name' not found on type Beans.QueryBean] with root cause javax.el.PropertyNotFoundException: Property 'name' not found on type Beans.QueryBean at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:229) at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:206) at javax.el.BeanELResolver.property(BeanELResolver.java:317) at javax.el.BeanELResolver.getValue(BeanELResolver.java:85) at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) at org.apache.el.parser.AstValue.getValue(AstValue.java:183) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185) 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:174) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) 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:889) at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:70) at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:57) at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:204) at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:121) at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:58) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863) at javax.faces.render.Renderer.encodeChildren(Renderer.java:176) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:70) at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:57) at org.primefaces.component.dialog.DialogRenderer.encodeContent(DialogRenderer.java:184) at org.primefaces.component.dialog.DialogRenderer.encodeMarkup(DialogRenderer.java:113) at org.primefaces.component.dialog.DialogRenderer.encodeEnd(DialogRenderer.java:47) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:461) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

Here is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>RIA</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>bluesky</param-value>
</context-param>
</web-app>
Maozturk
  • 324
  • 1
  • 4
  • 18
  • 2
    Where does `Beans.QueryBean` comes from? Have you other (inner) class which is named `QueryBean`? – LaurentG Feb 17 '14 at 14:02
  • I have only one QueryBean class in entire project, there is no inner class which is named QueryBean. – Maozturk Feb 17 '14 at 14:06
  • That could also be a class in an external library (maybe the automatic import went wrong). – LaurentG Feb 17 '14 at 14:29
  • Is it your bean under the namespace `Beans`? BTW, the use of upper cases is discouraged for package names. Apart from that, if you're running an embedded server in an IDE, just check the IDE has updated the content in the server deployment path. – Xtreme Biker Feb 17 '14 at 14:36
  • @LaurentG, I tried to give another name for my bean, it worked but I still couldn't get value of variable. – Maozturk Feb 17 '14 at 14:51
  • @XtremeBiker What do you mean namespace? I just created new package for beans. Okay, I will change the name of packages. – Maozturk Feb 17 '14 at 14:52
  • I mean, your bean is really in `beans` package or not. You've got two possible problems, either JSF not locating your proper bean or your server content not being correctly updated. – Xtreme Biker Feb 17 '14 at 14:53
  • Yes they are, I also checked location of my server (tomcat) whether beans are in there or not, QueryBean is in WEB-INF/classes. – Maozturk Feb 17 '14 at 14:59
  • My suggestion is to check any exceptions are being thrown by your application because primefaces swallows this exception and throwing property not found exception. This is what I observed this mostly happens when any exception occurs in action or actionListener. This may not exactly suits your case but I felt it is good to make you aware. – Srikanth Ganji Feb 17 '14 at 15:30
  • 2
    Isolate the problem first: create a new blank xhtml page with an empty `` and in your `` have this line only: `#{queryBean.name}`. That should work. If not, then you're using something else that you're not posting in the question at all. – Luiggi Mendoza Feb 17 '14 at 15:36
  • @LuiggiMendoza, I tried to create a new xHTML file which has only one line, h:outputLabel, but it still didn't work, what information do you need? What is your suggestion? – Maozturk Feb 17 '14 at 15:44
  • Are you by any mean using Spring in your project as well? Could you post the packages you're importing for both ``@ManagedBean and `@SessionScoped`? Can you post the definition of the Faces Servlet in your web.xml file along with the URL you're using to access to this new blank view? – Luiggi Mendoza Feb 17 '14 at 15:47
  • I edited my post to add web.xml, faces-config.xml is almost empty, I didn't add managed bean in faces-config, as you see I added them with annotations. I don't use Spring, I have another package which is named example and has beans, but I'm planning to delete it, I will move them to the bean package. They are beans that primefaces needs. URL that I use is localhost:8082/faces/index.xhtml Everything seems okay, where did I make mistake? – Maozturk Feb 17 '14 at 16:00
  • Possible duplicate of [Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable](https://stackoverflow.com/questions/30128395/identifying-and-solving-javax-el-propertynotfoundexception-target-unreachable) – Kukeltje Jan 16 '18 at 19:00

0 Answers0