| Author |
help :how to get value from logic:iterate
|
Robert Smith
Greenhorn
Joined: Oct 14, 2003
Posts: 23
|
|
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
Joined: Oct 26, 2000
Posts: 188
|
|
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 ]
|
My theory of evolution is that Darwin was adopted. - Steven Wright
|
 |
Robert Smith
Greenhorn
Joined: Oct 14, 2003
Posts: 23
|
|
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
Joined: Oct 26, 2000
Posts: 188
|
|
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
Joined: Oct 14, 2003
Posts: 23
|
|
|
thank you very much ! i learn a lot!
|
 |
Eric Fletcher
Ranch Hand
Joined: Oct 26, 2000
Posts: 188
|
|
You are very welcome, glad to help. E
|
 |
Kishore Sahu
Ranch Hand
Joined: Mar 10, 2009
Posts: 31
|
|
But is also not working.
I got errors saying as follows...
What is the actual solution? Please help me.
|
Kishore
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
just give the type in the bean:define tag
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
 |
|
|
subject: help :how to get value from logic:iterate
|
|
|