This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

logic:equal

 
Daniel Silva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I make to use dinamic values with equal tag, for example:
<bean efine id="string" value="<%=1%>" />
<logic:equal name="string" value="1">
The string contained the word Struts
</logic:equal>
in this case, don't print "The string contained the word Struts" at my scren, but if I change the <bean efine id="string" value="<%=1%>" /> for
<bean efine id="string" value="1" /> it's work ok (print the message), What I need to do for make this work fine, I need the dinamic values for compare, maybe I don't need the <bean efine id="string" value="<%=1%>" />,
just compare the logic:equal value with other number, but I don't know what attribute should use for it, parameter="<%=dinamicValue%>" or ???
Cheers
Daniel S.
 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
string is just the java bean object name.
In this java bean, there are couples of attributes/properties.
Therefore, logic:equal is to check the property in this java bean is equal to a value you specified.
e.g.
<logic:equals name="person" property="age" value="30">
I am 30 years old.
</logic:equals>
it will expect there is getter method in this java bean object, person, called getAge().
This is all I know. Hope it can help you.
Benson
 
Wayne Kidd
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To dynamically take different paths in your jsp with logic:equal you need a bean that gets its value from somewhere else in the application. So, for example, if there is a bean in some scope that has been set in an action:
String yesno = null;
if (a == "Bob") yesno = "yes";
else yesno = "no";
request.getSession().setAttribute("RESULT", yesno);
then tags like these might make sense:

<logic:equal name="RESULT" value="yes" >
<td>Written by Bob</td>
</logic:equal>
<logic:equal name="RESULT" value="no" >
<td>Not written by Bob</td>
</logic:equal>
 
Daniel Silva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, but my problem is:
I'm use the equal inside the logic:iterate and print 3 html coluns and change line, something like this (modulos is a Vector):
<%int rest=0;%>
<logic:iterate id="listModulos" name="modulos" indexId="index" >
<% int line = index.intValue() % 3; %>
<%=line%>
<logic:equal parameter="<%=line%>" value="<%=rest%>" >
<br> Printed <here I'll get attribute of my bean>!
</logic:equal>

<logic:notEqual parameter="<%=line%>" value="<%=rest%>" >
Printed <here I'll get attribute of my bean>!!
</logic:notEqual>

</logic:iterate>
If someone have other ideia to make it with logic:iterate ....
cheers
Daniel S.
 
Detlev Detleffsen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe this answer appears somewhat late, but I was just having the same problem and my solution is.

<%int rest=0;%>
<logic:iterate id="listModulos" name="modulos" indexId="index" >

<% request.setAttribute("line", new Integer(index.intValue()%3)); %>

<logic:equal name="line" value="<%=rest%>" >
<br> Printed <here I'll get attribute of my bean>!
</logic:equal>


<logic:notEqual name="line" value="<%=rest%>" >
Printed <here I'll get attribute of my bean>!!
</logic:notEqual>

</logic:iterate>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic