📄 facesutils.java
字号:
/* * Copyright 2002-2004 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 de.mindmatters.faces;import javax.faces.application.ViewHandler;import javax.faces.context.FacesContext;import javax.servlet.http.HttpServletRequest;import org.springframework.util.Assert;/** * Miscellaneous faces utility methods. Mainly for internal use within the * framework. * * @author Andreas Kuhrwahl */public final class FacesUtils { /** * Parameter name for the view id. The view id is mainly used as hidden * field to handle the <em>Restore View</em> phase of a submitted form * request. */ public static final String VIEWID_PARAM = "view"; /** * Parameter name for the transient flag. The transient flag is mainly used * as hidden field to handle the <em>Restore View</em> phase of a * post-submitted form request without any state. */ public static final String TRANSIENT_PARAM = "transient"; /** * Private Constructor - it's a static class. */ private FacesUtils() { } /** * Try to guess if this is a postback request. We use a simple heuristic: * for HttpServletRequests, "POST" and "PUT" are postbacks. For anything * that isn't an HttpServletRequest, just guess that if there's a request * parameter, it's probably a postback. * * @param context * FacesContext that holds request information * @return <code>true</code> if it's a postback request <code>false</code> * otherwise. */ public static boolean isPostback(final FacesContext context) { Object requestObject = context.getExternalContext().getRequest(); if (requestObject instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) requestObject; String method = request.getMethod(); if ("POST".equals(method) || "PUT".equals(method)) { return true; } return false; } else { return !context.getExternalContext().getRequestParameterMap() .isEmpty(); } } /** * Returns the value to use for the default extension if the webapp is using * url extension mapping. * * @param context * FacesContext that holds request information * @return The default suffix */ public static String getDefaultSuffix(final FacesContext context) { String suffix = context.getExternalContext().getInitParameter( ViewHandler.DEFAULT_SUFFIX_PARAM_NAME); if (suffix == null) { suffix = ViewHandler.DEFAULT_SUFFIX; } return suffix; } /** * Encodes the view id of the current * {@link javax.faces.component.UIViewRoot}. * * @param context * FacesContext that holds request information * @return The encoded view id */ public static String encodeViewId(final FacesContext context) { String viewId = context.getViewRoot().getViewId(); viewId = viewId.substring(1, viewId.lastIndexOf('.')); return viewId; } /** * Decodes the view id of the current request. * * @param context * FacesContext that holds request information * @return The decoded view id */ public static String decodeViewId(final FacesContext context) { String viewId = (String) context.getExternalContext() .getRequestParameterMap().get(FacesUtils.VIEWID_PARAM); if (viewId != null) { viewId = '/' + viewId + getDefaultSuffix(context); } return viewId; } /** * Checks whether the string <code>value</code> is a value binding * compatible string or not. * * @param value * the string to check * @return <code>true</code> if <code>value</code> is a value binding * compatible string else <code>false</code> */ public static boolean isValueReference(final String value) { Assert.notNull(value); return value.indexOf("#{") != -1 && value.indexOf("#{") < value.indexOf('}'); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -