You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by PhoenixelRay <si...@web.de> on 2008/11/14 11:39:05 UTC

Struts2 OGNL Problem

Hi,

i have a little question because of a Problem I faced with OGNL in
Struts 2. I have tried a lot of things but it didn work.

OK. I´ve set up a new Struts 2 Project with Tomcat 6.0 and integrated
Tiles 2. I want to use the menuing support of tiles.
This is the relevant code of the tiles-defs.xml:
------------------------
<definition name="menue" template="/tiles/menue.jsp">
  <put-list-attribute name="myListAttribute">
        <item value="menue.uebersicht" link="uebersicht.action" />
        ...
  </put-list-attribute>
</definition>
------------------------

Here I want to define all sections of the main menue. The value of the
item property should be a ressource key which I have in the
"package.property" file in my project directory (WEB-INF/src/java).  

The code of the the menue.jsp is:
------------------------
<tiles:importAttribute name="myListAttribute" />
        <c:forEach var="item" items="${myListAttribute}">
        <s:property value="${item.value}"/>
        <br/>
        </c:forEach>
------------------------

This loop should integrate the menu sections.

The exception I get is:
/tiles/menue.jsp(18,30) According to TLD or attribute directive in tag
file, attribute value does not accept any expressions

Without <s:property/> it would work.

I think the Problem is that the Struts-Tags dont support EL. Is it
possible to solve this Problem with OGNL? I dont know how I can access
the "item.link" and "item.value" properties with OGNL. Is there a way to
use EL with Stuts 2?

So many questions. I didnt find a solution in the net for this specific
problem and the OGNL documentation is not very helpfull for me. Maybe
someone can give me a little clue.

Thank you in advance.

Best regards

Ray
-- 
View this message in context: http://www.nabble.com/Struts2-OGNL-Problem-tp20498124p20498124.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 OGNL Problem

Posted by PhoenixelRay <si...@web.de>.
This helped me a lot, thank you! =)

Now the list is iterated and i get the output as a ressource. The solution
was:

<tiles:importAttribute name="myListAttribute"/>
<s:iterator value="%{#attr.myListAttribute}">
  <s:a href="#link"><s:text name="%{#attr.value}"/></s:a>
</s:iterator> 

Greets Ray



Jeromy Evans - Blue Sky Minds wrote:
> 
> PhoenixelRay wrote:
>> I tryed it like this <s:iterator value="%{#attr.myListAttribute}"> with
>> the
>> same Problem.
>>
>>   
> 
> <tiles:importAttribute> places the object into page scope if not 
> specified otherwise.
> 
> This means in OGNL it's only available via #attr.
> 
> First, confirm you can access the attribute from JSP EL and that's the 
> object is type that can be iterated over.
> 
> Then <s:iterator value="#attr.myListAttribute"> will definitely iterate 
> over it.
> 
> Within your sample code you referenced #item but that doesn't exist. 
> When inside the iteration, the top of the stack is the item being 
> iterated over, so
> <s:property value="link"/> will get the property name "link" of the 
> current item, and so on.
> 
> Hope that helps,
> Jeromy Evans
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts2-OGNL-Problem-tp20498124p20557573.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 OGNL Problem

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
PhoenixelRay wrote:
> I tryed it like this <s:iterator value="%{#attr.myListAttribute}"> with the
> same Problem.
>
>   

<tiles:importAttribute> places the object into page scope if not 
specified otherwise.

This means in OGNL it's only available via #attr.

First, confirm you can access the attribute from JSP EL and that's the 
object is type that can be iterated over.

Then <s:iterator value="#attr.myListAttribute"> will definitely iterate 
over it.

Within your sample code you referenced #item but that doesn't exist. 
When inside the iteration, the top of the stack is the item being 
iterated over, so
<s:property value="link"/> will get the property name "link" of the 
current item, and so on.

Hope that helps,
Jeromy Evans


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


Re: Struts2 OGNL Problem

Posted by Lukasz Lenart <lu...@googlemail.com>.
2008/11/18 PhoenixelRay <si...@web.de>:
> I tryed it like this <s:iterator value="%{#attr.myListAttribute}"> with the
> same Problem.
> Is this maybe a tiles problem?

Did you try to use <s:debug/> tag on that page?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: Struts2 OGNL Problem

Posted by PhoenixelRay <si...@web.de>.
I tryed it like this <s:iterator value="%{#attr.myListAttribute}"> with the
same Problem.
Is this maybe a tiles problem?


Lukasz Lenart wrote:
> 
> 2008/11/18 PhoenixelRay <si...@web.de>:
>> No output and error message with both :-((
> 
> Did you try with #attr or #request ?
> 
> 
> Regards
> -- 
> Lukasz
> http://www.lenart.org.pl/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts2-OGNL-Problem-tp20498124p20556631.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 OGNL Problem

Posted by Lukasz Lenart <lu...@googlemail.com>.
2008/11/18 PhoenixelRay <si...@web.de>:
> No output and error message with both :-((

Did you try with #attr or #request ?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: Struts2 OGNL Problem

Posted by PhoenixelRay <si...@web.de>.
No output and error message with both :-((


Lukasz Lenart wrote:
> 
> 2008/11/18 PhoenixelRay <si...@web.de>:
>>
>> i tried it like this, but it didnt work.
>>
>> <tiles:importAttribute name="myListAttribute" />
>> <s:iterator value="#myListAttribute">
>> #item.link <s:text name="#item.value"/>
>> </s:iterator>
> 
> Try with force evaluation
> 
> <tiles:importAttribute name="myListAttribute" />
> <s:iterator value="%{#myListAttribute}">
>   <s:property value="%{#item.link}"/> <s:text name="%{#item.value}"/>
> </s:iterator>
> 
> 
> Regards
> -- 
> Lukasz
> http://www.lenart.org.pl/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts2-OGNL-Problem-tp20498124p20556221.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 OGNL Problem

Posted by Lukasz Lenart <lu...@googlemail.com>.
2008/11/18 PhoenixelRay <si...@web.de>:
>
> i tried it like this, but it didnt work.
>
> <tiles:importAttribute name="myListAttribute" />
> <s:iterator value="#myListAttribute">
> #item.link <s:text name="#item.value"/>
> </s:iterator>

Try with force evaluation

<tiles:importAttribute name="myListAttribute" />
<s:iterator value="%{#myListAttribute}">
  <s:property value="%{#item.link}"/> <s:text name="%{#item.value}"/>
</s:iterator>


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: Struts2 OGNL Problem

Posted by PhoenixelRay <si...@web.de>.
i tried it like this, but it didnt work.

<tiles:importAttribute name="myListAttribute" />
<s:iterator value="#myListAttribute">
#item.link <s:text name="#item.value"/> 
</s:iterator>



newton.dave wrote:
> 
> --- On Fri, 11/14/08, PhoenixelRay wrote:
>> in this case I have to use OGNL to get access to the list
>> which is defined in the tiles-defs.xml.
> 
> IIRC you can put Tiles defs into scope through one of the tiles tags
> (don't recall how). You can then access it via one of the OGNL scope
> prefixes.
> 
> Dave
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts2-OGNL-Problem-tp20498124p20555087.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 OGNL Problem

Posted by Dave Newton <ne...@yahoo.com>.
--- On Fri, 11/14/08, PhoenixelRay wrote:
> in this case I have to use OGNL to get access to the list
> which is defined in the tiles-defs.xml.

IIRC you can put Tiles defs into scope through one of the tiles tags (don't recall how). You can then access it via one of the OGNL scope prefixes.

Dave


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


Re: Struts2 OGNL Problem

Posted by PhoenixelRay <si...@web.de>.
thanks,

in this case I have to use OGNL to get access to the list which is defined
in the tiles-defs.xml.
I have already tried it in different ways but i didnt get the correct
syntax. 




newton.dave wrote:
> 
> --- On Fri, 11/14/08, PhoenixelRay wrote:
>> I know, but I thougt the only way to use resources is the
>> struts tag and this is not possible with el. Therefore I 
>> wantet to know if there is an other way than this example. 
> 
> Yes, by using <s:iterator...> and <s:property...>.
> 
> But your assumption is incorrect: JSP EL is only disallowed *inside S2
> tags*.
> 
> Dave
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts2-OGNL-Problem-tp20498124p20501757.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 OGNL Problem

Posted by Dave Newton <ne...@yahoo.com>.
--- On Fri, 11/14/08, PhoenixelRay wrote:
> I know, but I thougt the only way to use resources is the
> struts tag and this is not possible with el. Therefore I 
> wantet to know if there is an other way than this example. 

Yes, by using <s:iterator...> and <s:property...>.

But your assumption is incorrect: JSP EL is only disallowed *inside S2 tags*.

Dave


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


Re: Struts2 OGNL Problem

Posted by PhoenixelRay <si...@web.de>.
I know, but I thougt the only way to use resources is the struts tag and this
is not possible with el. Therefore I wantet to know if there is an other way
than this example. 


newton.dave wrote:
> 
> --- On Fri, 11/14/08, PhoenixelRay wrote:
>> Yes, it works that way, but how can i include the resource
>> key without using OGNL?
> 
> The forEach example already doesn't use OGNL.
> 
> Dave
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts2-OGNL-Problem-tp20498124p20501202.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 OGNL Problem

Posted by Dave Newton <ne...@yahoo.com>.
--- On Fri, 11/14/08, PhoenixelRay wrote:
> Yes, it works that way, but how can i include the resource
> key without using OGNL?

The forEach example already doesn't use OGNL.

Dave


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


Re: Struts2 OGNL Problem

Posted by PhoenixelRay <si...@web.de>.
Yes, it works that way, but how can i include the resource key without using
OGNL?



stanlick wrote:
> 
> Have you tried using <s:iterator/>
> 
> Also, this works as well:
> 
>                 <c:forEach items="${employees}" var="currRow"
> varStatus="loopStatus">
>                     <tr>
>                         <td>
>                             ${currRow.id}
>                         </td>...
> 
> Peace,
> Scott
> 
> On Fri, Nov 14, 2008 at 4:39 AM, PhoenixelRay
> <si...@web.de>wrote:
> 
>>
>> Hi,
>>
>> i have a little question because of a Problem I faced with OGNL in
>> Struts 2. I have tried a lot of things but it didn work.
>>
>> OK. I´ve set up a new Struts 2 Project with Tomcat 6.0 and integrated
>> Tiles 2. I want to use the menuing support of tiles.
>> This is the relevant code of the tiles-defs.xml:
>> ------------------------
>> <definition name="menue" template="/tiles/menue.jsp">
>>  <put-list-attribute name="myListAttribute">
>>        <item value="menue.uebersicht" link="uebersicht.action" />
>>        ...
>>  </put-list-attribute>
>> </definition>
>> ------------------------
>>
>> Here I want to define all sections of the main menue. The value of the
>> item property should be a ressource key which I have in the
>> "package.property" file in my project directory (WEB-INF/src/java).
>>
>> The code of the the menue.jsp is:
>> ------------------------
>> <tiles:importAttribute name="myListAttribute" />
>>        <c:forEach var="item" items="${myListAttribute}">
>>        <s:property value="${item.value}"/>
>>        <br/>
>>        </c:forEach>
>> ------------------------
>>
>> This loop should integrate the menu sections.
>>
>> The exception I get is:
>> /tiles/menue.jsp(18,30) According to TLD or attribute directive in tag
>> file, attribute value does not accept any expressions
>>
>> Without <s:property/> it would work.
>>
>> I think the Problem is that the Struts-Tags dont support EL. Is it
>> possible to solve this Problem with OGNL? I dont know how I can access
>> the "item.link" and "item.value" properties with OGNL. Is there a way to
>> use EL with Stuts 2?
>>
>> So many questions. I didnt find a solution in the net for this specific
>> problem and the OGNL documentation is not very helpfull for me. Maybe
>> someone can give me a little clue.
>>
>> Thank you in advance.
>>
>> Best regards
>>
>> Ray
>> --
>> View this message in context:
>> http://www.nabble.com/Struts2-OGNL-Problem-tp20498124p20498124.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts2-OGNL-Problem-tp20498124p20500060.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts2 OGNL Problem

Posted by st...@gmail.com.
Have you tried using <s:iterator/>

Also, this works as well:

                <c:forEach items="${employees}" var="currRow"
varStatus="loopStatus">
                    <tr>
                        <td>
                            ${currRow.id}
                        </td>...

Peace,
Scott

On Fri, Nov 14, 2008 at 4:39 AM, PhoenixelRay <si...@web.de>wrote:

>
> Hi,
>
> i have a little question because of a Problem I faced with OGNL in
> Struts 2. I have tried a lot of things but it didn work.
>
> OK. I´ve set up a new Struts 2 Project with Tomcat 6.0 and integrated
> Tiles 2. I want to use the menuing support of tiles.
> This is the relevant code of the tiles-defs.xml:
> ------------------------
> <definition name="menue" template="/tiles/menue.jsp">
>  <put-list-attribute name="myListAttribute">
>        <item value="menue.uebersicht" link="uebersicht.action" />
>        ...
>  </put-list-attribute>
> </definition>
> ------------------------
>
> Here I want to define all sections of the main menue. The value of the
> item property should be a ressource key which I have in the
> "package.property" file in my project directory (WEB-INF/src/java).
>
> The code of the the menue.jsp is:
> ------------------------
> <tiles:importAttribute name="myListAttribute" />
>        <c:forEach var="item" items="${myListAttribute}">
>        <s:property value="${item.value}"/>
>        <br/>
>        </c:forEach>
> ------------------------
>
> This loop should integrate the menu sections.
>
> The exception I get is:
> /tiles/menue.jsp(18,30) According to TLD or attribute directive in tag
> file, attribute value does not accept any expressions
>
> Without <s:property/> it would work.
>
> I think the Problem is that the Struts-Tags dont support EL. Is it
> possible to solve this Problem with OGNL? I dont know how I can access
> the "item.link" and "item.value" properties with OGNL. Is there a way to
> use EL with Stuts 2?
>
> So many questions. I didnt find a solution in the net for this specific
> problem and the OGNL documentation is not very helpfull for me. Maybe
> someone can give me a little clue.
>
> Thank you in advance.
>
> Best regards
>
> Ray
> --
> View this message in context:
> http://www.nabble.com/Struts2-OGNL-Problem-tp20498124p20498124.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>