Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4069698
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:32:00+00:00 2026-05-20T16:32:00+00:00

I’m migrating an old application from JSP 1.1 to JSP 2.1, and trying to

  • 0

I’m migrating an old application from JSP 1.1 to JSP 2.1, and trying to do everything without scriptlets. I have a JavaBean that I create, populate and insert into the page scope via a CustomTag. This JavaBean exposes some methods that transform data, generate HTML snippets, etc, based on it’s instance variables.

When I need to access a property in the JavaBean I use:

${mybean.property}

But since JSP 2.1/EL 2.1 don’t support calling methods on your beans (this requires JSP 2.2/EL 2.2), I’m trying to determine the best way to expose such utility methods to my JSP pages without resorting to scriptlets.

Here is an example of the methods on the JavaBean that I need to access:

public String getThumbColor() {
   String tbgcolor = "#FF0000";
   if (this.getJavaBuildTotal() > 0 && 
        this.getJavaBuildBroke() == 0 && 
        this.getCeeBuildBroke() == 0 && 
        this.getJavaBuildInvalid() == 0 && 
        !this.hasBuildException()) {
      tbgcolor = "#00FF00";
   }
   else if (this.getJavaBuildTotal() == 0 && this.getCeeBuildTotal() == 0) {
      tbgcolor = "#f7f814";
   }
   return tbgcolor;
}

It feels like converting this (and the 10 or so other methods like it) entirely to JSTL in the JSP would be muddying up my JSP page.

Since I’m already doing a large refactoring, I don’t mind drastic changes; yet I can’t think of anyway to eliminate my need of certain methods that use conditionals for deciding on return values, generate small HTML snippets, etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:32:00+00:00Added an answer on May 20, 2026 at 4:32 pm

    Have a look at JSTL. It offers at least a basic set of core tags to control the flow in the page. Use this instead of if/else/switch whatever in scriptlets. It also offers several utility methods in the functions taglib. Basic String operations such as substring and so on are offered by this. You could also homegrow custom EL functions yourself which can call public static methods with arguments.

    See also:

    • How to avoid Java code in JSP files?
    • Hidden features of JSP/Servlet (contains an EL function example)

    Update as per the information in the comment

    They make decisions based on the instance variables in the class and respond accordingly

    You could add getters for those variables and use this in <c:if> or whatever.

    <c:if test="${bean.property == 'somevalue' && bean.otherproperty != 'foo'}">
    

    You could even wrap this in a boolean getter in the bean if those values are for example constants.

    public boolean isCondition() {
        return "somevalue".equals(property) && !"foo".equals(otherproperty);
    }
    

    which you use as follows:

    <c:if test="${bean.condition}">
    

    There are lot of ways depending on the concrete functional requirement, which is still vague in your question.

    See also:

    • Java EE 5 tutorial – Operators in EL

    Update 2: as per the new example in your question, presentation specifics should go in the view (JSP). The bgcolor is part of the presentation. I’d suggest to replace this by an enum.

    public enum Status {
        OK, FAIL, NONE;
    }
    
    public Status getStatus() {
       if (this.getJavaBuildTotal() > 0 && 
            this.getJavaBuildBroke() == 0 && 
            this.getCeeBuildBroke() == 0 && 
            this.getJavaBuildInvalid() == 0 && 
            !this.hasBuildException()) {
          return OK;
       }
       else if (this.getJavaBuildTotal() == 0 && this.getCeeBuildTotal() == 0) {
          return NONE;
       }
       return FAIL;
    }
    

    And declare the color in the view

    <c:set var="bgcolor" value="${(build.status == 'OK') ? '#00ff00' : (build.status == 'FAIL') ? '#ff0000' : '#f7f814'}" />
    ...
    <tr bgcolor="${bgcolor}">
    

    Or, better, make a CSS class of it

    <tr class="build ${build.status}">
    

    with in a style(sheet)

    tr.build.OK { background: #00ff00; }
    tr.build.FAIL { background: #ff0000; }
    tr.build.NONE { background: #f7f814; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.