You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by st...@sixty4bit.com on 2003/10/17 18:35:35 UTC

JSTL evaluate problems

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 

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


Re: JSTL evaluate problems

Posted by st...@sixty4bit.com.
Thank you Kris!  

Quoting Kris Schneider <kr...@dotech.com>:

> 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 <kr...@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 <kr...@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 <ma...@dotech.com>
> > > > > > D.O.Tech       <http://www.dotech.com/>
> > > > 
> > > > -- 
> > > > Kris Schneider <ma...@dotech.com>
> > > > D.O.Tech       <http://www.dotech.com/>
> 
> -- 
> Kris Schneider <ma...@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
> 
> 




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


Re: JSTL evaluate problems

Posted by Kris Schneider <kr...@dotech.com>.
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 <kr...@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 <kr...@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 <ma...@dotech.com>
> > > > > D.O.Tech       <http://www.dotech.com/>
> > > 
> > > -- 
> > > Kris Schneider <ma...@dotech.com>
> > > D.O.Tech       <http://www.dotech.com/>

-- 
Kris Schneider <ma...@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


Re: JSTL evaluate problems

Posted by st...@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 <kr...@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 <kr...@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 <ma...@dotech.com>
> > > > D.O.Tech       <http://www.dotech.com/>
> > 
> > -- 
> > Kris Schneider <ma...@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
> > 
> > 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 




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


Re: JSTL evaluate problems

Posted by st...@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 <kr...@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 <kr...@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 <ma...@dotech.com>
> > > D.O.Tech       <http://www.dotech.com/>
> 
> -- 
> Kris Schneider <ma...@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
> 
> 




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


Re: JSTL evaluate problems

Posted by Kris Schneider <kr...@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 <kr...@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 <ma...@dotech.com>
> > D.O.Tech       <http://www.dotech.com/>

-- 
Kris Schneider <ma...@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


Re: JSTL evaluate problems

Posted by st...@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 <kr...@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 <ma...@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
> 
> 




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


Re: JSTL evaluate problems

Posted by Kris Schneider <kr...@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 <ma...@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