Skip to content

Commit

Permalink
add getInitParameter shortcut methods
Browse files Browse the repository at this point in the history
  • Loading branch information
zhedar committed Apr 22, 2016
1 parent 2f0fb31 commit b6137a4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import javax.el.ValueExpression;
import javax.faces.component.FacesComponent;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.FacesContext;

import net.bootsfaces.C;
import net.bootsfaces.beans.ELTools;
Expand Down Expand Up @@ -89,8 +88,7 @@ public ColorPicker() {
// AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, "jq/jquery.js");
AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, "js/jquery.minicolors.min.js");

renderLabel= FacesContext.getCurrentInstance().getExternalContext()
.getInitParameter("net.bootsfaces.defaults.renderLabel");
renderLabel= BsfUtils.getInitParam("net.bootsfaces.defaults.renderLabel");
if (null != renderLabel && renderLabel.contains("#{")) {
renderLabel = ELTools.evalAsString(renderLabel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import javax.el.ValueExpression;
import javax.faces.component.FacesComponent;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.FacesContext;

import net.bootsfaces.C;
import net.bootsfaces.beans.ELTools;
Expand Down Expand Up @@ -102,8 +101,7 @@ public InputText() {
AddResourcesListener.addBasicJSResource("bsf", "js/bsf.js");
AddResourcesListener.addThemedCSSResource("core.css");
AddResourcesListener.addThemedCSSResource("bsf.css");
renderLabel= FacesContext.getCurrentInstance().getExternalContext()
.getInitParameter("net.bootsfaces.defaults.renderLabel");
renderLabel= BsfUtils.getInitParam("net.bootsfaces.defaults.renderLabel");
if (null != renderLabel && renderLabel.contains("#{")) {
renderLabel = ELTools.evalAsString(renderLabel);
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/bootsfaces/listeners/AddResourcesListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import net.bootsfaces.C;
import net.bootsfaces.beans.ELTools;
import net.bootsfaces.utils.BsfUtils;

/**
* This class adds the resource needed by BootsFaces and ensures that they are
Expand Down Expand Up @@ -106,7 +107,7 @@ public void processEvent(SystemEvent event) throws AbortProcessingException {
*/
private void addMetaTags(UIViewRoot root, FacesContext context) {
// Check context-param
String viewportParam = context.getExternalContext().getInitParameter(C.P_VIEWPORT);
String viewportParam = BsfUtils.getInitParam(C.P_VIEWPORT, context);

viewportParam = evalELIfPossible(viewportParam);
String content = "width=device-width, initial-scale=1";
Expand Down Expand Up @@ -167,8 +168,8 @@ private void addJavascript(UIViewRoot root, FacesContext context, boolean isProd
*/
String theme = null;
String usetheme = null;
theme = context.getExternalContext().getInitParameter(C.P_THEME);
usetheme = context.getExternalContext().getInitParameter(C.P_USETHEME);
theme = BsfUtils.getInitParam(C.P_THEME, context);
usetheme = BsfUtils.getInitParam(C.P_USETHEME, context);
theme = evalELIfPossible(theme);
if (!theme.isEmpty()) {
if (theme.equalsIgnoreCase("custom")) {
Expand Down Expand Up @@ -202,8 +203,7 @@ private void addJavascript(UIViewRoot root, FacesContext context, boolean isProd
UIComponent header = findHeader(root);
boolean useCDNImportForFontAwesome = (null == header) || (null == header.getFacet("no-fa"));
if (useCDNImportForFontAwesome) {
String useCDN = FacesContext.getCurrentInstance().getExternalContext()
.getInitParameter("net.bootsfaces.get_fontawesome_from_cdn");
String useCDN = BsfUtils.getInitParam("net.bootsfaces.get_fontawesome_from_cdn");
if (null != useCDN) {
useCDN = ELTools.evalAsString(useCDN);
}
Expand Down Expand Up @@ -312,7 +312,8 @@ private void addJavascript(UIViewRoot root, FacesContext context, boolean isProd
}
viewMap.remove(RESOURCE_KEY);
}
String blockUI = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("net.bootsfaces.blockUI");

String blockUI = BsfUtils.getInitParam("net.bootsfaces.blockUI", context);
if (null != blockUI)
blockUI = ELTools.evalAsString(blockUI);
if (null != blockUI && isTrueOrYes(blockUI)) {
Expand Down Expand Up @@ -362,8 +363,7 @@ private void addJavascript(UIViewRoot root, FacesContext context, boolean isProd
}

private boolean shouldLibraryBeLoaded(String initParameter) {
String suppressLibrary = FacesContext.getCurrentInstance().getExternalContext()
.getInitParameter(initParameter);
String suppressLibrary = BsfUtils.getInitParam(initParameter);
if (suppressLibrary != null)
suppressLibrary = ELTools.evalAsString(suppressLibrary);

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/net/bootsfaces/utils/BsfUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,22 @@ public static UIComponent findComponent(UIComponent c, String id) {
}
return null;
}

/**
* Shortcut for getting context parameters.
* @param param context parameter name
* @return value of context parameter, may be null or empty
*/
public static String getInitParam(String param) {
return getInitParam(param, FacesContext.getCurrentInstance());
}

/**
* Shortcut for getting context parameters using an already obtained FacesContext.
* @param param context parameter name
* @return value of context parameter, may be null or empty
*/
public static String getInitParam(String param, FacesContext context) {
return context.getExternalContext().getInitParameter(param);
}
}

0 comments on commit b6137a4

Please sign in to comment.