commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Camilo Gonzalez" <camig...@gmail.com>
Subject Support for DynaBean array-like property accesing
Date Sun, 01 Jul 2007 05:02:33 GMT
Hi all!!!

In the org.apache.commons.el.ArraySuffix class, inside the "evaluate"
method, it could be possible to add the following lines as the ending else.
This way, DynaBeans could be supported, giving the possibility of accesing
DynaBean properties like if we were accesing an array index.

--------------- Begin Code fragment ----------------
       else {
            try {
                Object val = null;
                Method m = pValue.getClass().getMethod("get", new Class[] {
String.class });
                val = m.invoke(pValue, new Object[] { indexVal + "" });
                return val;
            } catch (Exception ex) {
                if (pLogger.isLoggingError()) {
                    pLogger.logError(ex);
                    pLogger.logError(Constants.CANT_FIND_INDEX, indexVal,
pValue.getClass()
                            .getName(), getOperatorSymbol());
                }
                return null;
            }
        }
--------------------- End Code fragment ---------------------------------

In the EL of your JSP's you could access a DynaBean property like this
(assume b is an instance of a DynaBean implementation, that contains an id
which is a Integer object, and a name which is a wrapper for two strings:
lastName and firstName):

Id: <c:out value="${b[id]}"/>
Name: <c:out value="${b[name].firstName}"/> <c:out
value="${b[name].lastName}"/>

I've tried it and still don't have any troubles doing this.

Hope it is useful.

-- 
Camilo A. Gonzalez
Ing. de Sistemas
Lider Grupo Desarrollo
Dirección Nacional de Admisiones
Univ. Nacional de Colombia
Tel: 300 657 96 96
Tel: 57 1 316 5000 Ext: 18519

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message