Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF 2 managed bean does not get instantiated
    text
    copied!<p>I am having this problem in this sample jsf project I created. Managed beans do not get instantiated. Bean class:</p> <pre><code>@ManagedBean(name="loginMB") @RequestScoped public class LoginMB extends AbstractMB { private static final long serialVersionUID = -8523135776442886000L; @ManagedProperty("#{userMB}") private UserMB userMB; //getters and setters public String login() { UserSupport userSupport = new UserSupportImpl(); User user = userSupport.isValidLogin(email, password); if (user != null) { getUserMB().setUser(user); FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) context .getExternalContext().getRequest(); request.getSession().setAttribute("user", user); return "loggedIn"; //return "/pages/protected/index.xhtml"; } displayErrorMessageToUser("Check your email/password"); return null; } } </code></pre> <p>ManagedBean annotation and RequestScope annotation have been imported from </p> <blockquote> <p>import javax.faces.bean.*; </p> </blockquote> <p>this is how i ve used above bean,</p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"&gt; &lt;h:head&gt; &lt;/h:head&gt; &lt;h:body&gt; &lt;p&gt;#{bundle.loginHello}&lt;/p&gt; &lt;h:form&gt; &lt;p:growl showDetail="false" life="3000" /&gt; &lt;h:panelGrid columns="2"&gt; &lt;h:outputLabel value="#{bundle.loginUserName}" /&gt; &lt;h:inputText value="#{loginMB.email}" label="Email" id="email" required="true"&gt; &lt;f:validateLength minimum="6" /&gt; &lt;/h:inputText&gt; &lt;h:outputLabel value="#{bundle.loginPassword}" /&gt; &lt;h:inputSecret value="#{loginMB.password}" label="Password" id="senha" required="true" autocomplete="off" &gt; &lt;f:validateLength minimum="6" /&gt; &lt;/h:inputSecret&gt; &lt;/h:panelGrid&gt; &lt;p:commandButton action="#{loginMB.login}" value="Log in" ajax="false" /&gt; &lt;/h:form&gt; &lt;/h:body&gt; &lt;/html&gt; </code></pre> <p>Other managed bean</p> <pre><code>@SessionScoped @ManagedBean(name = "userMB") public class UserMB implements Serializable { public static final String INJECTION_NAME = "#{userMB}"; private static final long serialVersionUID = 1L; private User user; ....... } </code></pre> <p>Exception:</p> <pre><code>javax.el.PropertyNotFoundException: /login.xhtml @14,83 value="#{loginMB.email}": Target Unreachable, identifier 'loginMB' resolved to null at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95) </code></pre> <p>faces-config.xml</p> <pre><code>&lt;faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd" version="2.1"&gt; &lt;application&gt; &lt;resource-bundle&gt; &lt;base-name&gt;messages&lt;/base-name&gt; &lt;var&gt;bundle&lt;/var&gt; &lt;/resource-bundle&gt; &lt;message-bundle&gt;messages&lt;/message-bundle&gt; &lt;/application&gt; &lt;navigation-rule&gt; &lt;from-view-id&gt;/login.xhtml&lt;/from-view-id&gt; &lt;navigation-case&gt; &lt;from-action&gt;#{loginMB.login}&lt;/from-action&gt; &lt;from-outcome&gt;loggedIn&lt;/from-outcome&gt; &lt;to-view-id&gt;/index.xhtml&lt;/to-view-id&gt; &lt;redirect /&gt; &lt;/navigation-case&gt; &lt;/navigation-rule&gt; &lt;!-- &lt;managed-bean&gt; &lt;managed-bean-name&gt;loginMB&lt;/managed-bean-name&gt; &lt;managed-bean-class&gt; com.sample.jsfjpa.beans.LoginMB&lt;/managed-bean-class&gt; &lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt; &lt;/managed-bean&gt; &lt;managed-bean&gt; &lt;managed-bean-name&gt;userMB&lt;/managed-bean-name&gt; &lt;managed-bean-class&gt; com.sample.jsfjpa.beans.UserMB&lt;/managed-bean-class&gt; &lt;managed-bean-scope&gt;session&lt;/managed-bean-scope&gt; &lt;/managed-bean&gt; --&gt; &lt;/faces-config&gt; </code></pre> <p><img src="https://i.stack.imgur.com/wlw1M.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload