DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Creating Application using Spring Roo and Deploying on Google App Engine
  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • How To Build Web Service Using Spring Boot 2.x
  • How To Build Self-Hosted RSS Feed Reader Using Spring Boot and Redis

Trending

  • Unlocking AI Coding Assistants Part 3: Generating Diagrams, Open API Specs, And Test Data
  • Accelerating AI Inference With TensorRT
  • DGS GraphQL and Spring Boot
  • Scalable, Resilient Data Orchestration: The Power of Intelligent Systems
  1. DZone
  2. Coding
  3. Frameworks
  4. Calling a Static Method From EL

Calling a Static Method From EL

By 
Vineet Manohar user avatar
Vineet Manohar
·
Aug. 18, 10 · Interview
Likes (0)
Comment
Save
Tweet
Share
30.3K Views

Join the DZone community and get the full member experience.

Join For Free

In my previous post I showed how to pass parameters in EL methods. In this post, I will describe how to call static methods from EL.

Step 1: Download Call.java and ELMethod.java

Download the classes Call.java and ELMethod.java, and copy them to your project.

Step 2: Add an instance of Call.java as an application scoped bean

There are many ways to do this, depending on this technology you are using. Here are some examples:

How to set request scope in JSP

request.setAttribute("call", new Call());  

How to set session scope in JSP

session.setAttribute("call", new Call()); 
How to set application scope from Servlet
this.getServletContext().setAttribute("call", new Call())  

How to set application scope from JSP

 <jsp:useBean id="call" class="Call" scope="application" />  

How to set application scope in Seam

Add these annotations to your class

@Name("call")
@Scope(ScopeType.APPLICATION)

Step 3: Call any static method from EL as follows

Let us say you have a static method which formats date.

   package com.mycompany.util;  

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
public static String formatDate(String format, Date date) {
return new SimpleDateFormat(format).format(date);
}
}

You can call the above static method from EL as follows. Here “account” is a request scoped bean with a Date property call “creationDate”.

 ${call["com.mycompany.util.DateUtils.formatDate"]["MMM, dd"][account.creationDate]}  

In general the format is:

  ${call["full.package.name.MethodName"][arg1][arg2][...]}

Note:
  • Use map notation with [square brackets] when passing arguments to ${call}
  • First argument is the full package name + “.” + method name
  • If the static method you are calling takes arguments, simply pass those arguments using more [square brackets]
  • Overloaded methods are not supported, i.e. you cannot call methods where two methods with the same name exist in the class

References

  • Call.java source code from my Google code project
  • ELMethod.java source code from my Google code project
  • How to pass parameters in EL methods

 

From http://www.vineetmanohar.com/2010/08/calling-static-methods-from-el/

application Code Project Bracket (tournament) Pass (software) Google (verb) Requests POST (HTTP) Download Spring Framework

Opinions expressed by DZone contributors are their own.

Related

  • Creating Application using Spring Roo and Deploying on Google App Engine
  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • How To Build Web Service Using Spring Boot 2.x
  • How To Build Self-Hosted RSS Feed Reader Using Spring Boot and Redis

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!