001: /*
002: * $Id: FieldError.java 561837 2007-08-01 15:19:22Z jholmes $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.components;
022:
023: import java.util.ArrayList;
024: import java.util.List;
025:
026: import javax.servlet.http.HttpServletRequest;
027: import javax.servlet.http.HttpServletResponse;
028:
029: import org.apache.struts2.views.annotations.StrutsTag;
030: import org.apache.struts2.components.Param.UnnamedParametric;
031:
032: import com.opensymphony.xwork2.util.ValueStack;
033:
034: /**
035: * <!-- START SNIPPET: javadoc -->
036: *
037: * Render field errors if they exists. Specific layout depends on the particular theme.
038: *
039: * <!-- END SNIPPET: javadoc -->
040: *
041: * <p/> <b>Examples</b>
042: *
043: * <pre>
044: * <!-- START SNIPPET: example -->
045: *
046: * <!-- example 1 -->
047: * <s:fielderror />
048: *
049: * <!-- example 2 -->
050: * <s:fielderror>
051: * <s:param>field1</s:param>
052: * <s:param>field2</s:param>
053: * </s:fielderror>
054: * <s:form .... >
055: * ....
056: * </s:form>
057: *
058: * OR
059: *
060: * <s:fielderror>
061: * <s:param value="%{'field1'}" />
062: * <s:param value="%{'field2'}" />
063: * </s:fielderror>
064: * <s:form .... >
065: * ....
066: * </s:form>
067: *
068: * <!-- END SNIPPET: example -->
069: * </pre>
070: *
071: *
072: * <p/> <b>Description</b><p/>
073: *
074: *
075: * <pre>
076: * <!-- START SNIPPET: description -->
077: *
078: * Example 1: display all field errors<p/>
079: * Example 2: display field errors only for 'field1' and 'field2'<p/>
080: *
081: * <!-- END SNIPPET: description -->
082: * </pre>
083: *
084: */
085: @StrutsTag(name="fielderror",tldTagClass="org.apache.struts2.views.jsp.ui.FieldErrorTag",description="Render field error (all " + "or partial depending on param tag nested)if they exists")
086: public class FieldError extends UIBean implements UnnamedParametric {
087:
088: private List errorFieldNames = new ArrayList();
089:
090: public FieldError(ValueStack stack, HttpServletRequest request,
091: HttpServletResponse response) {
092: super (stack, request, response);
093: }
094:
095: private static final String TEMPLATE = "fielderror";
096:
097: protected String getDefaultTemplate() {
098: return TEMPLATE;
099: }
100:
101: public void addParameter(Object value) {
102: if (value != null) {
103: errorFieldNames.add(value.toString());
104: }
105: }
106:
107: public List getFieldErrorFieldNames() {
108: return errorFieldNames;
109: }
110: }
|