GeeCON Prague 2014*
The moose likes Struts and the fly likes logic:equal not working. Why ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "logic:equal not working. Why ?" Watch "logic:equal not working. Why ?" New topic
Author

logic:equal not working. Why ?

Francesco Marchioni
author
Ranch Hand

Joined: Sep 22, 2003
Posts: 191
Hi all !
I'm not able to replace the JSP code if (var) with the equivalente logic:equal.
Simply it doesn't work for me. Why.
Look at this:

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%
String name="frank";
%>
<logic:equal parameter="name" value="frank">hello frank!</logic:equal>
<logic:notEqual parameter="name" value="frank">anonymous</logic:notEqual>

I get displayed "anonymous". Why ??
Thanks
Francesco


WildFly 8 Administration Book - JBoss Tutorials
Tarun Yadav
Ranch Hand

Joined: Sep 20, 2007
Posts: 134
I've never used Struts tags but a look over here shows that the parameter attribute refers to the name of a request parameter.

Also, if Struts tags are anything like the JSTL, then you can't access scriptlet variables in the tags; they only work with attributes in the various scopes.

So your first condition fails, probably because the parameter evaluates for false.

EDIT: I guess if you were to use the 'name' attribute instead of the 'parameter' attribute and put the String into a scope you'd see it work correctly.


[ October 22, 2007: Message edited by: Tarun Yadav ]
Francesco Marchioni
author
Ranch Hand

Joined: Sep 22, 2003
Posts: 191
Hello, thanks for your reply.
Sorry I posted the wrong jsp file. This is the one I've used.

<%
String name="frank";

%>
<logic:equal name="name" value="frank">hello frank!</logic:equal>
<logic:notEqual name="name" value="frank">anonymous</logic:notEqual>

The one I posted was my last attempt (using parameter instead which is the equivalent of request.getParameter).

Anyway if I set the variable "name" inside pageContext it DOES works.
Yet it's a bit annoying because I have to replace all variable assignment with pageContex.setAttribute......maybe I'll find an easier way to do it.
Thanks a lot anywat
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
This would work:


and so would this:



- Brent
Francesco Marchioni
author
Ranch Hand

Joined: Sep 22, 2003
Posts: 191
Sorry, this:

<bean efine id="name" value="frank" /><logic:equal name="name" value="frank">hello frank!</logic:equal><logic:notEqual name="name" value="frank">anonymous</logic:notEqual>

seems not to work...anyway I have solved, when the variables are inserted from the action with request.setAttribute, then in the jsp called logic:equal works correctly
hw khan
Greenhorn

Joined: Oct 03, 2007
Posts: 9
Hello Francesco,

Iam facing similar problem as your,
My JSP is not entering the logic resent block at all

I have tried your solution but it's not working for me .

can you help me on this ?
I have also posted my query in the forum with the details of my jsp page.

Thanks
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Really? That did not work for you? I cut and pasted both of my samples into a JSP file and in both cases the string "hello frank!" was shown.

You can also set the values on your form. I generally prefer defining properties on a form rather than directly setting and getting attributes on the request.

- Brent
Trisha Sharma
Greenhorn

Joined: Mar 20, 2013
Posts: 1
I am also facing same problem.. <logic:equal> tag is not working in my case also.. will you please tell me what did you do??
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi ,


Refer this Link , which will give you idea and let us know if you cant make it work.

Regards
Jatan
 
 
subject: logic:equal not working. Why ?