This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes LinkedHashMap in  html:options Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "LinkedHashMap in  html:options" Watch "LinkedHashMap in  html:options" New topic
Author

LinkedHashMap in html:options

Bacchi Gerem
Ranch Hand

Joined: Jan 23, 2004
Posts: 120
Hi,
i want to display address of customer based on key.customer has two or more addresses.
i need to select key value in combo box.

based on key i need to print address.

opadid is key.

opcua1,opcua2,opcua3,opcua4 are address columns



How can write code in jsp page in struts.


public Map<String,siteBean> getsiteaddressMap() {
String select = "select opadid , opcua1 ,opcua2 , opcua3 ,opcua4 from customer

Map<String,siteBean> siteAddressMap = new LinkedHashMap<String,siteBean>();
if (con != null) {
try {
PreparedStatement ps = con.prepareStatement(select);

ResultSet rs = ps.executeQuery();
while (rs.next()) {
siteBean sb = new siteBean(
rs.getString("opcua1"),
rs.getString("opcua1"),
rs.getString("opcua1"),
rs.getString("opcua1"),
rs.getString("opadid"));

siteAddressMap.put(sb.getAdid(),sb);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
return siteAddressMap.isEmpty() ? null : siteAddressMap;

}



Thanks
[ March 03, 2008: Message edited by: Bhaskar Gara ]
Bacchi Gerem
Ranch Hand

Joined: Jan 23, 2004
Posts: 120
Anybody please help me ...
Bacchi Gerem
Ranch Hand

Joined: Jan 23, 2004
Posts: 120
this is map with key and Bean Object in struts
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
There are plenty of helpful people around here that are willing to lend a hand with answering questions, but not as many people that are willing to implement full pages for you (especially since all you did was post some code and a few sentences). Can you describe in more detail what you are trying to accomplish? I do not know what "i need to select key value in combo box. based on key i need to print address." really means. Could you also describe what you have tried so far and what specific issues you have encountered?

- Brent
Bacchi Gerem
Ranch Hand

Joined: Jan 23, 2004
Posts: 120
Hi ,
i need to display address of a customer .
for example.....
table:

id addressLine1 addressLine2 addressLine3

01 ********** ********* ***********

02 *********** ********** ***********

03 ********** ************ ***********



I need to diplay ids in drop down box.

If i select 01 in drop down box

it displays :


AddressLine1 : ********
AddressLine2 : ********
AddressLine3 : ********

How can i do that in struts?
Actually map contains one key and value.

But here it contains one key and multiple values.

Thank You
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I see...here are the three basic high-level solutions that I know of.

1) You could load all the values onto the page and use JavaScript to update the fields when the value of the drop down list changes. This works well for small sets.

2) When the selection changes, submit the page and use processing in your action to update the values so the correct address values will be shown when the page refreshes. This might be the easiest solution but the user experience is a bit clunky because the entire page refreshes.

3) Use an Ajax solution to load the address values when the selection changes. This might be a little overkill if you page only has a few values and you are not already using Ajax.

- Brent
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: LinkedHashMap in html:options
 
Similar Threads
Error with jsp and JavaBeans
A cleaner way to display LinkedHashMap/ArrayList
Iterating over Map using JSTL
clarification for jsp code
Null Values