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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:48:38+00:00 2026-06-13T10:48:38+00:00

I have implemented Autoconverter (with forceSelection=false) in maintainance screen. To edit existing record, User

  • 0

I have implemented Autoconverter (with forceSelection=false) in maintainance screen.
To edit existing record, User will select ID from Autocomplete list.

To add new record, user will enter new ID in same box.

In converter, Application will try to search record in DB using ID.
If not found, New empty object is created with supplied ID and to avoid duplications, this object is added to array list maintained in Converter.

This works as expected on single browser session. but while testing with multiple browser, I found that Array list is shared across all instances.

I am not sure whether approach I have taken is right? if not can you please suggest me an alternative approach.

private List<SchoolMasterDetails> schoolMasterDetailsDB = new ArrayList<SchoolMasterDetails>();


@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) {
SchoolMasterDetails selectedObject = null;  

System.out.println("getAsObject ==> Entering.");
System.out.println("getAsObject ==> '" + submittedValue + "'");

if (!submittedValue.trim().equals("")) {
    selectedObject = (SchoolMasterDetails) getMasterService().getSchoolbyCode(submittedValue);

    if (selectedObject == null) {
        // search Object on localDB
        for (SchoolMasterDetails p : schoolMasterDetailsDB) {
            if (p.getSchoolCode().equalsIgnoreCase(submittedValue.trim())) {
                System.out.println("getAsObject from ArrayList ==> " + p);
                return p;   // return selectedObject from list of created objects
            }
        }

        System.out.println("getAsObject ==> selectedObject is null, Hence Creating new Object");
        selectedObject = new SchoolMasterDetails();
        selectedObject.setSchoolCode(submittedValue.trim());
        selectedObject.setSchoolName("TEST TEST TEST");
        schoolMasterDetailsDB.add(selectedObject);
    }
    else {
        System.out.println("getAsObject from Database ==> " + selectedObject);
    }
}
System.out.println("getAsObject ==> " + selectedObject);
}
System.out.println("getAsObject ==> Exiting.");     
return selectedObject;
}

Regards,

Shirish

  • 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-06-13T10:48:39+00:00Added an answer on June 13, 2026 at 10:48 am

    As far as I understand this (still learning myself), a converter fulfills exactly one purpose: It prepares your custom objects to be used in the views (getAsString) and translates Strings back into objects (getAsObject). It will be used whenever an input (a radio list, textfield, autocomplete) is tied to a variable in a backing bean that is of the type of your custom object. It is in your freedom to decide what String should be used to represent your object and how you use this String in return to look up objects.

    With this in mind I would not use a converter to store a local list of objects, nor let it handle the creation process itself. Instead, I’d assume there is a backing bean somewhere, which holds your data objects and takes care of all your logic. This bean can have a list of, say, schoolMasters that can be queried for the objects it contains (similar to what your doing). You could then either implement the lookup there in a way that it handles the not-found case and always returns a valid object (which may be a new one), or you could catch the not-found-case in the converter and then trigger a createNew() from the bean to get a new instance.

    IMHO this separates the management of the instances more clearly from the translating purpose of your converter. Also, from your code, it seems like you have two places to look up objects – via getMasterService() (a local method?) and inside your stored ArrayList. I don’t quite get this…


    As for your problem with the browsers sharing an instance: This sounds like a scope issue. If your backing bean, which is supposed to store and manage your data, is in application scope then the same set of data will be available as long as the application runs. This data will be available across browsers and also across users.

    On the other hand, if you put the bean in session scope, each session will create its own instance of the bean and store unique data. Similarly, view scoped beans live as long as a single view and request beans are trashed and regenerate for each http request. You can read more here: How to choose the right scope

    The answers there talk about beans (which is where your data usually lives). I’m not sure about converters, I see them as classes that are available application wide, so that each session and view can use them for translation – if you maintain a list there, it may well be globally available.

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

Sidebar

Related Questions

I have implemented a jquery ui autocomplete with data from database. Right now what
I have implemented a table view with multiple threads. Currently when a user taps
i have implemented galleryview in one screen named display_image.xml in which i have shown
I have implemented Facebook authentication on my website. I have asked for user permissions
Have implemented an edit functionality in struts2. After i click submit button, the bean
I have implemented a simple file upload-download mechanism. When a user clicks a file
I have implemented a simple little DSL that generates classes from input files, by
I have Implemented Code to download a File from Internet, But I am getting
I have implemented correctly bump's api, and added this code: - (void) configureBump {
I have implemented pagination to my data, but the problem is I only have

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.