Does the LabelValueBean class which is connected to hibernate??
Main Topics
Browse All TopicsI need a jsp in which it contains a dropdown list. It allows the user to select the item and hit Submit button to initiate the process.
The backend process has been done.
The problem is I dont know how to build a dropdown list in which the data is extraced via Hibernate
Notes. the dao objected generated from Myeclipse works ok.
I only need to know how to i do it in JSP
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: jaggernatPosted on 2006-09-06 at 16:19:24ID: 17467222
you can create drop-down list in jsp using this tag <html:select>..so itwould be something like this:
")); // "BLONDE" is displayed on the front end and "1" is submitted to server )); ; HITE")); )); ALD")); )); G")); N")); ;
(true);
ePage");
Page");
<html:select property="hairType">
<html:option value="Select one"/>
<html:options collection="hairColorList " property="value" labelProperty="label"/>
</html:select>
You can populate the drop down (<html:select >) using LabelValueBean.
Follow this sample code
>>How to use Label Value Bean
LabelValueBean takes two parameters("x","y") something like LabelValueBean("x","Y")
one parameter is displayed in the front end ("Y") and the other one ("x") goes to the server when the jsp is submitted
Sample
Consider a scenario where you have a select field in your jsp page. you can perform operations on the select field using LabelValueBean
Create a util class which populates values in LabelValueBean
>>>>>>>>>>>>>>>>>
private static ArrayList hairColorList = new ArrayList();
private static void buildHairColorList() {
hairColorList.clear();
hairColorList.add(new LabelValueBean("1","BLONDE
hairColorList.add(new LabelValueBean("2","BLACK"
hairColorList.add(new LabelValueBean("3","RED"))
hairColorList.add(new LabelValueBean("4","GRAY/W
hairColorList.add(new LabelValueBean("5","BROWN"
hairColorList.add(new LabelValueBean("6","NONE/B
hairColorList.add(new LabelValueBean("7","OTHER"
hairColorList.add(new LabelValueBean("8","BALDIN
hairColorList.add(new LabelValueBean("9","UNKNOW
hairColorList.trimToSize()
}
>>>>>>>>>>>>>>>>
Your Jsp would be
<html:select property="hairType"> //Make sure hairType is in the form bean
<html:option value="Select one"/>
<html:options collection="hairColorList " property="value" labelProperty="label"/>
</html:select>
>>>>>>>>>>>>>
Once you submit your jsp page, in your action class you can get the value of the select field("hairType")
so, Your action class code would be
public ActionForward relType (
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
HttpSession session=request.getSession
DynaValidatorForm dForm = (DynaValidatorForm) form;
String hType = (String) dForm.get("hairType"); //get value of "hairType" select field from jsp
if (hType .equals("1")) // meaning BLONDE
{
// write logic for blonde women :)
return mapping.findForward("Blond
} else if (hType.equals("5")) //meaning BROWN
{
//write logic for brown women
return mapping.findForward("Brown
} else if (hType.equals("2 or 3 or 4 or some thing"))
{
return mapping.findForward("// do some thing");
}
}
hope this helps
J