0
votes

Well, I have a OLD jsp system using JavaEE5

One of the screens shows the user a BIG datatable that is called from the database each view, because the tables is HUGE and they need all the data it takes 15 miutus to render

In order to solve the problem I choose to use an AplicationScoped ManagedBean that stores the list in a List myList and it is acceded for the backing bean of the user interface

So far, so good, it work.

When the application adds another ecord I aded a line in the procedure to add the new object to the list myList.add(Object)

When I debug the application the object is correctly put in the list (the list grows by one record)

But when I logoff and log in, or refresh the grid the list is not renewed.

Maybe is not the best solution (using an application scoped bean)

I am using JSF 2.2, Primefaces 6.0 and javaEE5

My aPPScoped bean (getters and setters not shown to save space)

@ManagedBean(eager=true)
@ApplicationScoped
public class AplicationBean {

   public static List<Object> myList = new ArrayList();

   @PostConstruct
   public void iniciar() {
        myList=  est.getALLDATA();
   }
}

The backing bean

@ManagedBean
@SessionScoped
public class jsfbean {

    private List<Object> myList= new ArrayList();

    @PostConstruct
    public void init(){
        this.myList =  AplicationBean.getALLDATA();
    }
}     

the grid

                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"                      
                     paginator="true"
                     rows="40"
                     >

After the Insert an object P y created and then I add that in the list as this:

System.out.println("size"+AplicationBean.getMylist().size()); //(size is 1000)
AplicationBean.getMyList().add(P);

System.out.println("NEW SIZE"+AplicationBean.getMyList().size());
1
You have JSF 2.2 and Java EE 5? How this? Who is your add method?jklee
Yes, the system is made in JavaEE5 (not by me), when the app start the list is filled with all values and the grid shows perfectly, then in the Create form I aded a command like this AplicationBean.myList.add(Object);Alexev
But JSF 2.2 isn't a part of Java EE 5.jklee
It work, trust me, I just added the JSF 2.2 jar and its configuration files and the app works fine except for this problem. I am not the original developer, I would use JavaEE8 but now this is the reality I have to handleAlexev
JavaEE8 wasn't released.jklee

1 Answers

1
votes

EJB and static attributes is a bad idea. I propose the following structure.

@Startup
@Singleton
public class ApplicationBean {

    public List<Object> myList = new ArrayList();

    @PostConstruct
    public void iniciar()
    {
        myList=  est.getALLDATA();
    }

    public void add(Object o){
        this.myList.add(o);
    }

}

@ManagedBean
@SessionScoped
public class SessionBean {

    @EJB
    ApplicationBean applicationBean;

    List<Object> list;

    // Cached for the session
    public List<Object> getObjectList(){
        if(list==null){
            list = applicationBean.getObjectList();
        }
        return list;
    }

    // Always fresh data
    public List<Object> getObjectListNotCached(){
        return applicationBean.getObjectList();
    }
    ...
}

The list attributes live as long as the session. But this design have also problems, by example, what is after you update the base list? And the solutions isn't thread safe.