You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vijay Balakrishnan <Vi...@MyHealthBank.com> on 2002/12/04 21:32:51 UTC

get key value for a hashmap row-similar to result in jstl

HI,

I am trying to get the key values for a hashmap row from a collection of
hashmaps.I want to access the specific key value from the hashmap eg: 
I want to access the key value "nameId" from the hashMapQuestionRow
directly.How can i do that ? I am doing it this way right now.Is there an
easier way to do it.

<logic:iterate id="hashMapQuestionRow" name="ac"
property="hashMapQuestionRows" >
           <% int count=0;%>
            <logic:iterate id="item" name="hashMapQuestionRow">

                <logic:equal value="nameId" property="key" name="item" >
                    <%--<bean:write name="item" property="value" /> --%>

                    <bean:define id="nameId" name="item" property="value" />
                </logic:equal>
	</logic:iterate>

	 <input type="hidden" name="questionIDs" value="<bean:write
name="nameId" />">

</logic:iterate>

Thanx,
Vijay

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: get key value for a hashmap row-similar to result in jstl

Posted by Vinh Tran <vi...@processintelligence.com>.
Another option is to add some supporting fields to retrieve a
hashMapQuestionRow by key. For example:

class hashMapQuestionRows
{
	private String currentKey;
	private hashMapQuestionRow currentQuestionRow;

	....

	public getHashMapQuestionRow()
	{
		return (hashMapQuestionRow)yourMap.get(currentKey);
	}

}

Have getters and setters for both.  Do a <jsp:setProperty> on currentKey
than do a <bean:define> for currentQuestionRow. I don't know if this
approach defies any "rules" but it works well for my requirements. The nice
thing is that you no longer need to iterate over the entire collection
looking for the requested nameId row.

Vinh

-----Original Message-----
From: Vijay Balakrishnan [mailto:Vijay.Balakrishnan@MyHealthBank.com]
Sent: Wednesday, December 04, 2002 3:33 PM
To: 'struts-user@jakarta.apache.org'
Subject: get key value for a hashmap row-similar to result in jstl


HI,

I am trying to get the key values for a hashmap row from a collection of
hashmaps.I want to access the specific key value from the hashmap eg:
I want to access the key value "nameId" from the hashMapQuestionRow
directly.How can i do that ? I am doing it this way right now.Is there an
easier way to do it.

<logic:iterate id="hashMapQuestionRow" name="ac"
property="hashMapQuestionRows" >
           <% int count=0;%>
            <logic:iterate id="item" name="hashMapQuestionRow">

                <logic:equal value="nameId" property="key" name="item" >
                    <%--<bean:write name="item" property="value" /> --%>

                    <bean:define id="nameId" name="item" property="value" />
                </logic:equal>
	</logic:iterate>

	 <input type="hidden" name="questionIDs" value="<bean:write
name="nameId" />">

</logic:iterate>

Thanx,
Vijay

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>