• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem using bean:define

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am using following code and defining <bean efine> tag inside <logic:iterate>. I am trying to pass the the id of <bean efine> as a parameter in params.put. But it is giving me error. My code is as follows:
----------------Code---------------
<logic:iterate id="id_duplicatecompany" name="al_duplicatecompany">
<tr>
<td width="26%" class="<%=style%>" >
<bean efine name="id_duplicatecompany" id="paramcompany" />
<%
java.util.HashMap params = new java.util.HashMap();

params.put("cid",paramcompany);//Giving error here.

pageContext.setAttribute("params",params);
%>
</td>
</tr>
</logic:iterate>
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the error? Any why did you define the bean inside the iterate?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a custom tag creates a varialble referencing an object, by default that variable is placed in page scope. If you want to write a scriptlet that uses that object, you must retrieve it from the pageContext object.

In the example you gave, your <bean efine> tag is unnecessary.

The following code should work:

String paramCompany = (String) pageContext.getAttribute("id_duplicatecompany");
params.put("cid",paramcompany);
 
dimpsonu arora
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merrill it is working now.

Hi Alan,
I put bean tage inside iterator as my iterator was giving me different companyid and I needed different companyid to pass as the parameter.
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic