Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Can I use a same Bean for this JSP ?

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my JSP, it looks like
****************
<% String age = session.getAttribute("Age").toString();
String choice;
if(age.equals("senior")) choice = "MULTIPLE";
else choice = "SINGLE"; %>

<SELECT NAME="ITEMS" <%= choice %>>
<OPTION VALUE="item1">item1
<OPTION ...
...
</SELECT>
*****************

It may have some typo here. But the point is this JSP page can dynamically ask user to pick one or more items (sometimes one, sometimes more, depending on if you are senior member). Now suppose we have a "FormBean" matching this JSP, should I

1) create two "FormBean" class, in first one I put "private String item;" and in second class I put "private Collection item;" ?
2) or should I ONLY create one "FormBean" class and just put "private Collection item" ? The single item case should be covered by it anyway.

I guess I should take approach 2), is that right ?
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you're right. But I have never tried that.
 
steve francisco
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can someone give me a sure answer ?
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic