Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I set or get a property of a bean in which there is a Vector of object?  RSS feed

 
Chris Wang
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I defined a class Question which has some properties, such as id,type,etc.
public class Question implements Serializable {
private int id = -1;
private int number = -1;
private String prompt = "";
private String type = "singlechoice";
private boolean mandatory = true;
private int scaleCount = 0;
private Vector choices = new Vector(); // option choice Strings
.... setXXX and getXXX methods in here ....
}
I defined another class Survey which has a Vector of the Question object.
public class Survey implements Serializable{
private int id;
...some other properties...
private Vector questions = new Vector(); // vector of Question
...setXXX and getXXX...
}
After i edit the data in the editsurvey.jsp and submit the form, i want to validate the data in validatesurvey.jsp.
I use
<jsp:useBean id="survey" scope="request" class="com.mycompany.beans.Survey">
<jsp:setProperty name="survey" property="*" />
</jsp:useBean>
to get survey.
But i only get the int and string properties of survey, such as id, i can't get the vector of the question object.
How can i get the question object?
Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Chris!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
JSP Forum Bartender
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not think you can do what you want to do using the property="*" mechanism which does not seem to make any allowance for arrays of data.
You might want to read up here on what conversions the setProperty tag will perform.
That said, I think you'd be better off submitting your form to a servlet in which you can retrieve the submission data and populate the bean under your complete control. The bean can then be attached to the request and forwarded to your JSP page. (This is a "best practice" pattern that you'll find useful again and again.)
bear
[ January 13, 2004: Message edited by: Bear Bibeault ]
 
Chris Wang
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,Bear.
I will use Servlet instead of JSP.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!