📄 baseform.java
字号:
/*
* $Header: /home/cvs/jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/BaseForm.java,v 1.15 2004/03/14 14:32:19 husted Exp $
* $Revision: 1.15 $
* $Date: 2004/03/14 14:32:19 $
*
* Copyright 2001-2004 The Apache Software Foundation.
*
* 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.apache.struts.scaffold;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
// import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
// import org.apache.struts.validator.ValidatorForm; // Struts 1.1
import com.wintecinc.struts.action.ValidatorForm; // Struts 1.0.x
import org.apache.commons.scaffold.lang.ChainedException;
import org.apache.commons.scaffold.lang.Log;
import org.apache.commons.scaffold.lang.Tokens;
import org.apache.commons.scaffold.text.ConvertUtils;
/**
* Enhanced base ActionForm.
* :TODO: Extend from DynaValidatorForm in 1.1 version.
* @version $Revision: 1.15 $ $Date: 2004/03/14 14:32:19 $
*/
public class BaseForm extends ValidatorForm {
// ---------------------------------------------------------- Remote Host
/**
* The network address making this request.
* <p>
* This is the value returned by reqest.getremoteHost.
* It is provided so that this can be logged by components on
* the business tier if needed.
* This property is maintained automatically through the
* <code>reset</code> method.
*/
private String remoteHost = null;
/**
* Return our remoteHost property.
*/
public String getRemoteHost() {
return (this.remoteHost);
}
/**
* Set our remoteHost property.
*/
public void setRemoteHost(String remoteHost) {
this.remoteHost = remoteHost;
}
/**
* Sets RemoteHost attribute to request.getRemoteHost().
*/
protected void resetRemoteHost(HttpServletRequest request) {
setRemoteHost(request.getRemoteHost());
}
// ------------------------------------------------------- Session Locale
/**
* The session attribute key for our session locale [Action.LOCALE_KEY].
* (Suggestion only, may be overridden by presentation framework
*/
public static String STRUTS_LOCALE_KEY = Action.LOCALE_KEY;
/**
* Our locale property.
* <p>
* If the formBean instance is mutable, this is set to the Struts
* session locale whenever <code>reset()</code> is called. to update
* the session locale, use <code>putSessionLocale()</code>.
* <p>
* The properties refer to this as the "SessionLocale" so as to avoid
* naming/signature conflicts with business beans which may also
* maintain a Locale property.
*/
private Locale locale = null;
/**
* Set our locale property.
*
*/
public void setSessionLocale(Locale locale) {
this.locale = locale;
}
/**
* Retrieve our locale property.
*/
public Locale getSessionLocale() {
return this.locale;
}
/**
* Return the session key attribute for our locale object.
*/
public String getSessionLocaleName() {
return STRUTS_LOCALE_KEY;
}
/**
* Reset our locale property to the locale object found in
* the session associated with this request.
*/
protected void resetSessionLocale(HttpServletRequest request) {
HttpSession session = request.getSession();
if (session!=null) {
setSessionLocale((Locale)
session.getAttribute(getSessionLocaleName()));
}
else {
setSessionLocale(Locale.getDefault());
}
} // end resetSessionLocale
/**
* Change the locale property in the session to our locale object,
* or the default Locale if ours is null.
*/
protected void putSessionLocale(HttpServletRequest request) {
Locale locale = getSessionLocale();
if (null==locale) locale = Locale.getDefault();
request.getSession(true).setAttribute(Action.LOCALE_KEY,locale);
} // end putSessionLocale
/**
* Display the user's locale setting or the default locale.
*/
public String getLocaleDisplay() {
Locale locale = getSessionLocale();
if (null==locale) locale = Locale.getDefault();
return locale.getDisplayName();
} // end getLocaleDisplay
/**
* Set our locale to given ISO Language Code.
* An empty String is used for the country.
* <p>
* Mainly provided for completeness.
*/
public void setLocaleDisplay(String language) {
setSessionLocale(new Locale(language,EMPTY));
}
// -------------------------------------------------------------- Mutable
/**
* The mutable state.
* <p>
* To avoid autopopulation when forwarding beans between actions,
* set mutable to be true and be sure all setters observe the
* mutable state.
* <p>
* (<code>if (isMutable()) this.field = field;</code>).
* subject to autopopulation.
*/
private boolean mutable = true;
/**
* Set the mutable state.
*/
public void setMutable(boolean mutable) {
this.mutable = mutable;
}
/**
* Retrieve the mutable state.
*/
public boolean isMutable() {
return this.mutable;
}
// ------------------------------------------------------------- Dispatch
/**
* The dispatch property.
* <p>
* This can be set by a JavaScript buttonto indicate which task should
* be performed (or dispatched) by an action.
* Observes the bean's mutable state.
*/
public String dispatch = null;
/**
* Set dispatch.
*/
public void setDispatch(String dispatch) {
if (isMutable()) this.dispatch = dispatch;
}
/**
* Get the dispatch.
*/
public String getDispatch() {
return this.dispatch;
}
// --------------------------------------------------------- Public Methods
/**
* A static, empty String used by isBlank.
*/
private static String EMPTY = "";
/**
* Convenience method to check for a null or empty String.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -