• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,Bear.
I will use Servlet instead of JSP.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic