Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NOT EMPTY or NOT NULL?

 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am uncertain about a JSTL tag that I am using.

From a Struts action, I pass a Collection "logdata" in a request scope to my JSP page. Of course, I stored that Collection in an object" "LogData".

The Collection "logdata" can be a null because if I do not find any records in the database table, I return a null.

Now, I am looking at my JSP page (see the code below). I first set a variable called "logRows" and then test it using "${not empty logRows}". Is it correct?

 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could do both...
${not empty logRows || logRows != null}
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"not empty" also does a null check, making it VERY useful. In fact, I never write null checks in JSTL because I always use "not empty".

So your usage is correct.
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use the NOT EMPTY to do the testing. But, I got an Internal Server Error 500 problem (The log is shown after my code snippet.) I am unable to see the problem with my <c:when ....> tag.




Root cause of ServletException.
javax.servlet.jsp.JspTagException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "test" with value "${NOT EMPTY log
Rows}": Encountered "EMPTY", expected one of ["}", ".", ">", "gt", "<", "lt", "=
=", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/", "div", "%
", "mod", "and", "&&", "or", "||", ":", "("] (null)
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lowercase, partner.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic