facebook

Issue with MyEclipse Demo: "Using JSF for Web Applications"

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #393887 Reply

    Mork
    Participant

    I worked through the “Using JSF for Web Applications” demo, which seems quite good, but when I try to use the form by clicking the command button, I get:

    An Error Occurred:

    /userLogin.jsp(34,6) ‘#{UserBean.userName}’ Target Unreachable, identifier ‘UserBean’ resolved to null

    —-

    Here are my files. I don’t see the issue after having looked at it a while.

    Do you see why I get the error above?

    MessageBundle.properties:
    user_name_label=User Name\:
    user_password_label=Password\:
    login_button_label=Login


    UserBean.java:

    package net.jsfdemo.bean;

    public final class UserBean
    {
    private String password;
    private String userName;

    public UserBean() {
    super();
    // TODO Auto-generated constructor stub
    }

    /**
    * @return Returns the password.
    */

    public String getPassword() {
    return password;
    }

    /**
    * @param password The password to set.
    */

    public void setPassword(String password) {
    this.password = password;
    }

    /**
    * @return Returns the userName.
    */

    public String getUserName() {
    return userName;
    }

    /**
    * @param userName The userName to set.
    */

    public void setUserName(String userName) {
    this.userName = userName;
    }

    public String loginUser() {
    if(“myeclipse”.equals(getUserName()) && “myeclipse”.equals(getPassword()))
    return “success”;
    return “failure”;
    }
    }

    ————-
    faces-config.xml:

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <faces-config
    xmlns=”http://xmlns.jcp.org/xml/ns/javaee&#8221;
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
    xsi:schemaLocation=”http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd&#8221;
    version=”2.2″>
    <managed-bean>
    <managed-bean-name>userBean</managed-bean-name>
    <managed-bean-class>net.jsfdemo.bean.UserBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
    <property-name>password</property-name>
    <property-class>java.lang.String</property-class>
    <value></value>
    </managed-property>
    <managed-property>
    <property-name>userName</property-name>
    <property-class>java.lang.String</property-class>
    <value></value>
    </managed-property>
    </managed-bean>
    <navigation-rule>
    <display-name>userLogin</display-name>
    <from-view-id>/userLogin.jsp</from-view-id>
    <navigation-case>
    <from-outcome>success</from-outcome>
    <to-view-id>/userLoginSuccess.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>
    <navigation-rule>
    <display-name>userLogin</display-name>
    <from-view-id>/userLogin.jsp</from-view-id>
    <navigation-case>
    <from-outcome>failure</from-outcome>
    <to-view-id>/userLogin.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>

    </faces-config>

    ————–

    userLogin.jsp:

    <%@taglib uri=”http://java.sun.com/jsf/core&#8221; prefix=”f”%><%@taglib
    uri=”http://java.sun.com/jsf/html&#8221; prefix=”h”%><%@ page language=”java” import=”java.util.*” pageEncoding=”US-ASCII”%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
    %>

    <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
    <html>
    <head>
    <base href=”<%=basePath%>”>

    <title>My JSP ‘userLogin.jsp’ starting page</title>

    <meta http-equiv=”pragma” content=”no-cache”>
    <meta http-equiv=”cache-control” content=”no-cache”>
    <meta http-equiv=”expires” content=”0″>
    <meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″>
    <meta http-equiv=”description” content=”This is my page”>
    <!–
    <link rel=”stylesheet” type=”text/css” href=”styles.css”>
    –>

    </head>

    <body style=”height: 212px; “>

    <f:view>
    <f:loadBundle basename=”net.jsfdemo.MessageBundle” var=”bundle”/><br>

    <h:form id=”loginForm” style=”height: 117px; “>

    <h:outputLabel value=”#{bundle.user_name_label}” for=”userName”>
    <h:inputText id=”userName” value=”#{UserBean.userName}” required=”true”></h:inputText>
    </h:outputLabel>

    <br>
    <h:outputLabel value=”#{bundle.user_password_label}” for=”password”>
    <h:inputSecret id=”password” value=”#{UserBean.password}” required=”true” />
    </h:outputLabel>
    <br><h:commandButton value=”#{bundle.login_button_label}” action=”#UserBean.loginUser}”></h:commandButton>

    </h:form>
    </f:view>
    </body>
    </html>

    ——————-

    userLoginSuccess.jsp:

    <%@taglib uri=”http://java.sun.com/jsf/core&#8221; prefix=”f”%><%@taglib
    uri=”http://java.sun.com/jsf/html&#8221; prefix=”h”%><%@ page language=”java” import=”java.util.*” pageEncoding=”US-ASCII”%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
    %>

    <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
    <html>
    <head>
    <base href=”<%=basePath%>”>

    <title>My JSP ‘userLoginSuccess.jsp’ starting page</title>

    <meta http-equiv=”pragma” content=”no-cache”>
    <meta http-equiv=”cache-control” content=”no-cache”>
    <meta http-equiv=”expires” content=”0″>
    <meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″>
    <meta http-equiv=”description” content=”This is my page”>
    <!–
    <link rel=”stylesheet” type=”text/css” href=”styles.css”>
    –>

    </head>

    <body>
    <f:view>Hello <h:outputText value=”#{UserBean.userName}”></h:outputText>, you successfully logged in.</f:view>
    <br>
    </body>
    </html>

    Attachments:
    You must be logged in to view attached files.
    #393923

    support-swapna
    Moderator

    Jim,

    Sorry that you are seeing this issue.

    In the faces-config.xml, the managed bean name should be capitalized.

    Replace the below line
    <managed-bean-name>userBean</managed-bean-name>

    with :
    <managed-bean-name>UserBean</managed-bean-name>

    Redeploy the project and check if it fixes the issue.

    The New Managed Bean wizard by default populates the Name with ‘userName’ and you should change it to ‘UserName’ which is already mentioned in the tutorial (3.Create Managed Beans section, point no 5 : Capitalize the default name – UserBean.). We will take a look if we can modify the wizard to populate the capitalized bean name instead of correcting it manually.

    Let us know how it works for you.

    –Swapna
    MyEclipse Support

    #393924

    Mork
    Participant

    Thanks, Yes, that fixed an issue and let me discover another I’m working on now. 🙂

    Would it be possible, as you suggested, to have the wizard generate code that doesn’t need to be manually changed?

    Since the tutorial was so long, I missed that step and spent a couple hours trying to figure out what was going on.

    Thanks,

    – m

    #393926

    support-swapna
    Moderator

    Jim,

    Glad that it worked. I have raised a PR for the dev team to check if we can make the changes on the wizard level to fix this issue.

    Sorry for inconvenience caused.

    Let us know if you see any issues.

    –Swapna
    MyEclipse Support

    #393930

    Mork
    Participant

    Thanks. Should be an easy fix and was probably just an oversight when you coded the wizard.

    Thanks very much for your support! 🙂

    – m

    #394006

    support-swapna
    Moderator

    Jim,

    Apologies for the confusion. The issue with the bean name is not a bug with MyEclipse wizard.
    The wizard correctly populates the bean name as ‘userBean’. I assume you have copy pasted the code just like I did when following the tutorial and in the tutorial since the bean name is ‘UserBean’ in the userLogin.jsp and userLoginSuccess.jsp, the error occurred at runtime.

    To summarize, the wizard is correct and you can give any name for bean name but make sure that the same name is used in all the declarations.
    In JSF 2.0 and higher, managed beans can be configured using the @ManagedBean annotation in the Java class, rather than in the faces-config.xml file.

    Let us know if you have any questions.

    –Swapna
    MyEclipse Support

    #394007

    Mork
    Participant

    Thanks very much for the follow up. 🙂

    Appreciate your help on this.

    – m

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: Issue with MyEclipse Demo: "Using JSF for Web Applications"

This topic is marked as closed to new replies, however your posting capabilities still allow you to do so.

You must be logged in to post in the forum log in