/*
* 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.base.taglib.html;
import javax.servlet.http.HttpServletRequest;
import de.odysseus.calyxo.base.ModuleContext;
import de.odysseus.calyxo.base.ModuleSupport;
/**
* Form tag to be used within calyxo applications.
* Correctly expands a Calyxo action path into a container-relative path
* by using the current module's context.
*
* @author Christoph Beck
*/
public class FormTag extends BasicTag {
private String action;
private String method;
private String enctype;
private String accept;
private String name;
private String target;
private String onsubmit;
private String onreset;
/**
* Constructor
*/
public FormTag() {
super("form", true);
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.taglib.html.BasicTag#appendAttributes(java.lang.StringBuffer)
*/
protected void appendAttributes(StringBuffer buffer) throws Exception {
super.appendAttributes(buffer);
append(buffer, "action", getActionAttribute());
append(buffer, "method", getMethodAttribute());
append(buffer, "enctype", getEnctypeAttribute());
append(buffer, "accept", getAcceptAttribute());
append(buffer, "name", getNameAttribute());
append(buffer, "target", getTargetAttribute());
append(buffer, "onsubmit", getOnsubmitAttribute());
append(buffer, "onreset", getOnresetAttribute());
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.taglib.html.BasicTag#reset()
*/
protected void reset() {
super.reset();
action = null;
method = null;
enctype = null;
accept = null;
name = null;
onreset = null;
onsubmit = null;
}
/**
* Get action attribute
*/
protected String getActionAttribute() throws Exception {
HttpServletRequest request =
(HttpServletRequest)pageContext.getRequest();
ModuleSupport support = ModuleSupport.getInstance(request);
ModuleContext context = support.getModuleContext(request);
StringBuffer buffer = new StringBuffer();
buffer.append(request.getContextPath());
buffer.append(context.getPath(action));
return buffer.toString();
}
/**
* Get name attribute
*/
protected String getNameAttribute() throws Exception {
return name;
}
/**
* Get target attribute
*/
protected String getTargetAttribute() throws Exception {
return target;
}
/**
* Get method attribute
*/
protected String getMethodAttribute() throws Exception {
return method;
}
/**
* Get enctype attribute
*/
protected String getEnctypeAttribute() throws Exception {
return enctype;
}
/**
* Get onreset attribute
*/
protected String getOnresetAttribute() throws Exception {
return onreset;
}
/**
* Get onsubmit attribute
*/
protected String getOnsubmitAttribute() throws Exception {
return onsubmit;
}
/**
* Get accept attribute
*/
protected final String getAcceptAttribute() {
return accept;
}
/**
* Set action property
*/
public final void setAction(String string) {
action = string;
}
/**
* Set name property
*/
public final void setName(String string) {
name = string;
}
/**
* Set target property
*/
public final void setTarget(String string) {
target = string;
}
/**
* Set method property
*/
public final void setMethod(String string) {
method = string;
}
/**
* Set enctype attribute
*/
public final void setEnctype(String string) {
enctype = string;
}
/**
* Set onreset attribute
*/
public final void setOnreset(String string) {
onreset = string;
}
/**
* Set onsubmit attribute
*/
public final void setOnsubmit(String string) {
onsubmit = string;
}
/**
* Set accept property
*/
public final void setAccept(String string) {
accept = string;
}
/**
* Get accept property
*/
public final String getAccept() {
return accept;
}
/**
* Get action property
*/
public final String getAction() {
return action;
}
/**
* Get enctype property
*/
public final String getEnctype() {
return enctype;
}
/**
* Get method property
*/
public final String getMethod() {
return method;
}
/**
* Get name property
*/
public final String getName() {
return name;
}
/**
* Get target property
*/
public final String getTarget() {
return target;
}
/**
* Get onreset property
*/
public final String getOnreset() {
return onreset;
}
/**
* Get onsubmit property
*/
public final String getOnsubmit() {
return onsubmit;
}
}