• 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

bean:define to define an array of Strings

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

I have a bean that has a list of names
the bean has name="companyNames" property="cName"

In the front end I want to manipulate these names for display purposes and so, want to do so using Java in the jsp page

Can I have this list in a Java string array
something like

<bean efine id="iNames[]" name="companyNames" type="java.lang.String[]" />

so that I can use the iNames[] array
<% System.out.println(iNames[0]); %> in jsp


Is there any way to do this?

I hope I was clear in telling what I wanted..

Thanks,
- Gayatri
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you use the <logic:iterate> tag to iterate through the list of bean objects, and <bean:write> to display the cName property from the companyNames list.

For example -


Hope this helps.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<%
String[] temp = {"","","","","","","",""};
String cNameID[]=temp;%>
<logic:notEmpty name="companyNames" property="cName">
 <bean:define  id="hidcName" name="companyNames" property="cName" type="java.lang.String[]" />
 <% cNameID= hidcName==null? temp : hidcName;%>
</logic:notEmpty>

After that in last of jsp add a .js block. In struts 1 if using Action then automatically array field will not set values, So we should use dispatchaction.
<script>
try{
document.getElementsByName("cName")[0].value = '<%=cNameID[0]%>';
document.getElementsByName("cName")[1].value = '<%=cNameID[1]%>';
document.getElementsByName("cName")[2].value = '<%=cNameID[2]%>';
document.getElementsByName("cName")[3].value = '<%=cNameID[3]%>';
document.getElementsByName("cName")[4].value = '<%=cNameID[4]%>';
}catch(er){}
</script>
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic