| Author |
pass value to a java method in EL(using TLD)
|
sammeta Phanikumar
Ranch Hand
Joined: Oct 25, 2007
Posts: 81
|
|
Hi, I'm getting the value from request, by passing this value I want to call a java method(getSquere()). In the jsp where I am calling the java method using prefix and want to pass the value which comes with request to method. I have used EL and <%= %> to get the values and pass an arguemnt but none of them is working. Here is code line which I've used. ${mine:getSquere( ${param.number} )} ${mine:getSquere{ <%= request.getParameter("number") %> }. Please help me how do Iget it without using scriptlets. Regards, Phani
|
SCJP 5, SCWCD 5, SCDJWS 5
|
 |
Hongli Li
Ranch Hand
Joined: Oct 29, 2006
Posts: 124
|
|
creat a tld file to describe your funtion(getSquere). in the jsp page declare the tag like this <%@ taglib prefix="mine" uri="/mine.tld" %> then <c:set var="name" value="${param.number}"/> ${mine:getSquere{${name}}} hope this will help
|
Do you know why this cup is useful? Because it is empty.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56153
|
|
Originally posted by Hongli Li: creat a tld file to describe your funtion(getSquere).
That will not work. You cannot use the EL to call instance methods at all. EL functions must be static functions and I'm pretty sure that's not what you are describing. And
${mine:getSquere{${name}}}
This is not valid syntax. Your best bet is to figure why you need to call a general function in JSP and see if you can get by without it by factoring processing out into the page controller. Otherwise, you might look into an EL function (keeping in mind their limitations) or a custom tag. Finding something on a JSP page that you can do with a scriptlet but not the EL is usually a red flag that you are doing something in the JSP that should be done in a Java class. Think long and hard about that. [ March 18, 2008: Message edited by: Bear Bibeault ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Hongli Li
Ranch Hand
Joined: Oct 29, 2006
Posts: 124
|
|
let me revise some typos
${mine:getSquere{${name}}}
should be ${mine:getSquere(name)} the java class should be something like : then the tld file <?xml version="1.0" encoding="UTF-8"?> <taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0"> <description>Utility functions</description> <display-name>Utility Tag Library</display-name> <tlib-version>1.0</tlib-version> <short-name>utility</short-name> <function> <name>mine</name> <function-class>youupackage.Util</function-class> <function-signature>java.lang.String getSuere(java.lang.String)</function-signature> </function> </taglib> then in jsp call <c:set var="name" value="${param.name}"/> ${mine:getSquere(name)} [ March 18, 2008: Message edited by: Hongli Li ]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56153
|
|
(You've still got typos) It's important to note that EL functions must be static. [ March 18, 2008: Message edited by: Bear Bibeault ]
|
 |
Hongli Li
Ranch Hand
Joined: Oct 29, 2006
Posts: 124
|
|
Originally posted by Bear Bibeault: (You've still got typos) It's important to note that EL functions must be static. [ March 18, 2008: Message edited by: Bear Bibeault ]
I used some code I used before, so where is the typo, the method is declared as static. Please point out for me
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56153
|
|
should be ${mine:getSquere(name)}
<function> <name> mine</name> <function-class>youupackage.Util</function-class> <function-signature> java.lang.String getSuere( java.lang.String)</function-signature> </function>
|
 |
Hongli Li
Ranch Hand
Joined: Oct 29, 2006
Posts: 124
|
|
Originally posted by Hongli Li: let me revise some typos should be ${mine:getSuere (name)} the java class should be something like : then the tld file <?xml version="1.0" encoding="UTF-8"?> <taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0"> <description>Utility functions</description> <display-name>Utility Tag Library</display-name> <tlib-version>1.0</tlib-version> <short-name>utility</short-name> <function> <name> mine</name> <function-class>youupackage.Util</function-class> <function-signature> java.lang.String getSuere( java.lang.String)</function-signature> </function> </taglib> then in jsp call <c:set var="name" value="${param.name}"/> ${mine:getSuere (name)} [ March 18, 2008: Message edited by: Hongli Li ]
method name is consistent now
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: pass value to a java method in EL(using TLD)
|
|
|