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

  • Home
  • SEARCH
  • 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 3877752
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:32:02+00:00 2026-05-19T22:32:02+00:00

this is more a design question. Suppose you have many beans A, B, C….

  • 0

this is more a design question. Suppose you have many beans A, B, C…. Then you have a class that creates, say, tables out of beans. You need something that tells this class which properties of those beans to display, what names give to the columns and other rendering properties. I don’t want to hardwire this in the class for each bean class, so I was thinking of giving the beans a common interface like TableAdapterProvider, that would come out with a class that gives all instructions to the rendering class. The problem is that I can’t make an interface method static in Java. And this doesn’t seem very clean for a number of reasons… for example to create an empty table I have to allocate a bean and then call the interface method TableAdapterProvider to retrieve the “rendering” class.

I thought of creating a factory like TableAdapterFactory(Class beanClass) that returns the correct TableAdapter for each bean class without instanting any. Anyway I have to update this factory for every bean I create.

Another solution could be use special naming conventions, for example if a bean name is Apple, then AppleTableRenderer will be the renderer. I can scan a package in search of this when the TableRenderer starts so the associations are done automatically.

Do you know of a better pattern? What do you think of my approaches?

For the future, is there a good book with recipes like these to use in web apps?

  • 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-19T22:32:03+00:00Added an answer on May 19, 2026 at 10:32 pm

    Seems to me that any bean (A, B, C..) that needs to be displayed as a HTML table (by some kind of TableRenderer) should implement an interface that provides the renderer with the required information. The likely interface methods would get the columns headers and the table data. Maybe also one for table style, but that is a bit subjective.

    With this in mind you might have;

    public interface Renderable
    {
      public List<String> getHeaders();
      public List<List<String>> getData();
    }
    
    public class A implements Renderable
    {
      private String name;
      private int age;
    
      public List<String> getHeaders()
      {
        List<String> headers = new ArrayList<String>();
        headers.add("Name");
        headers.add("Age");
        return list;
      }
    
      public List<List<String>> getData()
      {
        List<List<String>> data = new ArrayList<List<String>();
        List<String> row = new ArrayList<String>();
        row.add(name);
        row.add(String.valueOf(age));
        data.add(row);
        return data;
      }
    
      //getters and setters
    
    }
    

    It’s then pretty trivial to write your TableRenderer;

    public class TableRenderer
    {
      public String render(Renderable r)
      {
         //draw a HTML table
         //draw table headers from r.getHeaders()
         //draw table rows from r.getData()
      }
    }
    

    Note that instead of writing a TableRenderer class you might want to use the JSTL <c:forEach> syntax, which is a more standard approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question pertains primarily to good design. Suppose I have a controller action like
This is more of a business-oriented programming question that I can't seem to figure
I have a design questions about this scenario: Suppose you have a form with
Suppose you have this class: public class A { private int number; public setNumber(int
This is a question about style and design rather than syntax. I have domain
This is more of an academic inquiry than a practical question. Are there any
This is more of an generic XML Schema question, but if and how do
This is more an observation than a real question: MS-Access (and VBA in general)
This is more of a syntax question I'm trying to write a store procedure
Ok this is more of a computer science question, than a question based on

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.