Combining two lists in set / hash / map in Java, then displaying in Struts 1.x

At first, different data sets are stored from the two lists, however, after some combination of variables in the get method, it ultimately saves the same data type. The ultimate goal is to populate the drop-down list with two lists sorted by their names (description).

The main thing is that there are two tables containing the data type, but storing them so differently that it is almost impossible to write a good SQL statement to get it. The end result is a "name" or "nameIndex" object.

Both have an index code, but this is not related to the opposite table, it is related to what is stored in the third table, which must be updated using this code. Codes will never match between tables (one two characters long, the remaining 3 or more).

How to combine these two lists into a drop-down list for the user, so that the value of the drop-down list is an index code and a description displayed as a label?

Example:

<html:select property="name"> <html:optionsCollection name="nameList" label="nameDescription" value="nameCode" /> </html:select> <html:select property="nameIndex"> <html:optionsCollection name="nameIndexList" label="nameIndexDescription" value="nameIndexId.nameCode" /> </html:select> 

(note the value of "nameIndexId.nameCode"):

 <html:select property="allNames"> <html:optionsCollection name="allNames" label="nameDescription" value="nameCode" /> </html:select> 
+4
source share
2 answers

Although it was practically impossible, it was not entirely impossible. I created a view in SQL to pull both lists at once with the data I need, here is my answer:

 CREATE OR REPLACE VIEW FULL_NAME_LIST_VIEW AS SELECT N.NAME_ID AS ID, N.DISPLAY DISPLAY, 'BOSS' TYPE FROM NAME N UNION SELECT NI.NAME_INDEX_ID AS ID, (FIRST.DISPLAY || ' - ' || LAST.DISPLAY) AS DISPLAY, NI.TYPE_ID TYPE FROM NAME_INDEX NI, NAMEHOLDER FIRST, NAMEHOLDER LAST WHERE NI.FIRST_ID = FIRST.NAME_ID AND NI.LAST_ID = LAST.LAST_ID; 

This will create a view that you pull, like any regular table, for the ID, DISPLAY, and TYPE values. This is probably not a frequent problem, but it is a good solution for anyone who has such an undesirable effect in the future when you cannot change the data structure.

+2
source

One simple thing you can do in your DAO logic: create LabelValueBean objects by populating both lists (of course, using 2 loops). From the first list, you must create objects with a label as "nameDescription" and a value as "nameCode", and from the second list, any of the data. You must add these LabelValueBean objects to a single list and set it as an attribute for the request or session. Now in your JSP you can reference this new list in the html: optionsCollection tag.

+1
source

All Articles