jarodcanal
Jun 15th, 2007, 02:06 PM
Hi,
Our platform is a WAS 5.1, i.e. a J2EE 1.3 container (servlet 2.3, jsp 1.2), so the JSTL support is limited to JSTL 1.0.
I try to promote the use of frameworks, but things are moving slowly (please, do not laugh too hard, a few months ago we were not allowed to use Spring) .
Future apps could benefit from Spring for business tier and Faces for view tier (I hope so), but we have some old apps to maintain.
In the old ones, we got one with plenty of all-in-one jsp (no separation between business and view,...). I refactor things, but the (lack of) architecture made it too hard to change everything in one go (+ lack of time/resource to dev from the scratch, blablabla). But I am not here for crying, so back to the point.
In order to make jsp lighter and easier to read/maintain, I use JSTL (1.0) (since I cannot use something better for the views, at least for now).
The programs displays plenty of lists, and sometimes the list size.
JSTL 1.0 does not provide a solution to access list size (I mean to print it using JSTL EL).
Searching on internet, I found the following:
list size with JSTL 1.0 (http://www.phptr.com/articles/article.asp?p=30946&seqNum=8&rl=1)
I opted for the wrapper solution (with a very slight modif, returning a 0 size for null list). This way I can print list size with "myList.size" and access the rest of the list properties with "myList.list.x".
I know there are ways to do it with JSTL 1.1 (or Struts or other technologies), but is there another way just using JSTL 1.0 ? (alternative one, better one)
Thanks for your help.
Comments/ideas/corrections are welcome.
Regards.
package org.springframework.beans.support;
import java.io.Serializable;
import java.util.List;
/**
* ListWrapper is a simple wrapper for lists of objects.
*
* This is mainly targetted at usage in web UIs, with JSTL support limited to
* JSTL 1.0 (i.e. J2EE 1.3 container), since the only purpose of this class is to
* offer access to list size with JSTL EL like "myList.size". If you are using a
* more recent container (J2EE 1.4 or superior), you should be able to acces
* list size through JSTL or other technology without using this class.
* Typically, an instance will be instantiated with a list of beans, put into
* a scope, and the getSize() method will mainly be used by the view.
*/
public class ListWrapper implements Serializable {
/**
* List.
*/
private List list = null;
/**
* Set the list.
* @param list a list.
*/
public void setList(List list) {
this.list = list;
}
/**
* Get the list.
* @return the list.
*/
public List getList() {
return list;
}
/**
* Get the list size.
* @return the list size, or 0 if the list is null.
*/
public int getSize() {
if (list == null) {
return 0;
}
return list.size();
}
/**
* Create a new list wrapper instance.
*/
public ListWrapper() {
}
/**
* Create a new list wrapper instance.
* @param list a list.
*/
public ListWrapper(List list) {
this.list = list;
}
}
Our platform is a WAS 5.1, i.e. a J2EE 1.3 container (servlet 2.3, jsp 1.2), so the JSTL support is limited to JSTL 1.0.
I try to promote the use of frameworks, but things are moving slowly (please, do not laugh too hard, a few months ago we were not allowed to use Spring) .
Future apps could benefit from Spring for business tier and Faces for view tier (I hope so), but we have some old apps to maintain.
In the old ones, we got one with plenty of all-in-one jsp (no separation between business and view,...). I refactor things, but the (lack of) architecture made it too hard to change everything in one go (+ lack of time/resource to dev from the scratch, blablabla). But I am not here for crying, so back to the point.
In order to make jsp lighter and easier to read/maintain, I use JSTL (1.0) (since I cannot use something better for the views, at least for now).
The programs displays plenty of lists, and sometimes the list size.
JSTL 1.0 does not provide a solution to access list size (I mean to print it using JSTL EL).
Searching on internet, I found the following:
list size with JSTL 1.0 (http://www.phptr.com/articles/article.asp?p=30946&seqNum=8&rl=1)
I opted for the wrapper solution (with a very slight modif, returning a 0 size for null list). This way I can print list size with "myList.size" and access the rest of the list properties with "myList.list.x".
I know there are ways to do it with JSTL 1.1 (or Struts or other technologies), but is there another way just using JSTL 1.0 ? (alternative one, better one)
Thanks for your help.
Comments/ideas/corrections are welcome.
Regards.
package org.springframework.beans.support;
import java.io.Serializable;
import java.util.List;
/**
* ListWrapper is a simple wrapper for lists of objects.
*
* This is mainly targetted at usage in web UIs, with JSTL support limited to
* JSTL 1.0 (i.e. J2EE 1.3 container), since the only purpose of this class is to
* offer access to list size with JSTL EL like "myList.size". If you are using a
* more recent container (J2EE 1.4 or superior), you should be able to acces
* list size through JSTL or other technology without using this class.
* Typically, an instance will be instantiated with a list of beans, put into
* a scope, and the getSize() method will mainly be used by the view.
*/
public class ListWrapper implements Serializable {
/**
* List.
*/
private List list = null;
/**
* Set the list.
* @param list a list.
*/
public void setList(List list) {
this.list = list;
}
/**
* Get the list.
* @return the list.
*/
public List getList() {
return list;
}
/**
* Get the list size.
* @return the list size, or 0 if the list is null.
*/
public int getSize() {
if (list == null) {
return 0;
}
return list.size();
}
/**
* Create a new list wrapper instance.
*/
public ListWrapper() {
}
/**
* Create a new list wrapper instance.
* @param list a list.
*/
public ListWrapper(List list) {
this.list = list;
}
}