Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help :how to get value from logic:iterate

 
Robert Smith
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my jsp is :
<logic:iterate id="xxx" name="abc" >
<bean:write name="xxx" property="logname"/>
<bean:write name="xxx" property="password"/>
<bean:write name="xxx" property="phone"/>
<bean:write name="xxx" property=""id/>
</logic:iterate>
how can i put the value of <bean:write name="xxx" property=""id/> to
a variable!
i try in this way :
<% int t= <bean:write name="xxx" property=""id/>;
%>
but it is wrong!
how can i do?
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not 100% certain, but I believe you can use the <bean:define> for that.

Then you can access the values as a page variable using, for example <%=idValue%> in your code, like in a request string:
yourAction.do?id=<%=idValue%>
or something along those lines.
HTH,
E
[ October 15, 2003: Message edited by: Eric Fletcher ]
 
Robert Smith
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you! i learn this way!
but i want to put a property of bean into a varible,for examples ,if a prperty of bean is a int variable ,can i write in this way:
<bean efine id="dd" name="xxx" property="id" />
<% int i=dd ;%>
or
<% int i=dd.getId();
%>
but it is all wrong! i don't understand the type of the "dd"(inside the example ),how can i do?
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi skyspeed, glad I could help.
When you use the <bean:define>, the bean defined by the tag has to be an object. Primitives like an int are wrapped with the appropriate wrapper class behind the scenes by the Struts framework.
In your case, the framework assumes you have a method called getId() in class xxx(if you don't the tag will throw a JspException). Since the method returns an int property, the tag will define a bean of type Integer wrapping the retrieved value.
<bean:define id="dd" name="xxx" property="id" />
So behind the scenes, Struts has created a page-scope bean of type Integer identified as "dd", so to get the actual wrapped int you would use:
<% int i=dd.intValue();%>
I believe that should work for you. Post again if you have any other questions or problems.
Cheers,
E
 
Robert Smith
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much ! i learn a lot!
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are very welcome, glad to help.
E
 
Kishore Sahu
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But is also not working.
I got errors saying as follows...




What is the actual solution? Please help me.

 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just give the type in the bean:define tag

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic