• 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

Broken link in bean tag

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following in a JSP:

<jsp:useBean id="customers" class="java.lang.String[]" scope="request"></jsp:useBean>

I get a warning that "java.lang.String[]" is a broken link :-( What should be the proper type for an array of strings?
[ March 10, 2005: Message edited by: Venu Reddy ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A string array is not a bean.

If you are trying to hook up the scriplet variable 'customers' to a string array already resident on request scope, you can use the 'type' attribute rather than 'class'.
[ March 10, 2005: Message edited by: Bear Bibeault ]
 
Venu Reddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that's what I am trying to do. Even with type = "java.lang.String[]", it's still giving the same warning



Originally posted by Bear Bibeault:
A string array is not a bean.

If you are trying to hook up the scriplet variable 'customers' to a string array already resident on request scope, you can use the 'type' attribute rather than 'class'.

[ March 10, 2005: Message edited by: Bear Bibeault ]


[ March 10, 2005: Message edited by: Venu Reddy ]
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try it without the [] and use EL.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The jsp:useBean tag is for beans. Why not wrap your array in a bean with proper setter/getter methods?

If you don't really want to pull the processing out of the JSP, then just use a scriptlet to pull the array of request scope.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I concur with the "this isn't the way I'd do it" responses.

But, are you sure that it's the useBean tag giving you the error? That's a really weird (meaning bad) way to report such a problem.

Even with type = "java.lang.String[]", it's still giving the same warning



If this is truly the case, your JSP container is broken. Let me guess: Weblogic?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know Jasper will blow up if you try to call an array from a useBean tag.
UseBean will look for the object in the specified scope. If it doesn't find it it will instanciate it for you.

How can you instanciate an array without knowing it's dimensions?
The bean needs to have a zero argument constructor.
[ March 10, 2005: Message edited by: Ben Souther ]
 
Venu Reddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Websphere Application Developer 5.1, the message shows up in tasks pane and points to the corresponding location in the JSP file.

Originally posted by Bear Bibeault:
are you sure that it's the useBean tag giving you the error? That's a really weird (meaning bad) way to report such a problem.

If this is truly the case, your JSP container is broken. Let me guess: Weblogic?


[ March 10, 2005: Message edited by: Venu Reddy ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a further note.
Older versions of Jasper would go ahead and compile the program for you.
You would then get a runtime exception if the JSP page was run before the bean was put in session.

Starting in version 5 of Tomcat, it will fail to compile.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually Tomcat 5 (at least 5.0.28) will allow it -- not saying that's a good thing -- if you use the type attribute. That turns into code that simply casts and assigns the results of the attribute fetch to the specified type. No attempts at instatiation are made as when using the class attribute.

But when push comes to shove, I'd be using the JSTL and EL and avoiding these kinds of problems to begin with.
 
Venu Reddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got around it by changing the type to java.util.Vector in the bean tag and returning Vector i/o array in the corresponding servlet, weird.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not weird, the Vector class has a zero argument constructor.
 
Venu Reddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, thanx for the lesson :-)

Originally posted by Ben Souther:
It's not weird, the Vector class has a zero argument constructor.

 
reply
    Bookmark Topic Watch Topic
  • New Topic