You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sachin Bhutada <Sa...@xoriant.com> on 2005/02/17 09:17:55 UTC

Interating through a Map [ which has DTO in the values ] using l ogic:iterate


hi, 
   I have a HashMap which has Key and Value both as DTOs 

	Key contains Dept DTO (Dept has Dept No, Dept Name)
	Value contains Collection of EmpDetails DTO (It has Name, Email-Id,
etc information)
   In the jsp page I want to iterate through this Map using logic iterate
tag so that outpage html page should look like this..

  Dept No : Dept Name
	Emp One 	xxx@.xx.com 		.....
	Emp Two 	xxx@.xx.com 		.....
	and so on 
  Dept No 3 : Dept Name 3	
	Emp One 	xxx@.xx.com 		.....
	Emp Two 	xxx@.xx.com 		.....
	and so on ...........

 To achieve this, I have written following code. For the time being I am
just concetrating on displaying the Department Details.. 

 <logic:iterate id="element"  name="formName" property="deptHashMap">
	  <br/>
   	  <bean:write name="element" property="key"/> -- IT displayes the
Dept object name 

	When I try to use following code it shows error message 
	javax.servlet.jsp.JspException: No getter method for property
key.deptNo of bean element 
  	  <bean:write name="element" property="key.deptNo"/>
 </logic:iterate>

In my actionform class I have haspmap and getter and setter methods. 

How should I display deptNo and deptName in the Dept DTO ? 

Thanks in Advance
Sachin


Re: Interating through a Map [ which has DTO in the values ] using l ogic:iterate

Posted by Robert Taylor <64...@bellsouth.net>.
It may be better to create a value object containing the Dept DTO and
its respective collection of EmpDetails DTO. Then you don't have to
"jump through hoops" when using Maps.

<logic:iterate id="element" name="formName" property="depts">
<br />
<bean:write name="element" property="dept.deptNo"/>
<bean:write name="element" property="dept.deptName"/>
<logic:iterate id="empElement" name="element" property="employees">
<br />&nbsp;&nbsp;&nbsp;&nbsp;
       <bean:write name="empElement" property="name"/>
       <bean:write name="empElement" property="email"/>
</logic:iterate>
</logic:iterate>



/robert

Sachin Bhutada wrote:
> 
> hi, 
>    I have a HashMap which has Key and Value both as DTOs 
> 
> 	Key contains Dept DTO (Dept has Dept No, Dept Name)
> 	Value contains Collection of EmpDetails DTO (It has Name, Email-Id,
> etc information)
>    In the jsp page I want to iterate through this Map using logic iterate
> tag so that outpage html page should look like this..
> 
>   Dept No : Dept Name
> 	Emp One 	xxx@.xx.com 		.....
> 	Emp Two 	xxx@.xx.com 		.....
> 	and so on 
>   Dept No 3 : Dept Name 3	
> 	Emp One 	xxx@.xx.com 		.....
> 	Emp Two 	xxx@.xx.com 		.....
> 	and so on ...........
> 
>  To achieve this, I have written following code. For the time being I am
> just concetrating on displaying the Department Details.. 
> 
>  <logic:iterate id="element"  name="formName" property="deptHashMap">
> 	  <br/>
>    	  <bean:write name="element" property="key"/> -- IT displayes the
> Dept object name 
> 
> 	When I try to use following code it shows error message 
> 	javax.servlet.jsp.JspException: No getter method for property
> key.deptNo of bean element 
>   	  <bean:write name="element" property="key.deptNo"/>
>  </logic:iterate>
> 
> In my actionform class I have haspmap and getter and setter methods. 
> 
> How should I display deptNo and deptName in the Dept DTO ? 
> 
> Thanks in Advance
> Sachin
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org