Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How To Create This Drop-Down List  RSS feed

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My ArrayList is a collection of bean object. The ArrayList is created this way:

and my EditorBean is like:

After "editors" is returned, I create a session object:

How do I create a drop-down list for this collection of editors?

[ November 29, 2003: Message edited by: JiaPei Jen ]
 
manasa teja
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ideally for a select box, u should get lable and correspoding value from the bean..
ur bean shld be something like this..


put the Editors in the session or request obj.. get it in JSP..
JSP code ...

hope that helps!!
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help. May I ask two questions?
Q1.

EDITORS is the session object; i.e. session.setAttribute("EDITORS", editors);. What is 'id' in the <bean:define ....../> tag?
Q2.

Is it possible to specify the <htmlptions ..../> tag without labelProperty? I must go to the database to find a value to populate the bean and there is only one property in the bean.
[ November 29, 2003: Message edited by: JiaPei Jen ]
[ November 29, 2003: Message edited by: JiaPei Jen ]
 
manasa teja
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is 'id' in the <bean efine ....../> tag
its a scriptying varibale..
you have to declare that to get the "EDITORS" from the session into JSP
---
If your label and value are one and the same... then,
whatever u posted in ur fisr post is correct...
that is

then in JSP just do this!!

hope that helpS
[ November 30, 2003: Message edited by: manasa teja ]
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried

But, got an error message:
org.apache.jasper.JasperException: Cannot retrieve definition for form bean null
I tried another way:

The error message is the same. I do not have a form. Why the error message is "cannot retrieve definition from form bean null"?
Because the editors is a Collection. The editors is also an ArrayList of EditorBean(s), editors is passed to my JSP in a session object.

Do I have to retrieve editors from the session object in my JSP? How do I retriever a Collection from a session object?
[ December 01, 2003: Message edited by: JiaPei Jen ]
 
manasa teja
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by JiaPei Jen:
I tried

But, got an error message:
org.apache.jasper.JasperException: Cannot retrieve definition for form bean null
I tried another way:

The error message is the same. I do not have a form. Why the error message is "cannot retrieve definition from form bean null"?
Because the editors is a Collection. The editors is also an ArrayList of EditorBean(s), editors is passed to my JSP in a session object.

Do I have to retrieve editors from the session object in my JSP? How do I retriever a Collection from a session object?
[ December 01, 2003: Message edited by: JiaPei Jen ]

yes u have to retrive the arraylist into ur JSp from session.
it is like this
<bean efine id="editorsList" name="EDITORS" scope="session" type="java.util.ArrayList" />
then..
html:select tag..
Try this..
it should work
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried:

I got:
HTTP Status 500 - org.apache.jasper.JasperException: Cannot retrieve definition for form bean null
[ December 02, 2003: Message edited by: JiaPei Jen ]
 
Nathalie Keymeulen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this,
session.setAttribute( "editors", editors );
<html:form action="/Save" name="myForm" type="com.ctg.dspv.services.admLegalPerson.CreateUpdateForm" scope="session">
<html:select name="myForm" property="editorName">
<html ptions collection="editors" property="name" labelProperty="name"/>
</html:select>
</html:form>
ActionForm => com.ctg.dspv.services.admLegalPerson.CreateUpdateForm
with a getter and setter for editorName
 
manasa teja
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by JiaPei Jen:
I tried:

I got:
HTTP Status 500 - org.apache.jasper.JasperException: Cannot retrieve definition for form bean null
[ December 02, 2003: Message edited by: JiaPei Jen ]

I am not sure abt the problem,.. but,
plase check this..
1) have you declared the selectbox name in form bean..
2)See, whether, session attrribute name and the name you are reffereein gin the JSP are one aand same..
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nathalie, thank you very much. I tried what you suggested and I was able to disply the drop-down list.
Manasa, I also appreciate your support very much. You have helped me to understand a bit more about strusts form tag, select tag, and how to display an ArrayList that is passed to a JSP in a session object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!