<logic:empty> tag question

S

Steve

In the following code, why it prints "LOGIC: EMPTY" on the console? I
expect to see "LOGIC: NOT EMPTY" since ss is not null, and it should
pass the test <logic:notEmpty name="ss">. What I am missing here?
Please advice. Thanks!!


<%
String ss = "JJ";
System.out.println("from jsp = " + ss);
%>
<%
if (ss == null)
System.out.println("SS = null");
else
System.out.println("SS != null");
%>

<logic:empty name="ss">
<% System.out.println("LOGIC: EMPTY " ); %>
</logic:empty>
<logic:notEmpty name="ss">
<% System.out.println("LOGIC: NOT EMPTY " ); %>
</logic:notEmpty>

<c:if test="ss != null}">
<% System.out.println("JSTL LOGIC: NOT EMPTY " ); %>
</c:if>


output
==========
[8/9/06 16:19:57:470 PDT] 7d42a949 SystemOut O from jsp = JJ
[8/9/06 16:19:57:470 PDT] 7d42a949 SystemOut O SS != null
[8/9/06 16:19:57:470 PDT] 7d42a949 SystemOut O LOGIC: EMPTY
[8/9/06 16:19:57:470 PDT] 7d42a949 SystemOut O JSTL LOGIC: NOT
EMPTY
 
T

Tobias Schierge

Hi,
<%
String ss = "JJ";
System.out.println("from jsp = " + ss);
%>
<%
if (ss == null)
System.out.println("SS = null");
else
System.out.println("SS != null");
%>

<logic:empty name="ss">
<% System.out.println("LOGIC: EMPTY " ); %>
</logic:empty>
<logic:notEmpty name="ss">
<% System.out.println("LOGIC: NOT EMPTY " ); %>
</logic:notEmpty>

<c:if test="ss != null}">
<% System.out.println("JSTL LOGIC: NOT EMPTY " ); %>
</c:if>


You are mixing references to bean variables and locally declared variables.
Please get some deeper understanding of the stuff. Another Advice would be
to ban all scriptlets from JSP to avoid lots of trouble.

try: request.setAttribute("ss","jj"); or
pageContext.setAttribute("ss","jj");

Regards,

Tobias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top