• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pass paramters to arguments in an EL expression

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to pass some arguments from a JSP page into the Java code to get back answers based on the paramters.

I don't see any complete references to how to do this.

I have been writing "getFoo" functions in Java and accessing them in EL with ${something.foo}
But I really want to do ${something.foo(baz)} or square brackets or whatever is needed.

The Sun J2EE pages on JSP and EL give an example of a function, and refer to "in a TLD. The following functions.tld file in the date example ..."

But I'm missing the part of where does the TLD go, etc.

Thanks
pat
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The function is defined in the TLD file and the TLD file is placed in WEB-INF, to be referenced on the JSP page with a taglib directive.

Note the implementing Java method must be public static.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, I'm looking through the FrontMan sources, and don't see any TLD files. Since its my universal sample code, I'll need another. Got one?
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Note the implementing Java method must be public static.

So I need to pass in an Object to serve as "this" within the bean. Most strange, since the
${sessionScope.entity} is already a reference to a proper "entity" object.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Front Man defines no tags or functions.

I'll post an example later today...
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would be great. Thanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an example function that I set up to emit the JSON serialization of any object.

In the TLD file, the function is defined as:


In the CoreELFunctions.java file:


To define the library on a JSP page (or in a JSP prelude):


P.S. No, I don't really have a project named "whatever"... it's just a placeholder.

P.P.S. Gson is Google's JSON library.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Er, I hate to be dense, but how is it used?

Can you please post a fragment of the JSP on how to actually use your function.

I assume that with JSON, you really want to clank the server for the transfer.

What kind of object would you have in your JSP that would want to be returned as a JSON object?

thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Farrell wrote:Can you please post a fragment of the JSP on how to actually use your function.


Sure, something like:

where someScopedVariable is a scoped variable create by the page command or controller.

I assume that with JSON, you really want to clank the server for the transfer.
Not sure what you mean by that.

What kind of object would you have in your JSP that would want to be returned as a JSON object?
It's a quick and easy way to get data from a server-side declaration into a client-side declaration. I particularly use it with Maps. Create the Map on the server, and voila, instant JavaScript object.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Pat Farrell wrote:I assume that with JSON, you really want to clank the server for the transfer.
Not sure what you mean by that.


Again, I'm not fully grok'ing this all, but JSON seems to be hot for Web 2.0 stuff these days, aka AJAX or perhaps AJAJ (since it uses JSON rather than XML).
From what I can tell, AJAX is all about doing background clanks to the server using the magic HTTPrequest() function in javascript.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
To define the library on a JSP page (or in a JSP prelude):

P.S. No, I don't really have a project named "whatever"... it's just a placeholder.


I know its just a placeholder, but I used it, verbatim anyway.

This line in a JSP page results in an error:

<%@ taglib uri="http://whatever.bibeault.org/tld/core" prefix="whatever" %>

org.apache.jasper.JasperException: PWC6188: The absolute uri: http://whatever.bibeault.org/tld/core cannot be resolved in either web.xml or the jar files deployed with this application
/home/pfarrell/sandbox/bbook/branches/pat/fnfapp/build/web/WEB-INF/pages/closed/test.jsp(4,74)


I created a org.bibeault.whatever package, and created a Java class to match the upthread example. Got GSON installed.

Clearly something is not matching, and as I understand it, the URI is just a unique handle, so it should be as good as any other.

What do I need to change?

thanks
pat
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the URI exactly match that in the defining TLD?
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Does the URI exactly match that in the defining TLD?


That was this problem. I made them match, character by character and it stopped with that problem.
Thanks

Now on to the next one.

I am having problems with the syntax of my JSP

Both

<c:set var="user" value="${whatever:toJson(${sessionScope.user}) }" />

and

<c:set var="rawuser" value="${sessionScope.user}" />
<c:set var="user" value="${whatever:toJson( ${rawuser} ) }" />


fail to compile, The error message is not very helpful:
org.apache.jasper.JasperException: }
/home/pfarrell/sandbox/bbook/branches/pat/fnfapp/build/web/WEB-INF/pages/closed/test.jsp(11,3)

So what is the real syntax that it wants to see?
thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're sufferening from a common misconception that ${} is some sort of "fetch" operator that needs to be applied to each scoped variable reference. It isn't. It merely surrounds the entire EL expression.

So:


The ${} is never nested.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thanks.
I'll try that
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!