Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Page Bean not setting text property

 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to use a session bean to set the values from two textboxs. The first jsp has the following 2 lines of code at the beginning:
<jsp:useBean id="user" class="com.beans.UserData" scope="session" />
<jsp:setProperty name="user" property="*" />

For some reason the second jsp will not pick up the value of the textbox.
The second jsp has the following two lines of code at the beginning:
<jsp:useBean id="user" class="com.beans.UserData" scope="session" />
<%= user.getUserid() %>

You would think it could be a syntax or other error, but if I am to explicitly set the property value in the first jsp (ex. value="123"), the bean property is successfully populated and the value 123 is displayed in the second jsp. This also rules out the possibility of a configuration issue with Tomcat. Any ideas?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mention "the textbox", but give no clue as to where it fits into the picture. Is it in the first JSP? The unmentioned JSP that submitted to the first JSP?

If it's in the first JSP there's no way that its value will be set into a bean that you create on the same page. The JSP runs to create the page to send to the client, long before any input can be put into the form elements. If you want to pick up the values of submitted form elements in a bean, the bean must be declared in the JSP that you are submitting the form to.
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the super fast response! My text box was in the first jsp. There wasn't an unmentioned jsp. I made some modifications, which also are not working. The first jsp (login.jsp) contains two text boxes (loginid and loginpass) and uses a POST to submit to the second jsp (validate.jsp).
Validate.jsp looks like the following:

------
<jsp:useBean id="user" class="com.beans.UserData" scope="session"/>
<jsp:setProperty name="user" property="*"/>
<jsp:getProperty name="user" property="userid"/>

<html>
<HEAD>
</HEAD>

<BODY>
<FORM name="validateform">
This is coming from the userid textbox on login.jsp:
<br>
<%= user.getUserid() %>
</body>
</html>
------
And here is my UserData bean:

------
package com.beans;

/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: Aug 31, 2004
* Time: 12:18:36 AM
* To change this template use File | Settings | File Templates.
*/
public class UserData {
String userid = null;
String userpass = null;

public void setUserid(String value)
{
System.out.println("Andys value is: " + value);
userid = value;
}

public void setUserpass(String value)
{
userpass = value;
}

public String getUserid() { return userid; }

public String getUserpass() { return userpass; }
}
------

The second jsp (validate.jsp) is still displaying null.
Any ideas?

Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see where you expect loginid and loginpass to be set into the bean. It has no such properties.
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was a typo. These are the values I have in the first jsp:
<input type="text" name="userid" size="13"></font></input> <br>
<input type="password" name="userpass" size="13"></input></p>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the setters getting called?
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there is nothing printing in the log window. I wonder if the submit is not operating properly.. I added something like this on my second jsp:

------
<%
String name = request.getParameter( "userid" );
session.setAttribute( "theName", name );
%>
Hello, <%= session.getAttribute( "theName" ) %>
------

And it is producing null. I don't think there is a Tomcat config for allowing a session scope? I am out of ideas - it appears to be set up textbook.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you cut out the middle man and just see if the parameter is getting to the second page? Why all the hulabaloo with the session?

userid is <%= request.getParameter( "userid" ) %>

Is it as expected?

If not, what does your form look like?
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok figured it out. This is kind of embarrassing.
I have a js file for validation and it was set to this (see the error?):

------
function validateForm() {
if (form1.userid.value == "" && form1.userpass.value == "") {
alert("Enter a Username and Password");
form1.userid.focus();
return false;
}
else if (form1.userid.value == "") {
alert("Enter a Username");
form1.userid.focus();
return false;
} else if (form1.userpass.value == "") {
alert("Enter a Password");
form1.userpass.focus();
return false;
} else {

form1.userid.value = "";
form1.userpass.value = "";
return true;
}
}
------

Every time I submitted the form, I was clearing out the form values.
I am a newbie to JSP - I guess I learned a valuable lesson here.
Thanks for helping me out.
Regards.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No prob... that's what JavaRanch s all about!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic