cycle in a jsp

P

pincopallo_it

in a jsp i need to repeat this line
<jsp:useBean id="uv" class="it.finsiel.tea.nhxnwi.util.UserValue"

with different id
as example :
<jsp:useBean id="uv1" class="it.finsiel.tea.nhxnwi.util.UserValue"
<jsp:useBean id="uv2" class="it.finsiel.tea.nhxnwi.util.UserValue"
<jsp:useBean id="uv3" class="it.finsiel.tea.nhxnwi.util.UserValue"

written in this way does not work ....

<%
int m =uv.getId_Ute_Progrn();
for ( int s = m ; s > 0; s--)
{%>
<jsp:useBean id="uv
<% out.println(s);%>
" class="it.ibm.teo.ninwi.util.UserFornValue" scope="request"/>

<% }

%>


Getting crazy over here .... any idea ??
Thanks
Gio
 
S

Sikri

My suggestion is to change the approach. "out.println.." will write to
standard out and not to the file or the servlet that is being
generated. That is the line "out.println..." will exist as is in the
servlet and write back to the client.

You want to use indexed properties. Here is an example of using indexed
properties using the standard Struts Tag library.
Steps:
1. Create a bean "UserValueBeanArray" which contains a list of
"UserValue" beans with methods for getUserValue(int index) and
setUserValue(int index, String value).
2. Use the Beanutils package. Struts recognizes this arrangement of
signatures as an "indexed property", in this case with the property
name "UserValue".
3. To refer to a value <!-- indexedtest.jsp -->
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<jsp:useBean id="bean"
class="org.apache.struts.webapp....UserValueBeanArray"/>
<bean:write name="bean" property="UserValue[1]"/>
4. To write a value to the property using dynamic arrays -refer to the
dynamic index section in the following link.
http://struts.apache.org/faqs/indexedprops.html

Hope this helps.
 
S

Sikri

My suggestion is to change the approach. "out.println.." will write to
standard out and not to the file or the servlet that is being generated
by the servlet container. That is the line "out.println..." will exist
as is in the servlet and write back to the client.

You want to use indexed properties. Here is an example of using indexed
properties using the standard Struts Tag library.
Steps:
1. Create a bean "UserValueBeanArray" which contains a list of
"UserValue" beans with methods for getUserValue(int index) and
setUserValue(int index, String value).
2. Use the Beanutils package. Struts recognizes this arrangement of
signatures as an "indexed property", in this case with the property
name "UserValue".
3. To refer to a value <!-- indexedtest.jsp -->
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<jsp:useBean id="bean"
class="org.apache.struts.webapp....UserValueBeanArray"/>
<bean:write name="bean" property="UserValue[1]"/>
4. To write a value to the property using dynamic arrays -refer to the
dynamic index section in the following link.
http://struts.apache.org/faqs/indexedprops.html

Hope this helps.
 
R

Ross Bamford

in a jsp i need to repeat this line
<jsp:useBean id="uv" class="it.finsiel.tea.nhxnwi.util.UserValue"

with different id
as example :
<jsp:useBean id="uv1" class="it.finsiel.tea.nhxnwi.util.UserValue"
<jsp:useBean id="uv2" class="it.finsiel.tea.nhxnwi.util.UserValue"
<jsp:useBean id="uv3" class="it.finsiel.tea.nhxnwi.util.UserValue"

written in this way does not work ....

<%
int m =uv.getId_Ute_Progrn();
for ( int s = m ; s > 0; s--)
{%>
<jsp:useBean id="uv
<% out.println(s);%>
" class="it.ibm.teo.ninwi.util.UserFornValue" scope="request"/>

<% }

%>


Getting crazy over here .... any idea ??
Thanks
Gio

I'm pretty sure you want to add page context attributes from a scriptlet -
JSP's aren't recursively parsed.
out.println _is_ the correct way to get output, of course
(_System_.out.println goes to stdout), but that output doesn't itself get
compiled and executed, so this won't work.

It's been a while since I did anything JSP but IIRC you want to be getting
hold of the PageContext (or maybe JspContext?) and calling it's
setAttribute method. Check the javadoc for either of those as a start...
 
T

Tim B

in a jsp i need to repeat this line
<jsp:useBean id="uv" class="it.finsiel.tea.nhxnwi.util.UserValue"

with different id
as example :
<jsp:useBean id="uv1" class="it.finsiel.tea.nhxnwi.util.UserValue"
<jsp:useBean id="uv2" class="it.finsiel.tea.nhxnwi.util.UserValue"
<jsp:useBean id="uv3" class="it.finsiel.tea.nhxnwi.util.UserValue"

written in this way does not work ....

<%
int m =uv.getId_Ute_Progrn();
for ( int s = m ; s > 0; s--)
{%>
<jsp:useBean id="uv
<% out.println(s);%>
" class="it.ibm.teo.ninwi.util.UserFornValue" scope="request"/>

<% }

%>


Getting crazy over here .... any idea ??
Thanks
Gio

instead of <jsp:useBean id="uv <% out.println(s);%>" ...

try <jsp:useBean id="uv<%=s%>" ...
or <jsp:useBean id='<%="uv"+ s%>' ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top