File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes calling a bean function using jstl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "calling a bean function using jstl" Watch "calling a bean function using jstl" New topic
Author

calling a bean function using jstl

Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
Hi

i m calling a bean function and getting the error
The function ast must be used with a prefix when a default namespace is not specified

I m using using glassfish v2.1
I have the bean



The taglib


in jsp im having



the line ${u.ast()} gives the error message (thanks to Bear Bibeault)



else everything works fine such as



Any help

Thanks
Pradyut


Pradyut
http://pradyut.tk/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

Pradyut Bhattacharya wrote: the line ${u.ast()} gives the problem

In the future, please be sure to include the error message -- not just say "gives a problem". (Please read this for more information.)

But in this case, I can tell you that the problem is that EL functions must be static. You can't call instance methods.




Why are you using getProperty in place of the EL?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
thanks for the fast reply

changed the code to



but still could not get solved. The same error message



thanks for quoting the getProperty but i was just showing they are working just fine...

regards
Pradyut

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

You need to use the TLD's namespace to invoke the function.
Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
could not understand tld namespace or wheres it located...

new to tld and namespaces :-(
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

You created the namespace when you mapped the TLD:

So to call the function:


By the way, the URI you chose doesn't follow the usual convention. It should look like a URL (even though it's not a URL) using a domain that you own. That way, there's never any chance of it conflicting with some other library's URI.

Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63

Changed the uri to "http://pradyut.dyndns.org/newtag_library"

Thanks but still no change... the same error message
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

You'll need to show your new files.

Are you sure that you are using a colon and not a dot to separate the namespace from the function name?
Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
wow.. i didnt know the use of colons like that...
well the new exception thrown is...

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

That's because it's not declared in your TLD. You must add a function element to define the function otherwise how is the JSP engine supposed to know anything about it?
Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
but in my tld i have



Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
sorry about that... now my tld is...



and in jsp i m calling



and still the error message



please rescue...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

Looks pretty clear to me; the class cannot be found. Did you compile the bean and put the class file in the correct location?
Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
thanks Bear Bibeault

you rocked it!!!

the tld should be

Varun Selva
Ranch Hand

Joined: Jun 17, 2012
Posts: 42

This is the late comment.
I also found this same problem.
I got the solution by defining the method as static.


Varun Selva
 
 
subject: calling a bean function using jstl
 
Similar Threads
Custom Tag
JSTL Syntax
tld file error
about EL Function
Problem is running EL FUnction