This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes logic:equal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "logic:equal" Watch "logic:equal" New topic
Author

logic:equal

Daniel Silva
Greenhorn

Joined: Nov 10, 2003
Posts: 9
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

Joined: Apr 10, 2003
Posts: 207
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

Joined: Aug 17, 2003
Posts: 7
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

Joined: Nov 10, 2003
Posts: 9
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

Joined: Jun 01, 2004
Posts: 1
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>
 
 
subject: logic:equal
 
Similar Threads
Accessing bean in logic Tag
c:if tag not working as expected
Adding a String Scripting Variable
logic:equal compare two values
Struts - logic:equal and Scriplet question