Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

logic:equal not working. Why ?

 
Francesco Marchioni
author
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would work:


and so would this:



- Brent
 
Francesco Marchioni
author
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,


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

Regards
Jatan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic