Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Broken link in bean tag  RSS feed

 
Venu Reddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Colin Fletcher
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it without the [] and use EL.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!