From a33008d0b24faa6660a9e533e551802c5c2b6536 Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Mon, 11 Jun 2012 18:00:46 +0200 Subject: [PATCH] Solved a problem with multiple session access to the projects list; Added code to differ between sessions --- .../beans/application/ProjectsBean.java | 13 ++++++-- .../kieker/webgui/beans/session/UserBean.java | 12 ++++++- .../view/CurrentProjectOverviewBean.java | 33 +++++++++++++++++++ .../src/main/webapp/ProjectOverview.xhtml | 4 +-- 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ProjectsBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ProjectsBean.java index 66a9ea28..2e041c11 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ProjectsBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ProjectsBean.java @@ -27,6 +27,7 @@ import java.util.Date; import java.util.List; import javax.annotation.PostConstruct; +import javax.el.ELResolver; import javax.faces.application.FacesMessage; import javax.faces.application.FacesMessage.Severity; import javax.faces.bean.ApplicationScoped; @@ -37,6 +38,7 @@ import kieker.analysis.AnalysisController; import kieker.analysis.model.analysisMetaModel.MIProject; import kieker.common.logging.Log; import kieker.common.logging.LogFactory; +import kieker.webgui.beans.view.CurrentProjectOverviewBean; import kieker.webgui.common.ACManager; import kieker.webgui.common.FSManager; import kieker.webgui.common.exception.ProjectAlreadyExistingException; @@ -92,6 +94,11 @@ public final class ProjectsBean { this.projects.add(project); // Inform the user ProjectsBean.showMessage(FacesMessage.SEVERITY_INFO, "Project created."); + // Update the list of the "calling" bean + final ELResolver el = FacesContext.getCurrentInstance().getApplication().getELResolver(); + final CurrentProjectOverviewBean bean = (CurrentProjectOverviewBean) el.getValue(FacesContext.getCurrentInstance().getELContext(), null, + "currentProjectOverviewBean"); + bean.updateLists(); } catch (final IOException ex) { ProjectsBean.LOG.error("An error occured while creating the project.", ex); ProjectsBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while creating the project."); @@ -159,10 +166,12 @@ public final class ProjectsBean { /** * This method delivers all available projects as a list of string. * - * @return All currently available projects. Do not modify this list with add, remove etc. (It still has to be sortable for Primefaces though) + * @return All currently available projects. The list is just a copy. */ public List<String> getProjects() { - return this.projects; + synchronized (this.projects) { + return new ArrayList<String>(this.projects); + } } /** diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/UserBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/UserBean.java index aee82bb4..76548bda 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/UserBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/UserBean.java @@ -21,7 +21,9 @@ package kieker.webgui.beans.session; import java.io.Serializable; +import java.util.concurrent.atomic.AtomicLong; +import javax.annotation.PreDestroy; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @@ -44,11 +46,19 @@ public final class UserBean implements Serializable { */ private final String userName; + private static final AtomicLong guestCounter = new AtomicLong(); + /** * Creates a new instance of this class. The user name is set to "Guest". */ public UserBean() { - this.userName = "Guest"; + this.userName = "Guest #" + UserBean.guestCounter.getAndIncrement(); + } + + @Override + @PreDestroy + protected void finalize() { + UserBean.guestCounter.decrementAndGet(); } /** diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentProjectOverviewBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentProjectOverviewBean.java index 4a7be8dc..62f4f1c4 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentProjectOverviewBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentProjectOverviewBean.java @@ -20,8 +20,16 @@ package kieker.webgui.beans.view; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.el.ELResolver; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; +import javax.faces.context.FacesContext; + +import kieker.webgui.beans.application.ProjectsBean; /** * This bean is used in the context of the project overview page. @@ -33,6 +41,10 @@ import javax.faces.bean.ViewScoped; @ViewScoped public class CurrentProjectOverviewBean { + /** + * This list contains all available projects by name. + */ + private List<String> projects = new ArrayList<String>(); /** * The name of the "selected" project. */ @@ -64,4 +76,25 @@ public class CurrentProjectOverviewBean { this.projectName = projectName; } + @PostConstruct + protected void init() { + this.updateLists(); + } + + public void updateLists() { + final ELResolver el = FacesContext.getCurrentInstance().getApplication().getELResolver(); + final ProjectsBean bean = (ProjectsBean) el.getValue(FacesContext.getCurrentInstance().getELContext(), null, "projectsBean"); + + this.projects = bean.getProjects(); + } + + /** + * This method delivers all available projects as a list of string. + * + * @return All currently available projects. The list is just a copy. + */ + public List<String> getProjects() { + return this.projects; + } + } diff --git a/Kieker.WebGUI/src/main/webapp/ProjectOverview.xhtml b/Kieker.WebGUI/src/main/webapp/ProjectOverview.xhtml index 9461387b..e7f811a6 100644 --- a/Kieker.WebGUI/src/main/webapp/ProjectOverview.xhtml +++ b/Kieker.WebGUI/src/main/webapp/ProjectOverview.xhtml @@ -22,7 +22,7 @@ <p:menuitem value="New Project" onclick="newProjectDialog.show()" ajax="true"/> <p:menuitem value="Import Project" ajax="true" disabled="true"/> <p:separator/> - <p:menuitem value="Refresh Projects List" update=":projectsListForm" ajax="true"/> + <p:menuitem value="Refresh Projects List" update=":projectsListForm" action="#{currentProjectOverviewBean.updateLists()}" ajax="true"/> <p:separator/> <p:menuitem value="Settings" onclick="settingsDlg.show()" ajax="true"/> </p:submenu> @@ -46,7 +46,7 @@ <p:commandButton icon="ui-icon-plus" value="Project" onclick="newProjectDialog.show()" ajax="true"/> </p:toolbarGroup> </p:toolbar> - <p:dataTable rows="15" paginator="true" paginatorPosition="bottom" var="project" rowsPerPageTemplate="5,10,15,25,50" value="#{projectsBean.projects}" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"> + <p:dataTable rows="15" paginator="true" paginatorPosition="bottom" var="project" rowsPerPageTemplate="5,10,15,25,50" value="#{currentProjectOverviewBean.projects}" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"> <p:column headerText="Project Name" id="modelHeader" sortBy="#{project}"> <p:commandLink id="dynaButton" value="#{project}"/> -- GitLab