S
Spivee
I have seen several topics about this, but generally, they don't seem
very helpful, mostly stating that there is no built-in way to do it,
and that a custom solution must be created. Also, most posts say that
there shouldn't be a reason for it, but here's my current dilemma.
I am doing a struts based form page to manage our application servers
etc. I want to do a form page with a dropdown of all our servers, in
alphabetical order by servername.
I want a dropdown list of servers with the html tag value being the
server_id value from our database. Each server has two values, (of
interest to this issue), server_id, a unique row identifier, and
host_name. Hostname does not have to be unique since we have servers
in different environments that are named the same.
I want something like this..
<select name="server_id">
<option value="1">aserver1</option>
<option value="3">bserver2</option>
<option value="2">cserver3</option>
</select>
When I pull the data out of the db, I have been putting the values in a
hashmap, with key equal to server_id and value equal to host_name. I
then use logic:iterate or htmlptions to print out the dropdown select
elements.
Something like this...
<html:select property="server_id">
<htmlptions collection="servermap"
property="key"
labelProperty="value" />
</html:select>
The problem is that maps sort by key, so all my servers come out in the
order of server_id, nt host_name. Since two servers can have the same
name, I can't just invert the hashmap key/values.
I know I could probably do this with a custom solution, but that would
make a less than pretty jsp file. I doubt I could use any of the html
taglibs to do it. This just seems to me to be a basic type of thing
that would be done a lot in web based applications. I'm thinking
there's either a solution out there I'm unaware of or the process I'm
trying to use is flawed. Maybe there's an easier way for me to build
the map and the page.
Any suggestions would be helpful.
very helpful, mostly stating that there is no built-in way to do it,
and that a custom solution must be created. Also, most posts say that
there shouldn't be a reason for it, but here's my current dilemma.
I am doing a struts based form page to manage our application servers
etc. I want to do a form page with a dropdown of all our servers, in
alphabetical order by servername.
I want a dropdown list of servers with the html tag value being the
server_id value from our database. Each server has two values, (of
interest to this issue), server_id, a unique row identifier, and
host_name. Hostname does not have to be unique since we have servers
in different environments that are named the same.
I want something like this..
<select name="server_id">
<option value="1">aserver1</option>
<option value="3">bserver2</option>
<option value="2">cserver3</option>
</select>
When I pull the data out of the db, I have been putting the values in a
hashmap, with key equal to server_id and value equal to host_name. I
then use logic:iterate or htmlptions to print out the dropdown select
elements.
Something like this...
<html:select property="server_id">
<htmlptions collection="servermap"
property="key"
labelProperty="value" />
</html:select>
The problem is that maps sort by key, so all my servers come out in the
order of server_id, nt host_name. Since two servers can have the same
name, I can't just invert the hashmap key/values.
I know I could probably do this with a custom solution, but that would
make a less than pretty jsp file. I doubt I could use any of the html
taglibs to do it. This just seems to me to be a basic type of thing
that would be done a lot in web based applications. I'm thinking
there's either a solution out there I'm unaware of or the process I'm
trying to use is flawed. Maybe there's an easier way for me to build
the map and the page.
Any suggestions would be helpful.