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 3692226
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:14:17+00:00 2026-05-19T04:14:17+00:00

I am running JSF 2.0 I currently have one java controller that is called

  • 0

I am running JSF 2.0

I currently have one java controller that is called Contacts.java. Inside there I have a list of addresses stored as a member variable

List<Addresses> addresses;

When my application loads it displays a bunch of contacts and you are able to click on a contact to “open it” to view its data. When you click on the contact the contactId is passed to a method that populates the List based on the contactId. It in turn then displays the data.

I also have a bunch of functionality that will add an address to the list, remove an address, updated etc. which are all dependent on this contactId.

I was considering splitting up my Contacts.java into two controllers Contacts.java and Addresses.java because there is just so much logic having to do with addresses that I figured it should be in its own class.

The issue that I am struggling with is that if I move all of the logic dealing with Addresses into Addresses.java it will need to somehow have a reference to the contactId that was selected after compile time.

At compile time Addresses will compile looking for the current contactId when it is populating the List addresses in the constructor. It will have not been set at this point though because the contactId is set when the user selects a contact in the application.

Is this a bad design idea ? I am very new to Java and OOP and have not full grasped the concepts of how to break these apart. Any help would be appreciated.

  • 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-19T04:14:17+00:00Added an answer on May 19, 2026 at 4:14 am

    In general, a single bean per view/form is preferable, but that also depends on whether you’re using asynchronous requests or not (ajax or not). As to passing the data around, there are several ways depending on the source, the target and/or the route.

    At compile time Addresses will compile looking for the current contactId when it is populating the List addresses in the constructor. It will have not been set at this point though because the contactId is set when the user selects a contact in the application.

    In your particular case, you seem to expect that the constructor/postconstruct is the only way to load the data. This is not true. You can also do it in the event (action) methods. E.g.

    <h:dataTable value="#{contacts.list}" var="contact">
      <h:column>
        #{contact.name}
      </h:column>
      <h:column>
        <h:commandButton value="View info" action="#{contacts.view(contact)}">
      </h:column>
    </h:dataTable>
    

    And then in the Contacts backing bean (you only need to make List<Address> and List<Phone> a property of the Contact, with appropriate getters and setters)

    public String view(Contact contact) {
        this.contact = contact;
        contact.setAddresses(addressDAO.list(contact));
        contact.setPhones(phoneDAO.list(contact));
        return "view";
    }
    

    And then in the page associated with view:

    <h:dataTable value="#{contacts.contact.addresses}" var="address">
        ...
    </h:dataTable>
    <h:dataTable value="#{contacts.contact.phones}" var="phone">
        ...
    </h:dataTable>
    

    Or if you’re using JPA, you can also take benefit of lazy loading. But that’s a story and design apart.

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

Sidebar

Related Questions

Running ipconfig /all shows a Teredo Tunneling Pseudo-Interface. What is that? Does this have
We have several JSF portlets running in a websphere portal environment. A developer wants
I have Enterprise Application with EJB3 and JSF on Glassfish server. After running this
I'm building a webapp that uses jboss-seam with jsf, facelets and rich faces, running
I am developing a Java EE project (used EJB3, JSF and maven) running on
running git instaweb in my repository opens a page that says 403 Forbidden -
Running into a problem where on certain servers we get an error that the
Running IIS5 (yes, really). I'd like to remove the eTag http header that IIS
We currently run two separate webapps (WARs) deployed in one single EAR containing additional
I am running a Seam web application with Richfaces for the JSF implementation. I

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.