• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

logic:equal not working. Why ?

 
author
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This would work:


and so would this:



- Brent
 
Francesco Marchioni
author
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic