• Post Reply Bookmark Topic Watch Topic
  • New Topic

best practices min, max function?

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the current "best" way to access the usual max and min functions, like as in java.lang.Math
package.

I could use scrptlets but that seem so last century.

Thanks
Pat
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Farrell wrote:I could use scrptlets but that seem so last century.

Indeed they are!

As the methods in the Math class are static, they are easily mapped to EL functions (which are declared in a TLD just like custom tags and tag files).

So let's say you create a TLD for the Math methods that you map to prefix math. A call would look like:

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should I make a new (additional to existing) .TLD for the math class and add all the functions?

Or would it be "better" to just add the one or two functions that I need today. Seems that its unlikely that I'll need all of the java.lang.Math functions (cosine anyone?) but min/max/mean/median are so handy.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either way. If you already have a TLD and want to use only a handful of the Math methods, it's easy to add the function declarations.

If you want something a bit more reusable that you can drop into multiple applications, I'd go with a math TLD.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Related best practices question:

Given that I have one or more TLD files is it better to refer to them locally within the jar file, i.e.
WEB-INF/tlds/foo.tld

or should I really post them to a public site and use a live URL such as
http://www.pfarrell.com/public/math.tld

I would think that relative is better. But I don't grok all this template/tld stuff.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are confusing URIs with URLs. The URI that you define within a TLD has nothing to do with a web location. It's just an identifier. It could just as well be "djfgjfhgdfjhgdsjhgfdsa", but URIs use the http + domain format in an attempt to enforce uniqueness. For example, no one else should create URIs containing bibeault.org but me.

So when you define a URI such as http://www.someserver.com/this/that/other, it does not mean that the TLD exists at that web location. It's just a string that is used to match against the URI that you specify in the tag directive.

Use proper URIs. Using relative file addresses is a fallback that should only be used when a TLD author is lazy and doesn't define a proper URI.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I've got something all fubar.

Error on execution is:

The class int a specified in the method signature in TLD for the function math:max cannot be found. int a
invocation is:



TLD code looks like:



Hints or pointers greatly appreciated.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't give the parameters in the signature names. Just list the types.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!