Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

logic:equal compare two values

 
Gayatri Sinha
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

Using the logic:equal I can compare one bean with one value only,
<logic:equal id="beanvalue" value="5">

can I compare the bean to two values

like
(beanvalue=="5" || beanvalue=="6")

I want to use struts tags only..

Thanks
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, <logic:equal> does not have the capability to do "and/or" comparisons. If you want to do an "and" comparison, you can nest one inside the other, but for an "or" comparison your only options are to use a scriptlet or to use JSTL.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In many cases the JSTL is a better choice than the Struts Logic tags. This is one of those cases. In fact if you look at the online docs for the Logic tag library you will see this note at the very top of the page.

Note: - Many of the features in this taglib are also available in the JavaServer Pages Standard Tag Library (JSTL) . The Struts team encourages the use of the standard tags over the Struts specific tags when possible.


Edited to add this: One thing you can do though is to move the logic into your Form...something like this:

In your Action Form:
public boolean getShouldDisplaySection()
{
return (this.beanvalue.equals("5") || this.beanvalue.equals("6"))
}

In your JSP:
<logic:equal name="myForm" property="shouldDisplaySection" value="true">


- Brent
[ March 02, 2006: Message edited by: Brent Sterling ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic