palAlaa
palAlaa

Reputation: 9858

Bean setProperty

Hello everybody :) I have misunderstanging in setPropety in using Bean ? when I make like this

 <jsp:setProperty name="myBean" property="*">

I have to make the field names of the form the same as attribute names in myBean in order to make match between values is HTTPRequest and the attributes of myBean, if I use onther names in the form fields, values are reached null values. but If I ever want to use the form values in the same jsp page , and define Bean that holds the values of the form, it doesn't make sence if I use other names in the form fields rather than the same name of bean attributes !! why is that ??

see here, the name of password field is "password" , and the name of attribute of myBean is pass, and even that it works !

//index.jsp page
<form method="post" action="index.jsp">
        Enter Your email:<input type="text" name="email"/>
        <br/>
        Enter Your Password :<input type="password" name ="pass">
         <br/>
        <input type="submit" name ="submit"/>
    </form>

    <jsp:useBean id="info" class="beans.info" scope="page">
        <jsp:setProperty name="info" property="*"/>
    </jsp:useBean>
        Your email is : <jsp:getProperty name="info" property="email"/>
          <br/>
         Your Pass is : <jsp:getProperty name="info" property="pass"/>
</body>

can some one tell me what has happened?

Edit: I make modification to the code.

Upvotes: 0

Views: 4140

Answers (2)

Mohammed Joraid
Mohammed Joraid

Reputation: 6480

I faced the same problem as you, and I just made this example and it works!

HTML page

<form name="registrationForm" id="registrationForm" method="post" action="registerBean.jsp" >
Full Name:* 
<input type="text" name="fullname" id="fullname"/> 
  </form>

registerBean.jsp

<jsp:useBean id="userBean" scope="session" class="Code.UserBean" />
<jsp:setProperty name="userBean" property="fullName" param="fullname" />

Focus on (param="") attribute, because it's the one that will make the matching between the html form field name on one hand and javabean on the other hand.


UserBean.java

    public class UserBean
    {
        private String fullName;
 /**
     * @return the fullName
     */
    public String getFullName()
    {
        return fullName;
    }

    /**
     * @param fullName the fullName to set
     */
    public void setFullName(String fullName)
    {
        this.fullName = fullName;
    }
}

Upvotes: 0

BalusC
BalusC

Reputation: 1108722

<input type="password" name ="pass">

The name of your password field is also pass.

Other cause could be that you aren't running the code you think you're running. Note that the bean name infoo is wrong.

Upvotes: 1

Related Questions