Skip to content

Commit

Permalink
Merge pull request #555 from persapiens/adminfaces-properties
Browse files Browse the repository at this point in the history
configure AdminFaces using Spring Boot application.yml or application.properties
  • Loading branch information
persapiens committed Oct 17, 2018
2 parents 0bbc5ad + 4807987 commit cd1ec2f
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -43,6 +43,7 @@ standard (javax.faces) | jsf | `jsf.project-stage=development`
[primefaces](http://primefaces.org/) | jsf.primefaces | `jsf.primefaces.theme=overcast`
[bootsfaces](http://bootsfaces.net/) | jsf.bootsfaces | `jsf.bootsfaces.usetheme=true`
[butterfaces](http://butterfaces.org/) | jsf.butterfaces | `jsf.butterfaces.provide-j-query=true`
[adminfaces](http://adminfaces.github.io/site/) | jsf.adminfaces | `jsf.adminfaces.skin=skin-blue`
[richfaces](https://github.com/richfaces/richfaces) | jsf.richfaces | `jsf.richfaces.resource-default-ttl=86400`
[omnifaces](http://omnifaces.org/) | jsf.omnifaces | `jsf.omnifaces.faces-views-enabled=true`
[angularfaces](http://angularfaces.net/) | jsf.angularfaces | `jsf.angularfaces.add-labels=true`
Expand Down
@@ -0,0 +1,105 @@
/*
* Copyright 2016-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.joinfaces.autoconfigure.adminfaces;

import com.github.adminfaces.template.config.AdminConfig;
import com.github.adminfaces.template.config.ControlSidebarConfig;
import lombok.Setter;

/**
* AdminConfig Wrapper to use AdminFacesProperties.
* This class is not simpler because AdminConfig.getProperty is private.
*
* @author Marcelo Fernandes
*/
public class AdminConfigWrapper extends AdminConfig {
@Setter
private AdminfacesProperties adminfacesProperties;

@Override
protected void loadDefaults() {
super.loadDefaults();
configureAdminFacesProperties();
}

private String getAdminFacesStringProperty(String current, String fromAdminFacesProperties) {
String result = current;
if (fromAdminFacesProperties != null) {
result = fromAdminFacesProperties;
}
return result;
}

private Boolean getAdminFacesBooleanProperty(Boolean current, Boolean fromAdminFacesProperties) {
Boolean result = current;
if (fromAdminFacesProperties != null) {
result = fromAdminFacesProperties;
}
return result;
}

private Integer getAdminFacesIntegerProperty(Integer current, Integer fromAdminFacesProperties) {
Integer result = current;
if (fromAdminFacesProperties != null) {
result = fromAdminFacesProperties;
}
return result;
}

private void configureAdminFacesProperties() {
setLoginPage(getAdminFacesStringProperty(getLoginPage(), this.adminfacesProperties.getLoginPage()));
setIndexPage(getAdminFacesStringProperty(getIndexPage(), this.adminfacesProperties.getIndexPage()));
setDateFormat(getAdminFacesStringProperty(getDateFormat(), this.adminfacesProperties.getDateFormat()));
setTemplatePath(getAdminFacesStringProperty(getTemplatePath(), this.adminfacesProperties.getTemplatePath()));
setBreadCrumbMaxSize(getAdminFacesIntegerProperty(getBreadCrumbMaxSize(), this.adminfacesProperties.getBreadcrumbSize()));
setRenderMessages(getAdminFacesBooleanProperty(isRenderMessages(), this.adminfacesProperties.getRenderMessages()));
setRenderAjaxStatus(getAdminFacesBooleanProperty(isRenderAjaxStatus(), this.adminfacesProperties.getRenderAjaxStatus()));
setDisableFilter(getAdminFacesBooleanProperty(isDisableFilter(), this.adminfacesProperties.getDisableFilter()));
setRenderBreadCrumb(getAdminFacesBooleanProperty(isRenderBreadCrumb(), this.adminfacesProperties.getRenderBreadCrumb()));
setEnableSlideMenu(getAdminFacesBooleanProperty(isEnableSlideMenu(), this.adminfacesProperties.getEnableSlideMenu()));
setEnableRipple(getAdminFacesBooleanProperty(isEnableRipple(), this.adminfacesProperties.getEnableRipple()));
setRippleElements(getAdminFacesStringProperty(getRippleElements(), this.adminfacesProperties.getRippleElements()));
setSkin(getAdminFacesStringProperty(getSkin(), this.adminfacesProperties.getSkin()));
setAutoShowNavbar(getAdminFacesBooleanProperty(isAutoShowNavbar(), this.adminfacesProperties.getAutoShowNavbar()));
setIgnoredResources(getAdminFacesStringProperty(getIgnoredResources(), this.adminfacesProperties.getIgnoredResources()));
setLoadingImage(getAdminFacesStringProperty(getLoadingImage(), this.adminfacesProperties.getLoadingImage()));
setExtensionLessUrls(getAdminFacesBooleanProperty(isExtensionLessUrls(), this.adminfacesProperties.getExtensionLessUrls()));
setRenderControlSidebar(getAdminFacesBooleanProperty(isRenderControlSidebar(), this.adminfacesProperties.getRenderControlSidebar()));

setRippleMobileOnly(getAdminFacesBooleanProperty(isRippleMobileOnly(), this.adminfacesProperties.getRippleMobileOnly()));
setRenderMenuSearch(getAdminFacesBooleanProperty(isRenderMenuSearch(), this.adminfacesProperties.getRenderMenuSearch()));
setAutoHideMessages(getAdminFacesBooleanProperty(isAutoHideMessages(), this.adminfacesProperties.getAutoHideMessages()));
setMessagesHideTimeout(getAdminFacesStringProperty(getMessagesHideTimeout(), this.adminfacesProperties.getMessagesHideTimeout()));
setIconsEffect(getAdminFacesBooleanProperty(isIconsEffect(), this.adminfacesProperties.getIconsEffect()));

configControlSideBar();
}

private void configControlSideBar() {
setLeftMenuTemplate(getAdminFacesBooleanProperty(isLeftMenuTemplate(), this.adminfacesProperties.getControlSidebar().getLeftMenuTemplate()));

Boolean showOnMobile = getAdminFacesBooleanProperty(getControlSidebar().getShowOnMobile(), this.adminfacesProperties.getControlSidebar().getShowOnMobile());
Boolean fixedLayout = getAdminFacesBooleanProperty(getControlSidebar().getFixedLayout(), this.adminfacesProperties.getControlSidebar().getFixedLayout());
Boolean boxedLayout = getAdminFacesBooleanProperty(getControlSidebar().getBoxedLayout(), this.adminfacesProperties.getControlSidebar().getBoxedLayout());
Boolean expandOnHover = getAdminFacesBooleanProperty(getControlSidebar().getExpandOnHover(), this.adminfacesProperties.getControlSidebar().getExpandOnHover());
Boolean sidebarCollapsed = getAdminFacesBooleanProperty(getControlSidebar().getSidebarCollapsed(), this.adminfacesProperties.getControlSidebar().getSidebarCollapsed());
Boolean fixed = getAdminFacesBooleanProperty(getControlSidebar().getFixed(), this.adminfacesProperties.getControlSidebar().getFixed());
Boolean darkSkin = getAdminFacesBooleanProperty(getControlSidebar().getDarkSkin(), this.adminfacesProperties.getControlSidebar().getDarkSkin());

setControlSidebar(new ControlSidebarConfig(showOnMobile, fixedLayout, boxedLayout, expandOnHover, sidebarCollapsed, fixed, darkSkin));
}
}
Expand Up @@ -19,19 +19,23 @@
import javax.faces.application.ViewExpiredException;
import javax.persistence.OptimisticLockException;

import com.github.adminfaces.template.config.AdminConfig;
import com.github.adminfaces.template.exception.AccessDeniedException;
import com.github.adminfaces.template.session.AdminServletContextListener;
import com.github.adminfaces.template.session.AdminSession;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.joinfaces.autoconfigure.primefaces.Primefaces4_0Properties;
import org.joinfaces.autoconfigure.primefaces.Primefaces5_2Properties;
import org.joinfaces.autoconfigure.primefaces.PrimefacesAutoConfiguration;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.ServletComponentScan;
Expand All @@ -52,8 +56,7 @@
*/
@Slf4j
@Configuration
// will adminfaces autoconfigure via application.yml ?
//@EnableConfigurationProperties(AdminfacesProperties.class)
@EnableConfigurationProperties(AdminfacesProperties.class)
@ComponentScan({"com.github.adminfaces.template.bean",
"com.github.adminfaces.template.config",
"com.github.adminfaces.template.security"})
Expand All @@ -64,9 +67,14 @@
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class AdminfacesAutoConfiguration {

@Autowired
private AdminfacesProperties adminfacesProperties;

@Bean
public BeanPostProcessor adminfacesPrimeFacesPropertiesPostProcessor() {
return new PrimeFacesPropertiesPostProcessor();
PrimeFacesPropertiesPostProcessor result = new PrimeFacesPropertiesPostProcessor();
result.setAdminfacesProperties(this.adminfacesProperties);
return result;
}

// AdminSession does not contain @Named.
Expand Down Expand Up @@ -100,10 +108,14 @@ public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> adminface

/**
* Configures Primefaces to use admin theme.
* Apply adminfaces configuration from adminfaces properties.
*
* @author Marcelo Fernandes
*/
static class PrimeFacesPropertiesPostProcessor implements BeanPostProcessor {
@Setter
private AdminfacesProperties adminfacesProperties;

@Override
public Object postProcessBeforeInitialization(@Nullable Object bean, @Nullable String beanName) throws BeansException {
if (bean instanceof Primefaces4_0Properties) {
Expand All @@ -116,6 +128,11 @@ public Object postProcessBeforeInitialization(@Nullable Object bean, @Nullable S
log.warn("Changing primefaces fontAwesome from 'false' to 'true'.");
properties.setFontAwesome(true);
}
if (bean instanceof AdminConfig) {
AdminConfigWrapper adminConfigWrapper = new AdminConfigWrapper();
adminConfigWrapper.setAdminfacesProperties(this.adminfacesProperties);
bean = adminConfigWrapper;
}
return bean;
}
}
Expand Down

0 comments on commit cd1ec2f

Please sign in to comment.