0

I am new to Java... I made this application, but the problem is that when I run the project I am getting the text which i have written in h tag's value attribute instead of the value from the bean. I have searched a lot but the problem is still there. The code and the screenshot tells the rest of the story. Here is my login.jsp:

    </head>

    <body>
    <f:view>
        <div class="login_container">
            <h:messages errorClass="errorMsg"/>
            <div class="login_box">
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            <div class="login_wrap">
                                <div class="login_logo">
                                    <img src="images/login_logo.gif" width="116" height="141" />
                                </div>
                                <h:form id="login_form">
                                    <div class="login_form">
                                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td>
                                        <div style="float: left;">
                                            <h2 class="orange">
                                                Please Login
                                            </h2>
                                        </div>
                                        <div class="login_icon">
                                            <img src="images/icn_lock.png" width="16" height="16" />
                                        </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <label>
                                                        Username
                                                    </label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><h:inputText id="username" value="#{loginBean.username}" /></td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <label>
                                                        Password
                                                    </label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><h:inputText id="password" value="#{loginBean.password}"/>

                                                </td>
                                            </tr>
                                            <tr>
                                                <td>&nbsp;

                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="left" valign="middle">

                                                        <h:commandButton image="images/btn_login.gif" id="loginButton" action="#{loginBean.login}"
                                                            style="width:81px; height:29px" />

                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </h:form>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div class="login_box_bt">
                                &nbsp;
                            </div>
                        </td>
                    </tr>
                </table>
            </div>


            <div class="login_footer_box">
            <div class="login_footer">
                <div class="login_footer_text">
                    <p>

            <span class="text_orange">Phone:</span> (+92-51) 5120684
                        <br />
                        <span class="text_orange">E-mail:</span> support@noeticworld.com
                            <br />
                        <span class="text_orange">Web:</span> http://www.noeticworld.com.pk


            </p></div>
                <div class="login_footer1_text">
                    <p>
                        <span class="text_orange">Leading VAS Solution Provider
            </span>
                        <% /**<span class="text_orange">Fax:</span> (+92-51) 260 9263*/ %>
                        <br />
                    </p></div>
                </div>
                </div>
                <div class="login_box_bt">
                                &nbsp;

                            </div>





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

here is my backingbeans :

public class LoginBackingBean
{

    private String username;
    private String password;
    private Boolean rememberMe;


    public String getUsername()
    {
        return username;
    }

    public void setUsername(String username)
    {
        this.username = username;
    }

    public String getPassword()
    {
        return password;
    }

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

    public Boolean getRememberMe()
    {
        return rememberMe;
    }

    public void setRememberMe(Boolean rememberMe)
    {
        this.rememberMe = rememberMe;
    }

    public String login()
    {
        boolean isValidUser = true;
        String message = "";

        Employee employee = null;

        try
        {
            employee = getCurrentEmployee();

            if (employee == null)
            {
                isValidUser = false;
                message = "Sorry, the username or password is incorrect. Please try again";
            }

        }
        catch (SQLException e)
        {
            isValidUser = false;
            message = e.getMessage();
            e.printStackTrace();
        }

        if (!isValidUser)
        {
            FacesMessage facesMessage = new FacesMessage();
            facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
            facesMessage.setSummary(message);
            FacesContext.getCurrentInstance().addMessage("login_form", facesMessage);
            return "failure";
        }

        EmployeeBackingBean employeeBackingBean = EmployeeBackingBean.getEmployeeBackingBean(employee);

        List<Integer> recursiveSubordinatesIds;
        try
        {
            recursiveSubordinatesIds = new EmployeeDAOImpl(DigiDeskDAO.getSqlMapper()).selectIdsOfRecursiveSubordinates(employeeBackingBean.getEmployeeId());
            employeeBackingBean.setRecursiveSubordinatesIds(recursiveSubordinatesIds);
        }
        catch (SQLException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        SessionManager.setEmployeeInSession(employeeBackingBean);

        return "success";
    }

    /**
     * This function finds the employee with the provided username and password
     * 
     * @return - Employee object if validation succeeds, null if no matching user is found
     * @throws SQLException
     */
    private Employee getCurrentEmployee() throws SQLException
    {
        EmployeeDAOImpl employeeDAOImpl = new EmployeeDAOImpl(DigiDeskDAO.getSqlMapper());
        EmployeeExample employeeExample = new EmployeeExample();
        EmployeeExample.Criteria criteria = employeeExample.createCriteria();

        criteria.andUsernameEqualTo(username);
        criteria.andPasswordEqualTo(password);

        List<Employee> employeesList = employeeDAOImpl.selectByExampleWithBLOBs(employeeExample);

        if (employeesList.isEmpty())
        {
            return null;
        }

        Employee employee = employeesList.get(0);

        return employee;

    }

}

This is the problem, username and password shows the text:

enter image description here

Jason C
  • 38,729
  • 14
  • 126
  • 182
Raja
  • 11
  • 1
  • You appear to be using (or attempting to use) JSF. Are you sure you [have it set up properly](https://www.tutorialspoint.com/jsf/jsf_overview.htm)? Because it looks like it isn't configured and enabled, and so your `value` attributes are being used as-is and not replaced. You might be biting off more than you can chew right now jumping straight into JSF -- I mean that constructively, perhaps you might have less things to learn at once if you start with vanilla JSP stuff first? – Jason C Oct 27 '16 at 06:07
  • Also can you add the full page source? Your `` is missing. – Jason C Oct 27 '16 at 06:10
  • In JSP, the EL langage is use with $ not # (JSF) – AxelH Oct 27 '16 at 08:27
  • Thanks for getting in touch. Replacing # with $ does not make any change. let me tell you the environment i'm using...i'm using eclipse(neon) with tomcat6. According to me there are some compatibility issues rather than code. Still, if you require more insight of the code do let me know. – Raja Oct 27 '16 at 10:32

1 Answers1

0

Try to replace #{~~} with ${~~}

Al.T.Os
  • 72
  • 9
  • :( not working it says "According to TLD or attribute directive in tag file, attribute value does not accept any expressions" – Raja Oct 27 '16 at 12:54
  • @Raja It seems that finding out why value="#{loginBean.username}" appears literally in the inputText is our first problem to solve. – Al.T.Os Oct 28 '16 at 05:11