Permalink
Browse files

Make use of new JSF 2.3 constants

  • Loading branch information...
BalusC committed May 21, 2017
1 parent bf1e026 commit 236e93b1603eec6d4031cf1062f8295545f41769
@@ -14,6 +14,7 @@
import static java.lang.Boolean.parseBoolean;
import static java.util.Arrays.asList;
import static javax.faces.component.UIInput.EMPTY_STRING_AS_NULL_PARAM_NAME;
import static javax.faces.validator.BeanValidator.DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAME;
import static org.omnifaces.util.Beans.getQualifier;
import static org.omnifaces.util.Components.setLabel;
@@ -170,8 +171,7 @@ private static boolean interpretEmptyStringSubmittedValuesAsNull(FacesContext co
return interpretEmptyStringSubmittedValuesAsNull;
}
interpretEmptyStringSubmittedValuesAsNull = parseBoolean(context.getExternalContext()
.getInitParameter("javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL"));
interpretEmptyStringSubmittedValuesAsNull = parseBoolean(context.getExternalContext().getInitParameter(EMPTY_STRING_AS_NULL_PARAM_NAME));
return interpretEmptyStringSubmittedValuesAsNull;
}
@@ -16,6 +16,8 @@
import static java.lang.Boolean.parseBoolean;
import static java.lang.String.format;
import static java.util.Collections.unmodifiableList;
import static javax.faces.component.behavior.ClientBehaviorContext.BEHAVIOR_EVENT_PARAM_NAME;
import static javax.faces.component.behavior.ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME;
import static javax.faces.component.behavior.ClientBehaviorContext.createClientBehaviorContext;
import static org.omnifaces.util.Beans.getReference;
import static org.omnifaces.util.FacesLocal.getApplicationAttribute;
@@ -773,11 +775,11 @@ public void decode(FacesContext context) {
return;
}
if (!getClientId(context).equals(getRequestParameter(context, "javax.faces.source"))) {
if (!getClientId(context).equals(getRequestParameter(context, BEHAVIOR_SOURCE_PARAM_NAME))) {
return;
}
List<ClientBehavior> behaviors = clientBehaviors.get(getRequestParameter(context, "javax.faces.behavior.event"));
List<ClientBehavior> behaviors = clientBehaviors.get(getRequestParameter(context, BEHAVIOR_EVENT_PARAM_NAME));
if (behaviors == null) {
return;
@@ -15,9 +15,9 @@
import static java.lang.Boolean.TRUE;
import static java.lang.String.format;
import static java.util.logging.Level.FINE;
import static org.omnifaces.config.OmniFaces.LIBRARY_NAME;
import static org.omnifaces.config.OmniFaces.SCRIPT_NAME;
import static org.omnifaces.config.OmniFaces.UNLOAD_SCRIPT_NAME;
import static org.omnifaces.config.OmniFaces.OMNIFACES_LIBRARY_NAME;
import static org.omnifaces.config.OmniFaces.OMNIFACES_SCRIPT_NAME;
import static org.omnifaces.config.OmniFaces.OMNIFACES_UNLOAD_SCRIPT_NAME;
import static org.omnifaces.util.Ajax.load;
import static org.omnifaces.util.Ajax.oncomplete;
import static org.omnifaces.util.BeansLocal.getInstance;
@@ -84,7 +84,7 @@
private static final Logger logger = Logger.getLogger(ViewScopeManager.class.getName());
private static final ResourceIdentifier SCRIPT_ID = new ResourceIdentifier(LIBRARY_NAME, SCRIPT_NAME);
private static final ResourceIdentifier SCRIPT_ID = new ResourceIdentifier(OMNIFACES_LIBRARY_NAME, OMNIFACES_SCRIPT_NAME);
private static final String SCRIPT_INIT = "OmniFaces.Unload.init('%s')";
private static final int DEFAULT_BEANS_PER_VIEW_SCOPE = 3;
@@ -208,13 +208,13 @@ private static void registerUnloadScript(UUID beanStorageId) {
if (!Hacks.isScriptResourceRendered(context, SCRIPT_ID)) {
if (ajaxRequestWithPartialRendering) {
load(LIBRARY_NAME, UNLOAD_SCRIPT_NAME);
load(OMNIFACES_LIBRARY_NAME, OMNIFACES_UNLOAD_SCRIPT_NAME);
}
else if (context.getCurrentPhaseId() != PhaseId.RENDER_RESPONSE || TRUE.equals(context.getAttributes().get(StateManager.IS_BUILDING_INITIAL_STATE))) {
addScriptResourceToHead(LIBRARY_NAME, SCRIPT_NAME);
addScriptResourceToHead(OMNIFACES_LIBRARY_NAME, OMNIFACES_SCRIPT_NAME);
}
else {
addScriptResourceToBody(LIBRARY_NAME, UNLOAD_SCRIPT_NAME);
addScriptResourceToBody(OMNIFACES_LIBRARY_NAME, OMNIFACES_UNLOAD_SCRIPT_NAME);
}
}
@@ -16,6 +16,11 @@
import static java.lang.String.format;
import static java.util.Collections.singleton;
import static java.util.Collections.unmodifiableList;
import static javax.faces.application.ResourceHandler.JSF_SCRIPT_LIBRARY_NAME;
import static javax.faces.application.ResourceHandler.JSF_SCRIPT_RESOURCE_NAME;
import static javax.faces.component.behavior.ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME;
import static org.omnifaces.config.OmniFaces.OMNIFACES_LIBRARY_NAME;
import static org.omnifaces.config.OmniFaces.OMNIFACES_SCRIPT_NAME;
import static org.omnifaces.config.OmniFaces.getMessage;
import static org.omnifaces.el.functions.Numbers.formatBytes;
import static org.omnifaces.util.Ajax.update;
@@ -243,8 +248,8 @@
* @since 2.5
*/
@FacesComponent(InputFile.COMPONENT_TYPE)
@ResourceDependency(library="javax.faces", name="jsf.js", target="head") // Required for jsf.ajax.request.
@ResourceDependency(library="omnifaces", name="omnifaces.js", target="head") // Specifically inputfile.js.
@ResourceDependency(library=JSF_SCRIPT_LIBRARY_NAME, name=JSF_SCRIPT_RESOURCE_NAME, target="head") // Required for jsf.ajax.request.
@ResourceDependency(library=OMNIFACES_LIBRARY_NAME, name=OMNIFACES_SCRIPT_NAME, target="head") // Specifically inputfile.js.
public class InputFile extends HtmlInputFile {
// Public constants -----------------------------------------------------------------------------------------------
@@ -278,7 +283,7 @@
@Override
public void decode(FacesContext context) {
if ("validationFailed".equals(getRequestParameter(context, "omnifaces.event"))
&& getClientId(context).equals(getRequestParameter(context, "javax.faces.source")))
&& getClientId(context).equals(getRequestParameter(context, BEHAVIOR_SOURCE_PARAM_NAME)))
{
String fileName = getRequestParameter(context, "fileName");
addError(getClientId(context), getMaxsizeMessage(), Components.getLabel(this), fileName, formatBytes(getMaxsize()));
@@ -14,6 +14,13 @@
import static java.lang.Boolean.FALSE;
import static java.lang.String.format;
import static javax.faces.application.ResourceHandler.JSF_SCRIPT_LIBRARY_NAME;
import static javax.faces.application.ResourceHandler.JSF_SCRIPT_RESOURCE_NAME;
import static javax.faces.component.behavior.ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME;
import static javax.faces.event.PhaseId.APPLY_REQUEST_VALUES;
import static javax.faces.event.PhaseId.INVOKE_APPLICATION;
import static org.omnifaces.config.OmniFaces.OMNIFACES_LIBRARY_NAME;
import static org.omnifaces.config.OmniFaces.OMNIFACES_SCRIPT_NAME;
import static org.omnifaces.util.Components.getParams;
import static org.omnifaces.util.Components.validateHasParent;
import static org.omnifaces.util.Utils.isEmpty;
@@ -29,7 +36,6 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseId;
import org.omnifaces.component.ParamHolder;
import org.omnifaces.util.Json;
@@ -94,8 +100,8 @@
*/
@Deprecated
@FacesComponent(CommandScript.COMPONENT_TYPE)
@ResourceDependency(library="javax.faces", name="jsf.js", target="head") // Required for jsf.ajax.request.
@ResourceDependency(library="omnifaces", name="omnifaces.js", target="head") // Specifically util.js.
@ResourceDependency(library=JSF_SCRIPT_LIBRARY_NAME, name=JSF_SCRIPT_RESOURCE_NAME, target="head") // Required for jsf.ajax.request.
@ResourceDependency(library=OMNIFACES_LIBRARY_NAME, name=OMNIFACES_SCRIPT_NAME, target="head") // Specifically util.js.
public class CommandScript extends UICommand {
// Public constants -----------------------------------------------------------------------------------------------
@@ -147,11 +153,11 @@ public String getFamily() {
*/
@Override
public void decode(FacesContext context) {
String source = context.getExternalContext().getRequestParameterMap().get("javax.faces.source");
String source = context.getExternalContext().getRequestParameterMap().get(BEHAVIOR_SOURCE_PARAM_NAME);
if (getClientId(context).equals(source)) {
ActionEvent event = new ActionEvent(this);
event.setPhaseId(isImmediate() ? PhaseId.APPLY_REQUEST_VALUES : PhaseId.INVOKE_APPLICATION);
event.setPhaseId(isImmediate() ? APPLY_REQUEST_VALUES : INVOKE_APPLICATION);
queueEvent(event);
}
}
@@ -14,6 +14,10 @@
import static java.lang.Boolean.TRUE;
import static java.lang.String.format;
import static javax.faces.application.ResourceHandler.JSF_SCRIPT_LIBRARY_NAME;
import static javax.faces.application.ResourceHandler.JSF_SCRIPT_RESOURCE_NAME;
import static org.omnifaces.config.OmniFaces.OMNIFACES_LIBRARY_NAME;
import static org.omnifaces.config.OmniFaces.OMNIFACES_SCRIPT_NAME;
import static org.omnifaces.util.Components.getCurrentForm;
import java.io.IOException;
@@ -75,8 +79,8 @@
* @see ScriptFamily
*/
@FacesComponent(Highlight.COMPONENT_TYPE)
@ResourceDependency(library="javax.faces", name="jsf.js", target="head") // Required for jsf.ajax.addOnEvent.
@ResourceDependency(library="omnifaces", name="omnifaces.js", target="head") // Specifically highlight.js.
@ResourceDependency(library=JSF_SCRIPT_LIBRARY_NAME, name=JSF_SCRIPT_RESOURCE_NAME, target="head") // Required for jsf.ajax.request.
@ResourceDependency(library=OMNIFACES_LIBRARY_NAME, name=OMNIFACES_SCRIPT_NAME, target="head") // Specifically highlight.js.
public class Highlight extends OnloadScript {
// Public constants -----------------------------------------------------------------------------------------------
@@ -30,13 +30,13 @@
// Public constants -----------------------------------------------------------------------------------------------
/** Returns the "omnifaces" resource library name. */
public static final String LIBRARY_NAME = "omnifaces";
public static final String OMNIFACES_LIBRARY_NAME = "omnifaces";
/** Returns the "omnifaces.js" main script name. */
public static final String SCRIPT_NAME = "omnifaces.js";
public static final String OMNIFACES_SCRIPT_NAME = "omnifaces.js";
/** Returns the "unload.js" unload script name. */
public static final String UNLOAD_SCRIPT_NAME = "unload.js";
public static final String OMNIFACES_UNLOAD_SCRIPT_NAME = "unload.js";
// Constants ------------------------------------------------------------------------------------------------------
@@ -19,6 +19,8 @@
import static java.util.logging.Level.FINE;
import static java.util.regex.Pattern.quote;
import static javax.faces.component.UIComponent.getCompositeComponentParent;
import static javax.faces.component.behavior.ClientBehaviorContext.BEHAVIOR_EVENT_PARAM_NAME;
import static javax.faces.component.behavior.ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME;
import static javax.faces.component.visit.VisitContext.createVisitContext;
import static javax.faces.component.visit.VisitHint.SKIP_ITERATION;
import static javax.faces.component.visit.VisitResult.ACCEPT;
@@ -871,7 +873,7 @@ public static UIComponent getCurrentActionSource() {
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
if (context.getPartialViewContext().isAjaxRequest()) {
String sourceClientId = params.get("javax.faces.source");
String sourceClientId = params.get(BEHAVIOR_SOURCE_PARAM_NAME);
if (sourceClientId != null) {
UIComponent actionSource = findComponentIgnoringIAE(viewRoot, stripIterationIndexFromClientId(sourceClientId));
@@ -1305,7 +1307,7 @@ public static AjaxBehavior createAjaxBehavior(String expression) {
}
if (component instanceof ClientBehaviorHolder) {
String behaviorEvent = getRequestParameter("javax.faces.behavior.event");
String behaviorEvent = getRequestParameter(BEHAVIOR_EVENT_PARAM_NAME);
if (behaviorEvent != null) {
for (BehaviorListener listener : getBehaviorListeners((ClientBehaviorHolder) component, behaviorEvent)) {
@@ -15,6 +15,7 @@
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static java.util.logging.Level.FINE;
import static javax.faces.view.facelets.FaceletContext.FACELET_CONTEXT_KEY;
import static javax.servlet.http.HttpServletResponse.SC_MOVED_PERMANENTLY;
import static org.omnifaces.util.Reflection.instance;
import static org.omnifaces.util.Reflection.toClassOrNull;
@@ -138,11 +139,6 @@
private static final String DEFAULT_MIME_TYPE = "application/octet-stream";
private static final int DEFAULT_SENDFILE_BUFFER_SIZE = 10240;
private static final String ERROR_NO_VIEW = "There is no view.";
private static final String[] FACELET_CONTEXT_KEYS = {
FaceletContext.FACELET_CONTEXT_KEY, // Compiletime constant, may fail when compiled against EE6 and run on EE7.
"com.sun.faces.facelets.FACELET_CONTEXT", // JSF 2.0/2.1.
"javax.faces.FACELET_CONTEXT" // JSF 2.2.
};
// Constructors ---------------------------------------------------------------------------------------------------
@@ -722,14 +718,10 @@ private static void addParamToMapIfNecessary(Map<String, List<String>> map, Stri
* @see Faces#getFaceletContext()
*/
public static FaceletContext getFaceletContext(FacesContext context) {
Map<Object, Object> contextAttributes = context.getAttributes();
FaceletContext faceletContext = getContextAttribute(context, FACELET_CONTEXT_KEY);
for (String key : FACELET_CONTEXT_KEYS) {
FaceletContext faceletContext = (FaceletContext) contextAttributes.get(key);
if (faceletContext != null) {
return faceletContext;
}
if (faceletContext != null) {
return faceletContext;
}
throw new IllegalStateException(ERROR_NO_VIEW);

0 comments on commit 236e93b

Please sign in to comment.