struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Schneider <k...@dotech.com>
Subject Re: JSTL evaluate problems
Date Fri, 17 Oct 2003 19:27:52 GMT
Here's a quick test page that emulates what it sounds like you want to do. The
<bean:write> seems to work fine.

<%@ page contentType="text/plain" %>
<%@ taglib prefix="bean" uri="http://jakarta.apache.org/struts/tags-bean" %>
<%@ taglib prefix="c"    uri="http://java.sun.com/jstl/core" %>

<jsp:useBean id="person" class="java.util.HashMap">
    <jsp:useBean id="name" class="java.util.HashMap">
        <c:set target="${name}" property="firstName" value="Kris"/>
        <c:set target="${name}" property="lastName" value="Schneider"/>
    </jsp:useBean>
    <c:set target="${person}" property="name" value="${name}"/>
</jsp:useBean>

<c:set var="nestedProp" value="name.firstName"/>

person:                <c:out value="${person}"/>
person.name:           <c:out value="${person.name}"/>
person.name.firstName: <c:out value="${person.name.firstName}"/>

<jsp:useBean id="nestedProp" type="java.lang.String"/>
bean:write: <bean:write name="person" property="<%= nestedProp %>"/>

Quoting struts@sixty4bit.com:

> Never mind... that didn't fix it either.  property is a property of target,
> which is another object.
> 
> Carl
> 
> Quoting struts@sixty4bit.com:
> 
> > Kris,
> > 
> > Thanks for your tip.  You lead me to the answer.  Here is what works:
> > 
> > <c:set var="person" value="${requestScope.personForm}"/>
> > <c:set var="nestedProp" value="name.firstName"/>
> > <c:set var="val" value="${nestedProp}" property="${person}" />
> > 
> > Now, we can all stand around and scratch our heads and say "Duh! Why
> didn't
> > I
> > think of that?"  Setting the person as the property tells JSTL to use
> > person
> > as a bean and allows it to do normal nested queries on nestedProp.  Oh
> man
> > do
> > I feel like a dummy.
> > 
> > Carl
> > 
> > Quoting Kris Schneider <kris@dotech.com>:
> > 
> > > Then I don't see how to make it work with JSTL. So, "nestedProp" is a
> > > scoped
> > > variable containing the nested property you want to access, right? Does
> > > this
> > > work for you:
> > > 
> > > <jsp:useBean id="nestedProp" type="java.lang.String"/>
> > > <bean:write name="personForm" property="<%= nestedProp %>"/>
> > > 
> > > Unfortunately, I don't think Struts-EL provides a version of
> > <bean:write>
> > > or you
> > > could also try:
> > > 
> > > <bean-el:write name="personForm" property="${nestedProp}"/>
> > > 
> > > Quoting struts@sixty4bit.com:
> > > 
> > > > No.  The variable that is actually nestedProp is populated
> > dynamically.
> > > 
> > > > Most
> > > > of the time it is just a single property name, but from time to time,
> > > it
> > > > needs
> > > > to be nested.
> > > > 
> > > > Carl
> > > > 
> > > > Quoting Kris Schneider <kris@dotech.com>:
> > > > 
> > > > > Are you just trying to shorthand this:
> > > > > 
> > > > > <c:out value="${person.name.firstName}"/>
> > > > > 
> > > > > In other words, person.getName().getFirstName().
> > > > > 
> > > > > Quoting struts@sixty4bit.com:
> > > > > 
> > > > > > JSTL is not nesting appropriately.  Here is an example of what
I
> > am
> > > > > doing:
> > > > > > 
> > > > > > <c:set var="person" value="${requestScope.personForm}"/>
> > > > > > <c:set var="nestedProp" value="name.firstName"/>
> > > > > > <c:out value="${person[nestedProp]}"/>
> > > > > > 
> > > > > > The error that I am getting is:
> > > > > > Unable to find a value for "name.firstName" in object of class
> > > > > > "org.team.Person" using operator "[]" (null)
> > > > > > 
> > > > > > If nestedProp was just firstName (and Person had a firstName
> > > property)
> > > > > then
> > > > > > this works just fine.  JSTL is not seeing the . and doing
> > > > > > getName().getFirstName()
> > > > > > 
> > > > > > I have tried a number of combinations with [] and ' (escape)
and
> > \
> > > and
> > > > > ....
> > > > > > nothing works :(  Any help appreciated.
> > > > > > 
> > > > > > 
> > > > > > Carl
> > > > > 
> > > > > -- 
> > > > > Kris Schneider <mailto:kris@dotech.com>
> > > > > D.O.Tech       <http://www.dotech.com/>
> > > 
> > > -- 
> > > Kris Schneider <mailto:kris@dotech.com>
> > > D.O.Tech       <http://www.dotech.com/>

-- 
Kris Schneider <mailto:kris@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message