/*
* 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.ActionMapping;
import org.apache.struts.action.DynaActionForm;
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
* dyna action form class.
* However, all dynamic 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><calyxo-struts:flush></code>
* tag into your <code><html:form ...></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 FlushableDynaActionForm extends DynaActionForm implements FlushableForm {
private final FormsDelegate delegate = new FormsDelegate();
private final DynaFormAccessor accessor = new DynaFormAccessor(this);
private final FormData data;
/**
* Default constructor.
* Uses map-based form data.
*/
public FlushableDynaActionForm() {
super();
this.data = new FormDataMap(new HashMap());
}
/**
* Constructor.
* Uses the specified object as form data bean.
*/
protected FlushableDynaActionForm(Object bean) {
super();
this.data = new FormDataBean(bean);
}
/* (non-Javadoc)
* @see de.odysseus.calyxo.struts.forms.legacy.FormOutputValues#_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.FormOutputValues#_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);
}
}