jakarta.faces.component.html.HtmlCommandScript Maven / Gradle / Ivy
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package jakarta.faces.component.html;
import java.util.ArrayList;
import java.util.List;
import jakarta.el.ValueExpression;
import jakarta.faces.component.UICommand;
/**
*
* Represents an HTML script
element for a function that acts like an ajax form submit. This component must
* be placed inside a form, and requires JavaScript to be enabled in the client.
*
*
* By default, the rendererType
property must be set to "jakarta.faces.Script
". This value can
* be changed by calling the setRendererType()
method.
*
*/
public class HtmlCommandScript extends UICommand {
private static final String OPTIMIZED_PACKAGE = "jakarta.faces.component.";
public HtmlCommandScript() {
super();
setRendererType("jakarta.faces.Script");
}
/**
*
* The standard component type for this component.
*
*/
public static final String COMPONENT_TYPE = "jakarta.faces.HtmlCommandScript";
protected enum PropertyKeys {
autorun, execute, name, onerror, onevent, render, resetValues,;
String toString;
PropertyKeys(String toString) {
this.toString = toString;
}
PropertyKeys() {
}
@Override
public String toString() {
return toString != null ? toString : super.toString();
}
}
/**
*
* Return the value of the autorun
property.
*
*
* @return the property value
*
* Contents: Whether to execute declared JavaScript function during load
event of the window
.
* Defaults to false
.
*/
public boolean isAutorun() {
return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.autorun, false);
}
/**
*
* Set the value of the autorun
property.
*
*
* @param autorun the new property value
*/
public void setAutorun(boolean autorun) {
getStateHelper().put(PropertyKeys.autorun, autorun);
}
/**
*
* Return the value of the execute
property.
*
*
* @return the property value
*
* Contents: This is a space separated list of client identifiers of components that will participate in the "execute"
* portion of the Request Processing Lifecycle. If a literal is specified the identifiers must be space delimited. Any
* of the keywords "@this", "@form", "@all", "@none" may be specified in the identifier list. If not specified, the
* default value of "@this" is assumed. For example, @this clientIdOne clientIdTwo
.
*/
public java.lang.String getExecute() {
return (java.lang.String) getStateHelper().eval(PropertyKeys.execute);
}
/**
*
* Set the value of the execute
property.
*
*
* @param execute the new property value
*/
public void setExecute(java.lang.String execute) {
getStateHelper().put(PropertyKeys.execute, execute);
}
/**
*
* Return the value of the name
property.
*
*
* @return the property value
*
* Contents: Name of JavaScript function to be declared, e.g. name="functionName"
. This can be a namespaced
* function name, e.g. name="ez.functionName"
.
*/
public java.lang.String getName() {
return (java.lang.String) getStateHelper().eval(PropertyKeys.name);
}
/**
*
* Set the value of the name
property.
*
*
* @param name the new property value
*/
public void setName(java.lang.String name) {
getStateHelper().put(PropertyKeys.name, name);
}
/**
*
* Return the value of the onerror
property.
*
*
* @return the property value
*
* Contents: The name of the JavaScript function that will handle errors.
*/
public java.lang.String getOnerror() {
return (java.lang.String) getStateHelper().eval(PropertyKeys.onerror);
}
/**
*
* Set the value of the onerror
property.
*
*
* @param onerror the new property value
*/
public void setOnerror(java.lang.String onerror) {
getStateHelper().put(PropertyKeys.onerror, onerror);
}
/**
*
* Return the value of the onevent
property.
*
*
* @return the property value
*
* Contents: The name of the JavaScript function that will handle UI events.
*/
public java.lang.String getOnevent() {
return (java.lang.String) getStateHelper().eval(PropertyKeys.onevent);
}
/**
*
* Set the value of the onevent
property.
*
*
* @param onevent the new property value
*/
public void setOnevent(java.lang.String onevent) {
getStateHelper().put(PropertyKeys.onevent, onevent);
}
/**
*
* Return the value of the render
property.
*
*
* @return the property value
*
* Contents: This is a space separated list of client identifiers of components that will participate in the "render"
* portion of the Request Processing Lifecycle. If a literal is specified the identifiers must be space delimited. Any
* of the keywords "@this", "@form", "@all", "@none" may be specified in the identifier list. If not specified, the
* default value of "@none" is assumed. For example, @this clientIdOne clientIdTwo
.
*/
public java.lang.String getRender() {
return (java.lang.String) getStateHelper().eval(PropertyKeys.render);
}
/**
*
* Set the value of the render
property.
*
*
* @param render the new property value
*/
public void setRender(java.lang.String render) {
getStateHelper().put(PropertyKeys.render, render);
}
/**
*
* Return the value of the resetValues
property.
*
*
* @return the property value
*
* Contents: Reset specific input values. Interpret the value of the render
attribute as a space separated
* list of client identifiers suitable for passing directly to UIViewRoot.resetValues()
. The implementation
* must cause an ActionListener
to be attached to the ActionSource
component in which this tag
* is nested that calls UIViewRoot.resetValues()
passing the value of the render
attribute as
* the argument.
*/
public java.lang.Boolean getResetValues() {
return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.resetValues);
}
/**
*
* Set the value of the resetValues
property.
*
*
* @param resetValues the new property value
*/
public void setResetValues(java.lang.Boolean resetValues) {
getStateHelper().put(PropertyKeys.resetValues, resetValues);
}
private void handleAttribute(String name, Object value) {
List setAttributes = (List) getAttributes().get("jakarta.faces.component.UIComponentBase.attributesThatAreSet");
if (setAttributes == null) {
String cname = this.getClass().getName();
if (cname != null && cname.startsWith(OPTIMIZED_PACKAGE)) {
setAttributes = new ArrayList<>(6);
getAttributes().put("jakarta.faces.component.UIComponentBase.attributesThatAreSet", setAttributes);
}
}
if (setAttributes != null) {
if (value == null) {
ValueExpression ve = getValueExpression(name);
if (ve == null) {
setAttributes.remove(name);
}
} else if (!setAttributes.contains(name)) {
setAttributes.add(name);
}
}
}
}