fixed account handling
fixed view CDI integration
This commit is contained in:
@ -12,9 +12,10 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.ManagedProperty;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Inject;
|
||||
import org.primefaces.event.SelectEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -22,14 +23,14 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
@ManagedBean(name = "accountView")
|
||||
@SessionScoped
|
||||
@ViewScoped
|
||||
@Named("accountView")
|
||||
public class AccountView implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -8050582392249849438L;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AccountView.class);
|
||||
|
||||
@ManagedProperty(value = "#{applicationView}")
|
||||
@Inject
|
||||
private ApplicationView applicationView;
|
||||
@EJB
|
||||
private AccountControl accountService;
|
||||
@ -50,8 +51,6 @@ public class AccountView implements Serializable {
|
||||
// account currently on edit
|
||||
private AccountEntity currentAccount;
|
||||
private List<ApplicationRoleEntity> currentAccountRoles = null;
|
||||
// boolean flag to toggle buttons which require an account to be selected
|
||||
private boolean accountSelected = false;
|
||||
|
||||
public List<AccountEntity> getAccounts() {
|
||||
if (accountList == null) {
|
||||
@ -68,6 +67,17 @@ public class AccountView implements Serializable {
|
||||
return applicationRoles;
|
||||
}
|
||||
|
||||
public void selectAccount(SelectEvent event) {
|
||||
if (currentAccount == null) {
|
||||
applicationRoles = null;
|
||||
currentAccountRoles = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getAccountSelected() {
|
||||
return currentAccount != null;
|
||||
}
|
||||
|
||||
public void newAccount() {
|
||||
currentAccount = new AccountEntity();
|
||||
currentAccount.setUsername(null);
|
||||
@ -84,7 +94,7 @@ public class AccountView implements Serializable {
|
||||
this.currentAccountRoles = new ArrayList<>();
|
||||
if (currentAccount.getApplicationRoleList() != null) {
|
||||
currentAccountRoles.addAll(currentAccount.getApplicationRoleList());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,8 +111,7 @@ public class AccountView implements Serializable {
|
||||
currentAccount.setUsername(null);
|
||||
FacesUtil.addErrorMessage("editDialogMessaegs", "Create new account failed", "Account with username " + username + " already exists");
|
||||
} else {
|
||||
accountService.saveAccount(currentAccount, currentAccountRoles);
|
||||
selectAccount();
|
||||
accountService.saveAccount(applicationView.getCurrentApplication(), currentAccount, currentAccountRoles);
|
||||
if (currentAccount.getId() == null) {
|
||||
// this was a new account
|
||||
// force accounts to be loaded from database again
|
||||
@ -117,8 +126,7 @@ public class AccountView implements Serializable {
|
||||
accountList.remove(currentAccount);
|
||||
FacesUtil.addGlobalInfoMessage("Info", "Account " + currentAccount.getUsername() + " deleted");
|
||||
currentAccount = null;
|
||||
currentAccountRoles = null;
|
||||
deselectAccount();
|
||||
currentAccountRoles = null;
|
||||
} catch (AccountException ex) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(ex.toString(), ex);
|
||||
@ -130,14 +138,6 @@ public class AccountView implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public void selectAccount() {
|
||||
this.accountSelected = true;
|
||||
}
|
||||
|
||||
public void deselectAccount() {
|
||||
this.accountSelected = false;
|
||||
}
|
||||
|
||||
public void showDisabledAccountsChange() {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("show diabled accounts changed to {}", showDisabledAccounts);
|
||||
@ -150,11 +150,11 @@ public class AccountView implements Serializable {
|
||||
}
|
||||
|
||||
/* **** getter / setter **** */
|
||||
|
||||
/**
|
||||
* setter for managed property applicationView
|
||||
*
|
||||
* @param applicationView the applicaton view to inject
|
||||
*/
|
||||
*/
|
||||
public void setApplicationView(ApplicationView applicationView) {
|
||||
this.applicationView = applicationView;
|
||||
}
|
||||
@ -167,14 +167,6 @@ public class AccountView implements Serializable {
|
||||
this.currentAccount = currentAccount;
|
||||
}
|
||||
|
||||
public boolean isAccountSelected() {
|
||||
return accountSelected;
|
||||
}
|
||||
|
||||
public void setAccountSelected(boolean accountSelected) {
|
||||
this.accountSelected = accountSelected;
|
||||
}
|
||||
|
||||
public boolean isShowDisabledAccounts() {
|
||||
return showDisabledAccounts;
|
||||
}
|
||||
|
||||
@ -6,8 +6,9 @@ import de.muehlencord.shared.jeeutil.FacesUtil;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.SessionScoped;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.inject.Named;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.inject.Inject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -16,8 +17,8 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@ManagedBean (name="applicationView")
|
||||
@SessionScoped
|
||||
@Named("applicationView")
|
||||
public class ApplicationView implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5515249316880163539L;
|
||||
@ -29,14 +30,25 @@ public class ApplicationView implements Serializable {
|
||||
private ApplicationEntity currentApplication = null;
|
||||
private ApplicationEntity editApplication = null;
|
||||
private List<ApplicationEntity> applicationList = null;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void selectDefaultCurrentApplication() {
|
||||
// force applications to be loaded from database
|
||||
getAllApplications();
|
||||
if ((applicationList != null) && (!applicationList.isEmpty())) {
|
||||
currentApplication = applicationList.get(0);
|
||||
}
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("post construct executed");
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void predestroy() {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Predestroy executed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<ApplicationEntity> getAllApplications() {
|
||||
@ -79,19 +91,19 @@ public class ApplicationView implements Serializable {
|
||||
FacesUtil.addGlobalInfoMessage("Info", "Application saved");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void deleteApplication() {
|
||||
if (currentApplication == null) {
|
||||
FacesUtil.addGlobalErrorMessage("Error", "Need to provide data");
|
||||
} else if (currentApplication.getId() == null) {
|
||||
FacesUtil.addGlobalErrorMessage("Error", "Cannot delete non persistent data");
|
||||
FacesUtil.addGlobalErrorMessage("Error", "Cannot delete non persistent data");
|
||||
} else {
|
||||
String applicationName = currentApplication.getApplicationName();
|
||||
applicationService.delete (currentApplication);
|
||||
applicationService.delete(currentApplication);
|
||||
applicationList = null; // force reload to update view
|
||||
currentApplication = null;
|
||||
selectDefaultCurrentApplication();
|
||||
FacesUtil.addGlobalInfoMessage("Info", "Application "+applicationName+" deleted");
|
||||
FacesUtil.addGlobalInfoMessage("Info", "Application " + applicationName + " deleted");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -23,9 +23,9 @@ import de.muehlencord.shared.jeeutil.FacesUtil;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.ManagedProperty;
|
||||
import javax.faces.bean.SessionScoped;
|
||||
import javax.inject.Named;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -33,14 +33,14 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@ManagedBean(name = "permissionView")
|
||||
@SessionScoped
|
||||
@ViewScoped
|
||||
@Named("permissionView")
|
||||
public class PermissionView implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1469453490360990772L;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PermissionView.class);
|
||||
|
||||
@ManagedProperty(value = "#{applicationView}")
|
||||
@Inject
|
||||
private ApplicationView applicationView;
|
||||
|
||||
@EJB
|
||||
|
||||
@ -25,9 +25,9 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.ManagedProperty;
|
||||
import javax.faces.bean.SessionScoped;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Inject;
|
||||
import org.primefaces.event.SelectEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -36,14 +36,14 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@ManagedBean(name = "roleView")
|
||||
@SessionScoped
|
||||
@ViewScoped
|
||||
@Named("roleView")
|
||||
public class RoleView implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1669321020398119007L;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RoleView.class);
|
||||
|
||||
@ManagedProperty(value = "#{applicationView}")
|
||||
@Inject
|
||||
private ApplicationView applicationView;
|
||||
|
||||
@EJB
|
||||
|
||||
@ -32,9 +32,6 @@
|
||||
<span>Accounts</span>
|
||||
</p:link>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li>
|
||||
<p:commandLink target="/logout.xhtml" actionListener="#{loginView.logout}">
|
||||
<i class="fa fa-sign-out"></i>
|
||||
|
||||
@ -21,7 +21,7 @@ limitations under the License.
|
||||
xmlns:h="http://xmlns.jcp.org/jsf/html">
|
||||
|
||||
<ui:define name="head">
|
||||
<title>Product Catalog Designer</title>
|
||||
<title>Account UI</title>
|
||||
<link rel="shortcut icon" href="#{resource['images/favicon/favicon.ico']}" />
|
||||
<h:outputStylesheet name="css/admin.css" />
|
||||
</ui:define>
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<p:dataTable id="accountTable" value="#{accountView.accounts}" var="account" rowKey="#{account.username}" selectionMode="single" selection="#{accountView.currentAccount}"
|
||||
styleClass="box-primary">
|
||||
<p:ajax event="rowSelect" update="deleteButton,editButton" listener="#{accountView.selectAccount}" />
|
||||
<p:ajax event="rowUnselect" update="deleteButton,editButton" listener="#{accountView.deselectAccount}" />
|
||||
<p:ajax event="rowUnselect" update="deleteButton,editButton" listener="#{accountView.selectAccount}" />
|
||||
<p:column headerText="Username">
|
||||
<h:outputText value="#{account.username}" />
|
||||
</p:column>
|
||||
@ -220,10 +220,10 @@
|
||||
<p:outputLabel for="roles" value="Roles" />
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-6">
|
||||
<p:selectManyMenu id="roles" var="role" label="#{role.roleName}" value="#{accountView.currentAccountRoles}" converter="omnifaces.SelectItemsConverter" required="true" >
|
||||
<f:selectItems value="#{accountView.allApplicationRoles}" var="roleItem" itemLabel="#{roleItem.roleName}" itemValue="#{role}" />
|
||||
<p:selectManyMenu id="roles" var="role" label="#{role.roleName}" value="#{accountView.currentAccountRoles}" converter="omnifaces.SelectItemsConverter" required="false" >
|
||||
<f:selectItems value="#{accountView.allApplicationRoles}" var="roleItem" itemValue="#{roleItem}" />
|
||||
<p:column>
|
||||
<h:outputText value="#{role.roleName}"/>
|
||||
<h:outputText value="#{role.application.applicationName}-#{role.roleName}"/>
|
||||
</p:column>
|
||||
</p:selectManyMenu>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user