File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Problem with logic:present Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with logic:present" Watch "Problem with logic:present" New topic

Problem with logic:present

matt love
Ranch Hand

Joined: Jan 25, 2010
Posts: 67
I've condensed the code to its barest essentials to illustrate my problem as clearly as I can.

My addAssignment.jsp is showing the header "Messages" when the LinkedList should be, and appears to be, empty. If there are no messages in the LinkedList, I expect the logic:present tag to preclude the printing of the header "Messages". How do I prevent the header "Messages" from printing if there are no messages in the LinkedList?

The struts-config file.

The LoginAction file illustrates how I use the LinkedList. Also, the LoginAction works correctly with the Login.jsp page, the LinkedList and the Logic and Bean tags. That is, when error messages were present in the LinkedList, the Login.jsp page showed them corretly under the header Messages.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60740

Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Matt,
Hope this issue is already solved. If not, Logic present would return true if the specified attribute is present in the scope mentioned (in your case it is "messages" in scope "request"). So you could use list size/logic:empty to identify empty lists to display your header

Have Fun with Java
little,little.. little by little makes a lot..
matt love
Ranch Hand

Joined: Jan 25, 2010
Posts: 67
Thanks Shankar for you reply.

What do you mean by "list size"?

Are you referring to java code like: int x = listName.size();



Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

"Perfectly yes" when we talk about the logic behind it. But to implement the "same" you would use scriplets. However, never use such code in your JSP's. Struts equivalent would be something like OR if not sure about this use bean define to capture the size and work in similar fashion.
subject: Problem with logic:present
Similar Threads
web portal in struts and nothing is working at all
problem log out
javax.servlet.jsp.JspException: No getter method for property: "id" of bean: "Login.LoginForm"
Problem with logic:present tag
javax.servlet.ServletException:javax.servlet.jsp.JspException: Cannot find bean: "riga" in any scope