Package de.odysseus.calyxo.struts.forms.legacy

Source Code of de.odysseus.calyxo.struts.forms.legacy.FlushableActionForm

/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* 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.odysseus.calyxo.struts.forms.legacy;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import de.odysseus.calyxo.struts.forms.FormsDelegate;
import de.odysseus.calyxo.forms.FormData;
import de.odysseus.calyxo.forms.misc.FormDataBean;
import de.odysseus.calyxo.forms.misc.FormDataMap;


/**
* This class can be used as a drop-in replacement to struts' standard
* action form class.
* However, all form bean properties have to be of type
* <code>java.lang.String</code>.
* <p/>
* If you migrate from an existing struts application or want to use
* Calyxo Forms with the struts <code>html</code> tags, this class might
* be your choice. This action form implementation keeps the validated
* form data in a map, so it is available in your actions.
* <p/>
* You should insert a <code>&lt;calyxo-struts:flush&gt;</code>
* tag into your <code>&lt;html:form ...&gt;</code> tag to
* get your form bean properties updated with the formatted values, before
* they are displayed by the tags.
*
* @author Christoph Beck
*/
public class FlushableActionForm extends ActionForm implements FlushableForm {
   private final FormsDelegate delegate = new FormsDelegate();
  private final FormAccessor accessor = new FormAccessor(this);
  private final FormData data;

  /**
   * Default constructor.
   * Uses map-based form data.
   */
  public FlushableActionForm() {
    super();
   
    this.data = new FormDataMap(new HashMap());
  }

  /**
   * Constructor.
   * Uses the specified object as form data bean.
   */
  protected FlushableActionForm(Object bean) {
    super();
   
    this.data = new FormDataBean(bean);
  }

  /* (non-Javadoc)
   * @see de.odysseus.calyxo.struts.forms.legacy.FlushableForm#_setInput(java.lang.String, java.lang.String)
   */
  public void _setInput(String name, String value) {
    accessor._setInput(name, value);
  }

  /* (non-Javadoc)
   * @see de.odysseus.calyxo.struts.forms.legacy.FlushableForm#_setInputs(java.lang.String, java.lang.String[])
   */
  public void _setInputs(String name, String[] values) {
    accessor._setInputs(name, values);
  }

  /* (non-Javadoc)
   * @see de.odysseus.calyxo.forms.FormData#_getProperty(java.lang.String)
   */
  public Object _getProperty(String name) throws Exception {
    return data._getProperty(name);
  }

  /* (non-Javadoc)
   * @see de.odysseus.calyxo.forms.FormData#_setProperty(java.lang.String, java.lang.Object)
   */
  public void _setProperty(String name, Object value) throws Exception {
    data._setProperty(name, value);
  }

  /* (non-Javadoc)
   * @see de.odysseus.calyxo.forms.FormData#_getWrapped()
   */
  public Object _getWrapped() {
    return data._getWrapped();
  }

  /* (non-Javadoc)
   * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
   */
  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
      return delegate.validate(mapping, request, accessor);
  }
}
TOP

Related Classes of de.odysseus.calyxo.struts.forms.legacy.FlushableActionForm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.