aspose file tools*
The moose likes JSP and the fly likes How to convert Java ArrayList code to JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to convert Java ArrayList code to JSTL " Watch "How to convert Java ArrayList code to JSTL " New topic
Author

How to convert Java ArrayList code to JSTL

Vasanthan Ramakrishnan
Greenhorn

Joined: Dec 16, 2007
Posts: 13
Dear friends

1.I want to know, how to convert Java ArrayList codes in JSTL.

I written scriplet code in my jsp. In that scriplets i am getting the arrylist, and using the arraylist i am executing for loops.

Now I am moving to JSTl for readability of code and avoiding scriplets.

I dont know how to use the java Arraylist code in JSTL. Please suggest me how to use.


2. How to pass the JSTL Values to User defined XML tags.

Please suggest me to solve the problem.

Thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60985
    
  65

Originally posted by Vasanthan Ramakrishnan:
1.I want to know, how to convert Java ArrayList codes in JSTL.
Do you have a copy of the JSTL Specification? Look up <c:forEach>.

2. How to pass the JSTL Values to User defined XML tags.
I don't know what you mean by JSTL values. The JSTL is just a tag library. Do you mean scoped variables?

Also, what do you mean by "XML tag"?
[ January 23, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vasanthan Ramakrishnan
Greenhorn

Joined: Dec 16, 2007
Posts: 13
Thanks for reply
1. ok i am using for each.

I need how to assign the list value into JSTL varriable.

for example.

the arraylist values alist=[90,administrator,admin,a@yahoo.com,99,administrator1,admin1,a1@yahoo.com]

I need this output in HTML

Dept Code : 90 Deptname : administrator
Dept Manager: admin Deptmail : a@yahoo.com

Dept Code : 99 Deptname : administrator1
Dept Manager: admin1 Deptmail : a1@yahoo.com

I am written the code in JSTL

<c:forEach var="alist" items="${alist}" begin="0" end="${asize}" step="4">
<TR>
<TD>Det code : </TD>
<TD>${alist[0]} </TD>
<TD>Dept Name: </TD>
<TD>${alist[1]} </TD>
</TR>

<TR>
<TD>Dept Manager: </TD>
<TD>${alist[2]} </TD>
<TD>Dpt Mail: </TD>
<TD>${alist[3]} </TD>
</TR>
</c:forEach>

here asize is the array list size.

My Output

Dept Code : 90 Deptname : administrator
Dept Manager: admin Deptmail : a@yahoo.com

Dept Code : 90 Deptname : administrator
Dept Manager: admin Deptmail : a@yahoo.com

I know when i given alist[0],alist[1],alist[2],alist[3], it will print the same.


I dont know how to reteive the next iterate value. So only i just give the direct index value.

How to reterive the next value in for each. like in java scriplet code.

like this
<%for(int i=0;i<alist.size();i++) {
String str = String.valueOf(alist.get(i));
String str1 = String.valueOf(alist.get(i+1));// how to do this in JSTL
%>

<TD>STR - <%=str%> </TD>
<TD>STR1 - <%=str1%> </TD>

<% } %>

Please Suggest how to do this.

2.how to use JSTL varriable into Xml Tag.

for example

In my TLD File(eztaglib.tld)

<tag>
<name>companytag</name>
<tag-class>bas.CompanyTag</tag-class>
<attribute>
<name>dbase</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>dbpass</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>dburl</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>pgm_sname</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>session</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>

</tag>


old code :
java value I am passing to XML in jsp scriplet code.

<%@ taglib uri="/ezerptags.tld" prefix="eztag" %>
.......
....
<eztag:companytag pgm_sname="<%= strpgm_name%>" dbase="<%= strd%>"
dbpass="<%= strp%>" dburl="<%= stru%>" session="<%= session%>" />
....
...

After modified in JSTL

<%@ taglib uri="/ezerptags.tld" prefix="eztag" %>
.......
....
<eztag:companytag pgm_sname="${pgm_name}" dbase="${strd}"
dbpass="${strp}" dburl="${stru}" session="${session}" />
.....
...

but its Not working. How to use this

the "eztag" and "companytag" are the customtag. these tages available in eztaglib.tld file. I am passing the value through XML Tag.

but its Not working. How to use this

Thanks in advance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert Java ArrayList code to JSTL