aspose file tools*
The moose likes Struts and the fly likes Struts bug? <s:if> string comparison fail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts bug? <s:if> string comparison fail" Watch "Struts bug? <s:if> string comparison fail" New topic
Author

Struts bug? <s:if> string comparison fail

Miltos Tereres
Ranch Hand

Joined: Sep 04, 2009
Posts: 32
Hello...
I am forced to use struts


<jsp:include page="template/menu_top.jsp">
<jsp:param name="menu_key" value="configure"></jsp:param>
</jsp:include>


This calls menu_top.jsp

menu_top.jsp has some TEST code...

|<s:property value="#parameters.menu_key"/>|
|<s:property value="#parameters.menu_key == 'configure'"/>|
|<s:property value="#menu_item.key == 'configure'"/>|

the result is....

|configure|
|false|
|false|


|configure|
|false|
|false|


|configure|
|false|
|false|




|configure|
|false|
|false|


|configure|
|false|
|true|


|<s:property value="#parameters.menu_key == 'configure'"/>|
is never true for some reason.......

The only fix i found is to use #attr instead of #parameters...
am i missing something?
Satya Sakhinetipalli
Greenhorn

Joined: May 16, 2008
Posts: 7
Have you tried this?

<s:property value="#parameters.menu_key == %{'configure'}"/>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Miltos Tereres wrote:am i missing something?

Yes; you're trying to use Struts tags in a page that isn't reached through an action. Just use JSTL.

And please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.
Miltos Tereres
Ranch Hand

Joined: Sep 04, 2009
Posts: 32
i found why ....

#parameters.menuKey is an array!


I dont know why.....

Indeed i dididnt use an action.... but this wasnt the problem...
Now i do



without namespace="/" doesnt work...
dont know why
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Because request parameters can come as an array (multiple with same name and all that).
Miltos Tereres
Ranch Hand

Joined: Sep 04, 2009
Posts: 32
#parameters.menuKey[0] only works... why??? I didnt pass an array:S
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

http://struts.apache.org/2.x/docs/why-doesnt-the-if-tag-evaluate-params-properly.html
Miltos Tereres
Ranch Hand

Joined: Sep 04, 2009
Posts: 32
Books didnt mention that...
I dont know whats happenning...anyways!
I see my older project with struts 2 and i see there that i called parameteres
without
#parameters. prefix and worked fine...Now nothing happens
Miltos Tereres
Ranch Hand

Joined: Sep 04, 2009
Posts: 32
thank you man...
but this worked at
2.1.6 struts

<s:if test="id == selected_id">

selected_id was a parameter also....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts bug? <s:if> string comparison fail