• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Populating 'html:select' with values in Database

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,
I want to populate a <html:select> (a drop-down box) with values from the database. I did some search on the Internet regarding this and got the below code:
----------
<html:select property="unitId" >
<bean: Define id="lookupProjectUnits" name="pipingForm" property="projectUnits"/>
<html: options collection="lookupProjectUnits" property="value" labelProperty="label"/>
</html:select>
------------

I am not able to understand the <html ptions collection .... > part. Can anyone explicitly specify (with an example) what it's doing & how can i get data into the drop-down box.
Thanx in advance.....
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was searching for this last week. Though i don't know much abt that, i've one solution wid me.



Here.. "RequestBean" is a POJO where i've getter and setter for "productVesrion". I'm setting productVesrion with my DB data in my jsp.
and "Version" is the property in my Struts DynaForm.

Hope it helps U
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To display data of lists.
<html: options collection = name of the list,array or collection in the request.
[ April 25, 2006: Message edited by: sweta naidu ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If all else fails, read the documentation.
 
Shailesh Pillai
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for ur reply,
But i am getting the following error :

root cause

javax.servlet.jsp.JspException: Cannot find bean under name myList
org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:364)
org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:186)
org.apache.jsp.TeleActionInput_jsp._jspx_meth_html_options_0(TeleActionInput_jsp.java:334)
org.apache.jsp.TeleActionInput_jsp._jspx_meth_html_select_0(TeleActionInput_jsp.java:305)
org.apache.jsp.TeleActionInput_jsp._jspx_meth_html_form_0(TeleActionInput_jsp.java:204)
org.apache.jsp.TeleActionInput_jsp._jspx_meth_html_html_0(TeleActionInput_jsp.java:134)
org.apache.jsp.TeleActionInput_jsp._jspService(TeleActionInput_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

-------
My JSP is as follows:

<html:select property="empNo">
<html ptions collection="myList" property="empNo" labelProperty="empNo" />
</html:select>
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it better with :
 
Shailesh Pillai
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
First of all thanks for all your response. Now let me explain my problem clearly.

I have 2 JSP Pages viz. index.jsp & Page1.jsp.
In index.jsp I have a link to Page1.jsp as follows:
--------------------------------------------
<html:link action="/getPage1"> Employee Form </html:link>
--------------------------------------------
I have appropriate action mapping for the above action which forwards it to Page1.jsp

On Page1.jsp, I have an Employee Form where I have a field viz. Employee Code -which is a drop-down box.
What i want is the moment Page1.jsp is displayed, the Employee Code drop-down should be filled with
values from the Database.
So how to go about it.
Please provide a conceptual view to it.
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I am not wrong your code in the JSP looks as below..

<html:select property="empNo">
<html ptions collection="myList" property="empNo" labelProperty="empNo" />
</html:select>

I will explain you the html ptions tag step by step.

1. myList--> It is the name of the formBean which can be in request or session scope. Now this formBean is populated in the Action Class. The formBean can be populated with a ArrayList or Any other collection.
ex.. formBean.setEmployeeList(employeeyList). employeeList is a ArrayList.

This employeeList contains object of user defined beans which are populated through database.. Suppose the name of the bean object is employee
Now employee contains two attributes empId and empNo.

2. property="empId" --> It the value stored at the back of the combo box and is submiitet to the server when sumbit button is pressed.

3. property="empNo"--> It is the value dispayed to the user.

Hope this will solve ur problem.
 
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic