*
The moose likes Struts and the fly likes Jsp useBean and a bean id with a dot in the name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Jsp useBean and a bean id with a dot in the name?" Watch "Jsp useBean and a bean id with a dot in the name?" New topic
Author

Jsp useBean and a bean id with a dot in the name?

Jimi Svedenholm
Ranch Hand

Joined: May 19, 2001
Posts: 53
Hi,

I would like to save an ArrayList object in the request scope, and then use this list in a jsp page. However I want these two things to work to:

1. I want the name of the list to contain dots, like "com.mycompany.whatever.specialarray".

2. If the arraylist does not exist in the request, then the page should *not* fail (as is the case with the struts tag <bean:define>), instead it should create an empty ArrayList.

The second issue made me try <jsp:useBean>, however that one complains when I use the id="com.mycompany.whatever.specialarray". How can I solve this? What I would like is a combination of the struts <bean:define> tag and the <jsp:useBean> tag. For example:

<someTag id="nameToUseHere" name="com.mycompany.whatever.specialarray" class=java.util.ArrayList"/>

Does such a tag exist in struts (version 1) or regular J2EE?

Regards
/Jimi
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Jimi Svedenholm:
...
Does such a tag exist in struts (version 1) or regular J2EE?


I'm thinking this thread will do better in our Struts forum.
Moving.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187



The present element can be used to test for beans and whether they exist or not. If a bean exists in the scope that is specified, then the code will be included in the response.
Jimi Svedenholm
Ranch Hand

Joined: May 19, 2001
Posts: 53
Originally posted by James Clark:



The present element can be used to test for beans and whether they exist or not. If a bean exists in the scope that is specified, then the code will be included in the response.


Ok, thanks! This works. I now use this code:



But it would have been nice if I could have just skipped that <logic:present> tag and make the <bean:define> tag either create an empty ArrayList, or just let it be null.

/Jimi
[ April 29, 2008: Message edited by: Jimi Svedenholm ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
You are welcome.

But it would have been nice if I could have just skipped that <logic_present> tag and make the <bean_define> tag either create an empty ArrayList, or just let it be null.


Struts is an open-source framework and the code for the define element is available. You still have the option of creating your own custom JSP element that functions the way you want it to.

<jimi_define id="... />
[ April 29, 2008: Message edited by: James Clark ]
 
 
subject: Jsp useBean and a bean id with a dot in the name?
 
Similar Threads
JSP:Include question
bean:define cannot instaniate new bean?
Jsp useBean and a bean id with a dot in the name?
bean:define help
Bean value to JSP var