2

I am working on Struts2 Application;

my displaying objects are Map objects:

Map<String, HashMap<String, List<PlanDAO>>> channelRoomTypePlanmap = 
                             new HashMap<String,HashMap<String,List<PlanDAO>>>();

Map<String, List<RateInventoryDAO>> rateInventoryMap = 
                             new HashMap<String, List<RateInventoryDAO>>();

Here, I have two objects, where rateInventoryMap key is dependent on channelRoomTypePlanmap value combination.

Like when I print first value of channelRoomTypePlanmap I want to create key using combination of its value, and find it in rateInventoryMap , if its true then it'll print its value.

<div>
    <table id="mainTable" >
        <tr>
            <td>
                <s:iterator value="channelRoomTypePlanmap">
                    <table border="1">
                        <tr>
                            <td><s:property value="key" />
                            </td>
                            <td>
                                <table>
                                    <s:iterator value="value">
                                        <tr>
                                            <td><s:property value="key" />
                                            </td>
                                            <td>
                                                <table border="1">
                                                    <s:iterator value="value">
                                                        <tr>
                                                            <td><s:property value="planName" />
                                                            </td>
                                                            <s:iterator value="rateInventoryMap">
                                                                <s:iterator value="value">
                                                                    <td><s:property value="currentRate" />
                                                                    </td>
                                                                </s:iterator>
                                                            </s:iterator>
                                                        </tr>
                                                    </s:iterator>
                                                </table>
                                            </td>
                                        </tr>
                                    </s:iterator>
                                </table>
                            </td>
                        </tr>
                    </table>
                </s:iterator>
            </td>
        </tr>
    </table>
</div>

I tried this, which is showing in wrong format, means showing all data from second Map in single row for all. I've also heard that scriptlet code should be avoided.

How can I join these two Maps on JSP ?

Current View using above code_ enter image description here

V.Rohan
  • 945
  • 2
  • 14
  • 27
  • What do you mean *create key using combination of its value*? Also you should not manipulate maps on the view layer without a reason. – Roman C Sep 02 '14 at 09:07
  • *... which is showing in wrong format, means showing all data from second Map in single row for all.* - But that is what you are doing. Put rows inside iterator if you want so. – Aleksandr M Sep 02 '14 at 09:12
  • @RomanC actually i done with combination key, now i want row from 'rateInventoryMap = new HashMap>();' based on that key on jsp page. Can i generate that key jsp page, and find that key in 'rateInventoryMap'? – V.Rohan Sep 02 '14 at 09:18
  • @V.Rohan Don't post a code in comments, edit a question and add details, also DAOs aren't supposed to use as data beans on the view layer. – Roman C Sep 02 '14 at 09:23
  • @AleksandrM i done with but where i can check for key, and print corresponding list – V.Rohan Sep 02 '14 at 09:24
  • @RomanC next time ll keep in my mind – V.Rohan Sep 02 '14 at 09:31
  • Don't check for key, just use it to retrieve value from the map. – Aleksandr M Sep 02 '14 at 09:37
  • @AleksandrM m attaching view above, where m getting all map values in one row. – V.Rohan Sep 02 '14 at 09:48
  • 2
    Use `rateInventoryMap['your_key_here'].currentRate`. – Aleksandr M Sep 02 '14 at 09:49
  • @AleksandrM i this this ll helpful, but how can i combine above values(above iterator values) to generate Key? – V.Rohan Sep 02 '14 at 09:57
  • So what is your key? What do you mean by generate a key? – Aleksandr M Sep 02 '14 at 10:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/60442/discussion-between-v-rohan-and-aleksandr-m). – V.Rohan Sep 02 '14 at 10:12

1 Answers1

2

Your model structure

new HashMap<String,HashMap<String,List<PlanDAO>>>(); 

should be improved; it is too noisy, you need five nested iterators in your page to do what you need, never know in which iterator you are without counting them, and, more important, even if this structure can be used to display data, it can't be used to send it back (you never know).

I strongly suggest you to read the following answer:

That said, when dealing with Collections in a JSP you must read about two great features of OGNL:

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • OP *don't* send it back, so you better find how to *join* them. – Roman C Sep 02 '14 at 09:12
  • 2
    @RomanC This is *not* a good reason to have an ugly design. And I've written *you never know* exactly for this reason. Maybe today he only displays them, and tomorrow a new use case will need them to be posted. And guess what ? The data structure will be already implemented all over the application, and it will be a pain to change it. Other than that, it is useful for other data structures he uses today in his application. Or do you think his application never sends anything back (possible, but unlikely) ? – Andrea Ligios Sep 02 '14 at 09:35