• Post Reply Bookmark Topic Watch Topic
  • New Topic

Return a List or Array from an EL function results in exception  RSS feed

 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys!!

Well, the title is not exactly true, let me explain what is happening.

I have an EL function called toArray(String, pageContext) that function (java method) splits the String into objects and add them to a List, and the function returns that List. The interesting thing is that I use that List in other places of my jsp, concretly in another function that has a List as parameter, there I have the problem, the compiler says that he cannot compile cause cannot cast String to List... it's really weird

Source code:

jsp:


tld:



I call the function, I debug it and see that a real List is being returned and then, in jsp, when calling the function that uses a List as argument... Kaboom!!



I don't understand why EL thinks that the List is an String while I am using other Objects in my application and using them as arguments in other functions and they work perfectly.
I have also tryed to pass an array of Objects but the same happends, I am really curious about why it's parsing the List/Array to String.

Any suggestions? Have any of you seen something like this before?

Thanks for your time.
 
Ankit Garg
Sheriff
Posts: 9608
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I found a similar problem here. So I'm not sure if you can use c:set to set references of type other than Object or String or whatever. I may be wrong as I don't have much idea about this...
 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit,

Thanks for the reply, I know I can do it through scriptless cause I had it like that but I am migrating the code to EL functions so use scriptless is not a possibility hehe, before i had something like this:



and then call the method with the arguments:



and that was working fine, so I don't understand why if I do it with a function something is assumming that is a String when it is a List... it's so weird xDD

Thanks for your response
 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will reply myself as I have found the solution and maybe someone is interested (or maybe not, who knows? ) but I have found the solution in a way I don't understand so maybe knows why the solution is this.

I have change the assignament of the "arguments" var from this:



to:



And it works... so, what is the difference between this two staments? Why in the first case it assums is a String and in the second it realizes that is an Array?

Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the way that the tag works. If you embed the value within the body of the tag, the body text becomes the value. It really can't possibly work any other way. Why does this surprise you?
 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the point is that I am a bit stupid, so I was thinking that with other objects of the application was working in the other way, so I started to be a bit angry with that line of code. Anyway, something more I have learned.

Thanks for the reply
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!