You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2004/01/08 17:18:20 UTC
cvs commit: jakarta-struts/src/examples/org/apache/struts/webapp/validator TypeForm.java TypeAction.java RegistrationForm.java RegistrationAction.java MultiRegistrationAction.java MessageResources_ja.properties MessageResources_fr.properties MessageResources.properties LocaleAction.java EditTypeAction.java CityStateZip.java
husted 2004/01/08 08:18:20
Added: src/examples/org/apache/struts/webapp/validator
TypeForm.java TypeAction.java RegistrationForm.java
RegistrationAction.java
MultiRegistrationAction.java
MessageResources_ja.properties
MessageResources_fr.properties
MessageResources.properties LocaleAction.java
EditTypeAction.java CityStateZip.java
Log:
Place source code for validator module under examples.
Revision Changes Path
1.1 jakarta-struts/src/examples/org/apache/struts/webapp/validator/TypeForm.java
Index: TypeForm.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/examples/org/apache/struts/webapp/validator/TypeForm.java,v 1.1 2004/01/08 16:18:19 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/01/08 16:18:19 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.struts.webapp.validator;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;
import org.apache.struts.validator.ValidatorForm;
/**
* Form bean for the user type page.
*
* @author David Wintefeldt
*/
public final class TypeForm extends ValidatorForm implements Serializable {
private String action = null;
private String sByte = null;
private String sShort = null;
private String sInteger = null;
private String sLong = null;
private String sFloat = null;
private String sFloatRange = null;
private String sDouble = null;
private String sDate = null;
private String sCreditCard = null;
private String sSatisfaction = null;
private String[] sOsList = null;
private String sOverallSatisfaction = null;
private String sWouldRecommend = null;
private String[] sUsedLanguages = null;
private List lNames = initNames();
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getByte() {
return sByte;
}
public void setByte(String sByte) {
this.sByte = sByte;
}
public String getShort() {
return sShort;
}
public void setShort(String sShort) {
this.sShort = sShort;
}
public String getInteger() {
return sInteger;
}
public void setInteger(String sInteger) {
this.sInteger = sInteger;
}
public String getLong() {
return sLong;
}
public void setLong(String sLong) {
this.sLong = sLong;
}
public String getFloat() {
return sFloat;
}
public void setFloat(String sFloat) {
this.sFloat = sFloat;
}
/**
* Float field with range checking
* @return
*/
public String getFloatRange() {
return sFloatRange;
}
/**
* Float field with range checking
* @param sFloatRange
*/
public void setFloatRange(String sFloatRange) {
this.sFloatRange = sFloatRange;
}
public String getDouble() {
return sDouble;
}
public void setDouble(String sDouble) {
this.sDouble = sDouble;
}
public String getDate() {
return sDate;
}
public void setDate(String sDate) {
this.sDate = sDate;
}
public String getCreditCard() {
return sCreditCard;
}
public void setCreditCard(String sCreditCard) {
this.sCreditCard = sCreditCard;
}
public String getSatisfaction() {
return sSatisfaction;
}
public void setSatisfaction(String sSatisfaction) {
this.sSatisfaction = sSatisfaction;
}
public String[] getOsList() {
return sOsList;
}
public void setOsList(String[] anOsList) {
this.sOsList = anOsList;
}
public String getOverallSatisfaction() {
return sOverallSatisfaction;
}
public void setOverallSatisfaction(String anOverallSatisfaction) {
this.sOverallSatisfaction = anOverallSatisfaction;
}
public String getWouldRecommend() {
return sWouldRecommend;
}
public void setWouldRecommend(String anWouldRecommend) {
this.sWouldRecommend = anWouldRecommend;
}
public String[] getUsedLanguages() {
return sUsedLanguages;
}
public void setUsedLanguages(String[] anUsedLanguages) {
this.sUsedLanguages = anUsedLanguages;
}
public List getNameList() {
return lNames;
}
public void setNameList(List lNames) {
this.lNames = lNames;
}
/**
* Reset all properties to their default values.
*
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
String reset = (String)request.getAttribute("typeForm.reset");
if ((null != reset)|| ("true".equals(reset))) {
action = null;
sByte = null;
sShort = null;
sInteger = null;
sLong = null;
sFloat = null;
sFloatRange = null;
sDouble = null;
sDate = null;
sCreditCard = null;
sSatisfaction = null;
sOsList = null;
sOverallSatisfaction = null;
sUsedLanguages = null;
}
//lNames = initNames();
}
/**
* Initialize list.
* @return empty list of LabelValueBeans
*/
private static List initNames() {
List lResults = new ArrayList();
for (int i = 0; i < 3; i++) {
lResults.add(new LabelValueBean(null, null));
}
return lResults;
}
}
1.1 jakarta-struts/src/examples/org/apache/struts/webapp/validator/TypeAction.java
Index: TypeAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/examples/org/apache/struts/webapp/validator/TypeAction.java,v 1.1 2004/01/08 16:18:19 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/01/08 16:18:19 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.struts.webapp.validator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* Implementation of <strong>Action</strong> that validates a different 'types'.
*
* @author David Wintefeldt
*/
public final class TypeAction extends Action {
/**
* Commons Logging instance.
*/
private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it).
* Return an <code>ActionForward</code> instance describing where and how
* control should be forwarded, or <code>null</code> if the response has
* already been completed.
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request (if any)
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*
* @return Action to forward to
* @exception Exception if an input/output error or servlet exception occurs
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Was this transaction cancelled?
if (isCancelled(request)) {
if (log.isInfoEnabled()) {
log.info(
" "
+ mapping.getAttribute()
+ " - Type transaction was cancelled");
}
removeFormBean(mapping, request);
return mapping.findForward("success");
}
return mapping.findForward("success");
}
/**
* Convenience method for removing the obsolete form bean.
*
* @param mapping The ActionMapping used to select this instance
* @param request The HTTP request we are processing
*/
protected void removeFormBean(
ActionMapping mapping,
HttpServletRequest request) {
// Remove the obsolete form bean
if (mapping.getAttribute() != null) {
if ("request".equals(mapping.getScope())) {
request.removeAttribute(mapping.getAttribute());
} else {
HttpSession session = request.getSession();
session.removeAttribute(mapping.getAttribute());
}
}
}
}
1.1 jakarta-struts/src/examples/org/apache/struts/webapp/validator/RegistrationForm.java
Index: RegistrationForm.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/examples/org/apache/struts/webapp/validator/RegistrationForm.java,v 1.1 2004/01/08 16:18:19 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/01/08 16:18:19 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.struts.webapp.validator;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.ValidatorForm;
/**
* Form bean for the user registration page.
*
* @author David Wintefeldt
*/
public final class RegistrationForm extends ValidatorForm implements Serializable {
private String action = null;
private String sFirstName = null;
private String sLastName = null;
private String sAddr = null;
private CityStateZip csz = new CityStateZip();
private String sPhone = null;
private String sEmail = null;
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getFirstName() {
return sFirstName;
}
public void setFirstName(String sFirstName) {
this.sFirstName = sFirstName;
}
public String getLastName() {
return sLastName;
}
public void setLastName(String sLastName) {
this.sLastName = sLastName;
}
public String getAddr() {
return sAddr;
}
public void setAddr(String sAddr) {
this.sAddr = sAddr;
}
public CityStateZip getCityStateZip() {
return csz;
}
public void setCityStateZip(CityStateZip csz) {
this.csz = csz;
}
public String getPhone() {
return sPhone;
}
public void setPhone(String sPhone) {
this.sPhone = sPhone;
}
public String getEmail() {
return sEmail;
}
public void setEmail(String sEmail) {
this.sEmail = sEmail;
}
/**
* Reset all properties to their default values.
*
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
action = null;
sFirstName = null;
sLastName = null;
sAddr = null;
csz = new CityStateZip();
sPhone = null;
sEmail = null;
}
}
1.1 jakarta-struts/src/examples/org/apache/struts/webapp/validator/RegistrationAction.java
Index: RegistrationAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/examples/org/apache/struts/webapp/validator/RegistrationAction.java,v 1.1 2004/01/08 16:18:19 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/01/08 16:18:19 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.struts.webapp.validator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* Implementation of <strong>Action</strong> that validates a registration form.
*
* @author David Wintefeldt
*/
public final class RegistrationAction extends Action {
/**
* Commons Logging instance.
*/
private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it).
* Return an <code>ActionForward</code> instance describing where and how
* control should be forwarded, or <code>null</code> if the response has
* already been completed.
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request (if any)
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*
* @return Action to forward to
* @exception Exception if an input/output error or servlet exception occurs
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Was this transaction cancelled?
if (isCancelled(request)) {
if (log.isInfoEnabled()) {
log.info(
" "
+ mapping.getAttribute()
+ " - Registration transaction was cancelled");
}
removeFormBean(mapping, request);
return (mapping.findForward("success"));
}
return mapping.findForward("success");
}
/**
* Convenience method for removing the obsolete form bean.
*
* @param mapping The ActionMapping used to select this instance
* @param request The HTTP request we are processing
*/
protected void removeFormBean(
ActionMapping mapping,
HttpServletRequest request) {
// Remove the obsolete form bean
if (mapping.getAttribute() != null) {
if ("request".equals(mapping.getScope())) {
request.removeAttribute(mapping.getAttribute());
} else {
HttpSession session = request.getSession();
session.removeAttribute(mapping.getAttribute());
}
}
}
}
1.1 jakarta-struts/src/examples/org/apache/struts/webapp/validator/MultiRegistrationAction.java
Index: MultiRegistrationAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/examples/org/apache/struts/webapp/validator/MultiRegistrationAction.java,v 1.1 2004/01/08 16:18:19 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/01/08 16:18:19 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.struts.webapp.validator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
/**
* Implementation of <strong>Action</strong> that validates a multi-page
* registration form.
*
* @author David Wintefeldt
*/
public final class MultiRegistrationAction extends Action {
/**
* Commons Logging instance.
*/
private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it).
* Return an <code>ActionForward</code> instance describing where and how
* control should be forwarded, or <code>null</code> if the response has
* already been completed.
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request (if any)
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*
* @exception Exception if an input/output error or servlet exception occurs
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Extract attributes we will need
RegistrationForm info = (RegistrationForm) form;
// Was this transaction cancelled?
if (isCancelled(request)) {
if (log.isInfoEnabled()) {
log.info(
" "
+ mapping.getAttribute()
+ " - Registration transaction was cancelled");
}
removeFormBean(mapping, request);
return mapping.findForward("success");
}
ActionMessages errors = info.validate(mapping, request);
if (errors != null && errors.isEmpty()) {
if (info.getPage() == 1)
return mapping.findForward("input2");
if (info.getPage() == 2)
return mapping.findForward("success");
} else {
this.saveErrors(request, errors);
if (info.getPage() == 1){
return mapping.findForward("input" + info.getPage());
}
if (info.getPage() == 2){
return mapping.findForward("input" + info.getPage());
}
}
return mapping.findForward("input1");
}
/**
* Convenience method for removing the obsolete form bean.
*
* @param mapping The ActionMapping used to select this instance
* @param request The HTTP request we are processing
*/
protected void removeFormBean(
ActionMapping mapping,
HttpServletRequest request) {
// Remove the obsolete form bean
if (mapping.getAttribute() != null) {
if ("request".equals(mapping.getScope())) {
request.removeAttribute(mapping.getAttribute());
} else {
HttpSession session = request.getSession();
session.removeAttribute(mapping.getAttribute());
}
}
}
}
1.1 jakarta-struts/src/examples/org/apache/struts/webapp/validator/MessageResources_ja.properties
Index: MessageResources_ja.properties
===================================================================
button.cancel=\u30ad\u30e3\u30f3\u30bb\u30eb
button.confirm=\u78ba\u8a8d
button.reset=\u30ea\u30bb\u30c3\u30c8
button.save=\u4fdd\u5b58
# Errors
errors.footer=
errors.header=<h3><font color="red">\u5165\u529b\u30c1\u30a7\u30c3\u30af\u30a8\u30e9\u30fc</font></h3>\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044:
errors.ioException=\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8 {0} \u306e\u51fa\u529b\u3067I/O\u4f8b\u5916\u304c\u767a\u751f\u3057\u307e\u3057\u305f
error.database.missing=<li>\u30e6\u30fc\u30b6\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3002\u30ed\u30b0\u30aa\u30f3\u306e\u8a8d\u8a3c\u304c\u51fa\u6765\u307e\u305b\u3093\u3002</li>
errors.required={0} \u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002
errors.minlength={0} \u306f {1} \u6587\u5b57\u4ee5\u4e0a\u3067\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093
errors.maxlength={0} \u306f {2} \u6587\u5b57\u4ee5\u4e0b\u3067\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002
errors.invalid={0} \u306f\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002
errors.byte={0} \u306fbyte\u578b\u3067\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002
errors.short={0} \u306fshort\u578b\u3067\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002
errors.integer={0} \u306finteger\u578b\u3067\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002
errors.long={0} \u306flong\u578b\u3067\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002
errors.float={0} \u306ffloat\u578b\u3067\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002
errors.double={0} \u306fdouble\u578b\u3067\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002
errors.date={0} \u306f\u65e5\u4ed8\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002
errors.range={0} \u306f {1} \u304b\u3089 {2} \u306e\u9593\u3067\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002
errors.creditcard={0} \u306F\u6B63\u3057\u3044\u30AF\u30EC\u30B8\u30C3\u30C8\u30FC\u30AB\u30FC\u30C9\u756A\u53F7\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002
errors.email={0} \u306F\u6B63\u3057\u3044\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002
# Index Page
index.title=Struts Validator
index.power=Powered by Struts
# Registration Form
registrationForm.title=\u767b\u9332\u30d5\u30a9\u30fc\u30e0
registrationForm.title.create=\u767b\u9332\u8005
registrationForm.title.edit=\u30e6\u30fc\u30b6\u60c5\u5831\u3092\u7de8\u96c6
registrationForm.firstname.displayname=\u540d
registrationForm.lastname.displayname=\u59d3
registrationForm.addr.displayname=\u4f4f\u6240
registrationForm.city.displayname=\u90fd\u5e02
registrationForm.stateprov.displayname=\u5dde
registrationForm.zippostal.displayname=\u90f5\u4fbf\u756a\u53f7
registrationForm.phone.displayname=\u96fb\u8a71\u756a\u53f7
registrationForm.email.displayname=\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9
registrationForm.lastname.maskmsg=\u59d3\u306b\u306f\u7a7a\u767d\u3092\u542b\u3081\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093
# JavaScript Registration Form
jsRegistrationForm.title=JavaScript\u3092\u4f7f\u3063\u305f\u767b\u9332\u30d5\u30a9\u30fc\u30e0
jsRegistrationForm.description=JavaScript\u3092\u4f7f\u3063\u305f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u5165\u529b\u30c1\u30a7\u30c3\u30af\u304a\u3088\u3073\u30b5\u30fc\u30d0\u5074\u5165\u529b\u30c1\u30a7\u30c3\u30af
# Muli-page Registration Form
multiRegistrationForm.title=\u8907\u6570\u30da\u30fc\u30b8\u306b\u308f\u305f\u308b\u767b\u9332\u30d5\u30a9\u30fc\u30e0
multiRegistrationForm.description=JavaScript\u306b\u3088\u308b\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u5165\u529b\u30c1\u30a7\u30c3\u30af\u304a\u3088\u3073\u30b5\u30fc\u30d0\u5074\u5165\u529b\u30c1\u30a7\u30c3\u30af\u3092\u4f34\u3046\u8907\u6570\u30da\u30fc\u30b8\u306b\u308f\u305f\u308b\u767b\u9332\u30d5\u30a9\u30fc\u30e0\u306e\u30b5\u30f3\u30d7\u30eb
# Type form
typeForm.title=\u30c7\u30fc\u30bf\u578b\u30c1\u30a7\u30c3\u30af\u30d5\u30a9\u30fc\u30e0
typeForm.description=\u30d7\u30ea\u30df\u30c6\u30a3\u30d6\u578b\u306e\u6570\u5b57\u3001integer\u306e\u7bc4\u56f2\u3001\u65e5\u4ed8\u3001\u304a\u3088\u3073\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u756a\u53f7\u306e\u5165\u529b\u30c1\u30a7\u30c3\u30af\u306e\u30b5\u30f3\u30d7\u30eb
typeForm.title.create=\u30c7\u30fc\u30bf\u578b\u30c1\u30a7\u30c3\u30af\u30d5\u30a9\u30fc\u30e0
typeForm.byte.displayname=Byte\u578b\u30d5\u30a3\u30fc\u30eb\u30c9
typeForm.short.displayname=Short\u578b\u30d5\u30a3\u30fc\u30eb\u30c9
typeForm.integer.displayname=Integer\u578b\u30d5\u30a3\u30fc\u30eb\u30c9
typeForm.long.displayname=Long\u578b\u30d5\u30a3\u30fc\u30eb\u30c9
typeForm.float.displayname=Float\u578b\u30d5\u30a3\u30fc\u30eb\u30c9
typeForm.floatRange.displayname=Float\u578b\u306e\u7bc4\u56f2\u30c1\u30a7\u30c3\u30af\u30d5\u30a3\u30fc\u30eb\u30c9
typeForm.double.displayname=Double\u578b\u30d5\u30a3\u30fc\u30eb\u30c9
typeForm.date.displayname=\u65e5\u4ed8\u578b\u30d5\u30a3\u30fc\u30eb\u30c9
typeForm.creditCard.displayname=\u30af\u30ec\u30b8\u30c3\u30c8\u30fc\u30ab\u30fc\u30c9\u756a\u53f7\u30d5\u30a3\u30fc\u30eb\u30c9
typeForm.nested=\u30cd\u30b9\u30c8\u3057\u305f\u6587\u5b57\u5217\u306e\u30d5\u30a3\u30fc\u30eb\u30c9
typeForm.nested.name.displayname=\u540d\u524d
# JavaScript Type Form
jsTypeForm.title=JavaScript\u3092\u4f7f\u3063\u305f\u30c7\u30fc\u30bf\u578b\u30c1\u30a7\u30c3\u30af\u30d5\u30a9\u30fc\u30e0
jsTypeForm.description=JavaScript\u3092\u4f7f\u3063\u305f\u5165\u529b\u30c1\u30a7\u30c3\u30af\u304a\u3088\u3073\u30b5\u30fc\u30d0\u5074\u5165\u529b\u30c1\u30a7\u30c3\u30af
# Locale Form
localeForm.fr=\u767b\u9332\u30d5\u30a9\u30fc\u30e0\u3001JavaScript\u3092\u4f7f\u3063\u305f\u767b\u9332\u30d5\u30a9\u30fc\u30e0\u3001\u304a\u3088\u3073\u8907\u6570\u30da\u30fc\u30b8\u306b\u308f\u305f\u308b\u767b\u9332\u30d5\u30a9\u30fc\u30e0\u306b\u3044\u304f\u3064\u304b\u306e\u9055\u3044\u304c\u3042\u308a\u307e\u3059(/WEB-INF/validation.xml \u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044)\u3002\u30c7\u30fc\u30bf\u578b\u30c1\u30a7\u30c3\u30af\u30d5\u30a9\u30fc\u30e0\u3068JavaScript\u3092\u4f7f\u3063\u305f\u30c7\u30fc\u30bf\u578b\u30c1\u30a7\u30c3\u30af\u30d5\u30a9\u30fc\u30e0\u3067\u306finteger\u306e\u30c1\u30a7\u30c3\u30af\u306e\u7bc4\u56f2\u306f50-60\u306b\u306a\u308a\u3001\u65e5\u4ed8\u306e\u66f8\u5f0f\u306f'dd.MM.yyyy'\u306b\u306a\u308a\u307e\u3059\u3002
localeForm.frCA=JavaScript\u3092\u4f7f\u3063\u305f\u30c7\u30fc\u30bf\u578b\u30c1\u30a7\u30c3\u30af\u30d5\u30a9\u30fc\u30e0\u306einteger\u306e\u30c1\u30a7\u30c3\u30af\u306e\u7bc4\u56f2\u306f100-200\u306b\u306a\u308a\u3001\u65e5\u4ed8\u306e\u66f8\u5f0f\u306f'dd-MM-yyyy'\u306b\u306a\u308a\u307e\u3059\u3002
localeForm.ja=JavaScript\u3092\u4f7f\u3063\u305f\u30c7\u30fc\u30bf\u578b\u30c1\u30a7\u30c3\u30af\u30d5\u30a9\u30fc\u30e0\u306einteger\u306e\u30c1\u30a7\u30c3\u30af\u306e\u7bc4\u56f2\u306f400-700\u306b\u306a\u308a\u3001\u65e5\u4ed8\u306e\u66f8\u5f0f\u306f'yyyy/MM/dd'\u306b\u306a\u308a\u307e\u3059\u3002
1.1 jakarta-struts/src/examples/org/apache/struts/webapp/validator/MessageResources_fr.properties
Index: MessageResources_fr.properties
===================================================================
# Correct translations compliments of Regis Brochu
# Some fields have been added after Regis Brochu
# translated the file and may have incorrect translation.
button.cancel=Annuler
button.confirm=Soumettre
button.reset=Effacer
button.save=Sauvegarder
# Errors
errors.footer=
errors.header=<h3><font color="red">Erreur de Validation</font></h3>Vous devez corriger l'erreur(s) suivante avant de continuer :
errors.ioException=Exception d'E/S durant le rendu des messages d'erreur: {0}
error.database.missing=<li>La base de donn�es des utilisateurs est manquante. Impossible de valider les privil�ges de connexion
errors.required={0} est obligatoire.
errors.minlength=Le {0} ne peut pas �tre moins de {1} caract�res.
errors.maxlength=Le {0} ne peut pas �tre plus de {1} caract�res.
errors.invalid={0} est invalide.
errors.byte=Le {0} doit �tre un nombre de type byte.
errors.short=Le {0} doit �tre un nombre de type short.
errors.integer=Le {0} doit �tre un nombre de type integer.
errors.long=Le {0} doit �tre un nombre de type long.
errors.float=Le {0} doit �tre un nombre de type float.
errors.double=Le {0} doit �tre un nombre de type double.
errors.date=Le {0} n'est pas une date.
errors.range=Le {0} n'est pas dans l'intervalle {1} � {2}.
errors.creditcard=Le {0} n'est pas un num�ro de carte de cr�dit valide.
errors.email=Le {0} est une adresse incorrecte de e-mail.
# Index Page
index.title=Struts Validator
index.power=Actionn� par Struts
# Registration Form
registrationForm.title=Enregistrement
registrationForm.title.create=Registre
registrationForm.title.edit=�ditez l'information utilisateur
registrationForm.firstname.displayname=Pr�nom
registrationForm.lastname.displayname=Nom
registrationForm.addr.displayname=Adresse
registrationForm.city.displayname=Ville
registrationForm.stateprov.displayname=�tat/Province
registrationForm.zippostal.displayname=Code postal
registrationForm.phone.displayname=T�l�phone
registrationForm.email.displayname=E-mail
registrationForm.lastname.maskmsg=Le nom peut seulement �tre compos� de lettres et de nombres, aucun espace.
# Javascript Registration Form
jsRegistrationForm.title=Enregistrement de JavaScript
jsRegistrationForm.description=avec la validation de JavaScript de c�t� de client et la validation lat�rale de serveur
# Muli-page Registration Form
multiRegistrationForm.title=De plusieurs pages Fiche
multiRegistrationForm.description=exemple de plusieurs pages avec la validation du c�t� JavaScript de client et la validation lat�rale de serveur
# Type form
typeForm.title=Formulaire de type
typeForm.description=Exemple validant quelques nombres primitifs, un intervalle sur la zone de nombre entier, une date, et un nombre de carte de cr�dit.
typeForm.title.create=Cr�er le formulaire
typeForm.byte.displayname=Champ Octet
typeForm.short.displayname=Champ Short
typeForm.integer.displayname=Champ Entier
typeForm.long.displayname=Champ Long
typeForm.float.displayname=Champ Float
typeForm.floatRange.displayname=Champ Float l'intervalle
typeForm.double.displayname=Champ Double
typeForm.date.displayname=Champ Date
typeForm.creditCard.displayname=Champ Carte de cr�dit
typeForm.nested=Embo�t� Texte
typeForm.nested.name.displayname=Nom
# JavaScript Type Form
jsTypeForm.title=Formulaire de type de JavaScript
jsTypeForm.description=avec la validation de JavaScript de c�t� de client et la validation lat�rale de serveur
# Locale Form
localeForm.fr=Il y a quelques diff�rences sur la fiche, la fiche de JavaScript, et la fiche de plusieurs pages (voient / WEB-INF/validation.xml). Sur la forme de forme de type et de type de JavaScript la zone de nombre entier devrait tomber dans un intervalle de 50-60 et la zone de date devrait avoir un format de ' dd.MM.yyyy '.
localeForm.frCA=Sur la forme de type de JavaScript la zone de nombre entier devrait tomber dans un intervalle de 100-200 et la zone de date devrait avoir un format de ' dd-MM-yyyy '.
localeForm.ja=Sur la forme de type de JavaScript la zone de nombre entier devrait tomber dans un intervalle de 400-700 et la zone de date devrait avoir un format de ' yyyy/MM/dd '.
1.1 jakarta-struts/src/examples/org/apache/struts/webapp/validator/MessageResources.properties
Index: MessageResources.properties
===================================================================
button.cancel=Cancel
button.confirm=Confirm
button.reset=Reset
button.save=Save
# Errors
errors.footer=
errors.header=<h3><font color="red">Validation Error</font></h3>You must correct the following error(s) before proceeding:
errors.ioException=I/O exception rendering error messages: {0}
error.database.missing=<li>User database is missing, cannot validate logon credentials</li>
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be an byte.
errors.short={0} must be an short.
errors.integer={0} must be an integer.
errors.long={0} must be an long.
errors.float={0} must be an float.
errors.double={0} must be an double.
errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is an invalid e-mail address.
# Index Page
index.title=Struts Validator
index.power=Powered by Struts
# Registration Form
registrationForm.title=Registration
registrationForm.title.create=Register
registrationForm.title.edit=Edit User Information
registrationForm.firstname.displayname=First Name
registrationForm.lastname.displayname=Last Name
registrationForm.addr.displayname=Address
registrationForm.city.displayname=City
registrationForm.stateprov.displayname=State
registrationForm.zippostal.displayname=Zip
registrationForm.phone.displayname=Phone
registrationForm.email.displayname=E-mail
registrationForm.lastname.maskmsg=Last Name can only be letters, no spaces.
# JavaScript Registration Form
jsRegistrationForm.title=JavaScript Registration Form
jsRegistrationForm.description=with client side JavaScript validation and server side validation
# Muli-page Registration Form
multiRegistrationForm.title=Multi-page Registration Form
multiRegistrationForm.description=multi-page example with client side JavaScript validation and server side validation
# Type form
typeForm.byte.displayname=Byte Field
typeForm.checkbox.wouldrecommend=I would recommend
typeForm.checkbox.used.languages=Programming Languages used
typeForm.creditCard.displayname=Credit Card
typeForm.date.displayname=Date Field
typeForm.description=Example validating some primitive numbers, a range on the integer field, a date, and a credit card number.
typeForm.double.displayname=Double Field
typeForm.float.displayname=Float Field
typeForm.floatRange.displayname=Float Range Field
typeForm.integer.displayname=Integer Field
typeForm.long.displayname=Long Field
typeForm.nested.name.displayname=Name
typeForm.nested=Nested Text
typeForm.option.os.list=Operating Systems in use
typeForm.option.satisfaction=Satisfaction
typeForm.option.select.many=<Select one or more>
typeForm.option.select.one=<Select One>
typeForm.radio.overall.satisfaction=Overall Satisfaction
typeForm.short.displayname=Short Field
typeForm.title.create=Type Form
typeForm.title=Type Form
# JavaScript Type Form
jsTypeForm.title=JavaScript Type Form
jsTypeForm.description=with JavaScript Validation and Server Validation
# Locale Form
localeForm.fr=There are some differences on the Registration Form, JavaScript Registration Form, and Multi-page Registration form (see /WEB-INF/validation.xml). On the Type Form and JavaScript Type Form the integer field should fall in a range of 50-60 and the date field should have a format of 'dd.MM.yyyy'.
localeForm.frCA=On the JavaScript Type Form the integer field should fall in a range of 100-200 and the date field should have a format of 'dd-MM-yyyy'.
localeForm.ja=On the JavaScript Type Form the integer field should fall in a range of 400-700 and the date field should have a format of 'yyyy/MM/dd'.
1.1 jakarta-struts/src/examples/org/apache/struts/webapp/validator/LocaleAction.java
Index: LocaleAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/examples/org/apache/struts/webapp/validator/LocaleAction.java,v 1.1 2004/01/08 16:18:19 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/01/08 16:18:19 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.struts.webapp.validator;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* Implementation of <strong>Action</strong> that changes the user's
* @link(java.util.Locale and forwards to a page, based on request level
* parameters that are set (language, country, & page).
*
* @author David Wintefeldt
*/
public final class LocaleAction extends Action {
/**
* Commons Logging instance.
*/
private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
/**
* <p>
* Change the user's @link(java.util.Locale) based on @link(ActionForm)
* properties.
* </p>
* <p>
* This <code>Action</code> looks for <code>language</code> and
* <code>country</code> properties on the given form, constructs an
* appropriate Locale object, and sets it as the Struts Locale for this
* user's session.
* Any <code>ActionForm, including a @link(DynaActionForm), may be used.
* </p>
* <p>
* If a <code>page</code> property is also provided, then after
* setting the Locale, control is forwarded to that URI path.
* Otherwise, control is forwarded to "success".
* </p>
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request (if any)
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*
* @return Action to forward to
* @exception java.lang.Exception if an input/output error or servlet exception occurs
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Extract attributes we will need
HttpSession session = request.getSession();
Locale locale = getLocale(request);
String language = null;
String country = null;
String page = null;
try {
language = (String)
PropertyUtils.getSimpleProperty(form, "language");
country = (String)
PropertyUtils.getSimpleProperty(form, "country");
page = (String)
PropertyUtils.getSimpleProperty(form, "page");
} catch (Exception e) {
log.error(e.getMessage(), e);
}
if ((language != null && language.length() > 0) &&
(country != null && country.length() > 0)) {
locale = new java.util.Locale(language, country);
} else if (language != null && language.length() > 0) {
locale = new java.util.Locale(language, "");
}
session.setAttribute(Globals.LOCALE_KEY, locale);
if (null==page) return mapping.findForward("success");
else return new ActionForward(page);
}
}
1.1 jakarta-struts/src/examples/org/apache/struts/webapp/validator/EditTypeAction.java
Index: EditTypeAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/examples/org/apache/struts/webapp/validator/EditTypeAction.java,v 1.1 2004/01/08 16:18:19 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/01/08 16:18:19 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.struts.webapp.validator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;
/**
* Initializes ActionForm.
*
* @author Robert Leland
*/
public final class EditTypeAction extends Action {
/**
* Commons Logging instance.
*/
private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it).
* Return an <code>ActionForward</code> instance describing where and how
* control should be forwarded, or <code>null</code> if the response has
* already been completed.
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request (if any)
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*
* @return Action to forward to
* @exception Exception if an input/output error or servlet exception occurs
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Was this transaction cancelled?
initFormBeans(mapping, form, request);
return mapping.findForward("success");
}
/**
* Convenience method for initializing form bean.
* @param mapping The ActionMapping used to select this instance
* @param request The HTTP request we are processing
*/
protected void initFormBeans(
ActionMapping mapping, ActionForm form,
HttpServletRequest request) {
// Initialize
ArrayList satisfactionList = new ArrayList();
satisfactionList.add(new LabelValueBean("Very Satisfied", "4"));
satisfactionList.add(new LabelValueBean("Satisfied", "3"));
satisfactionList.add(new LabelValueBean("Not Very Satisfied", "2"));
satisfactionList.add(new LabelValueBean("Not Satisfied", "1"));
request.setAttribute("satisfactionList", satisfactionList);
ArrayList osTypes = new ArrayList();
osTypes.add(new LabelValueBean("Mac OsX", "OsX"));
osTypes.add(new LabelValueBean("Windows 95/98/Me", "Win32"));
osTypes.add(new LabelValueBean("Windows NT/2000/XP/2003", "WinNT"));
osTypes.add(new LabelValueBean("Linux", "Linux"));
osTypes.add(new LabelValueBean("BSD NetBSD/FreeBSD/OpenBSD", "BSD"));
request.setAttribute("osTypes", osTypes);
ArrayList languageTypes = new ArrayList();
languageTypes.add(new LabelValueBean("C++", "C++"));
languageTypes.add(new LabelValueBean("C#", "C#"));
languageTypes.add(new LabelValueBean("Java", "java"));
languageTypes.add(new LabelValueBean("Smalltalk", "Smalltalk"));
request.setAttribute("languageTypes", languageTypes);
}
}
1.1 jakarta-struts/src/examples/org/apache/struts/webapp/validator/CityStateZip.java
Index: CityStateZip.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/examples/org/apache/struts/webapp/validator/CityStateZip.java,v 1.1 2004/01/08 16:18:19 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/01/08 16:18:19 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.struts.webapp.validator;
/**
* Just used to provide an indexed properties example.
*
* @author David Wintefeldt
*/
public class CityStateZip implements java.io.Serializable {
private String sCity = null;
private String sStateProv = null;
private String[] sZipPostal = new String[3];
public String getCity() {
return sCity;
}
public void setCity(String sCity) {
this.sCity = sCity;
}
public String getStateProv() {
return sStateProv;
}
public void setStateProv(String sStateProv) {
this.sStateProv = sStateProv;
}
public String getZipPostal(int index) {
return sZipPostal[index];
}
public void setZipPostal(int index, String value) {
this.sZipPostal[index] = value;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org