
org.apache.struts.faces.component.HtmlComponent Maven / Gradle / Ivy
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts.faces.component;
import javax.el.ValueExpression;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
/**
* Custom component that replaces the Struts
* <html:html>
tag.
*/
public class HtmlComponent extends UIOutput {
// ------------------------------------------------------------ Constructors
/**
* Create a new {@link HtmlComponent} with default properties.
*/
public HtmlComponent() {
super();
setRendererType("org.apache.struts.faces.Html");
}
// ------------------------------------------------------ Instance Variables
/**
* Flag indicating we should create a locale.
*/
private boolean locale = true;
private boolean localeSet = false;
/**
* Flag indicating we should render XHTML output.
*/
private boolean xhtml = false;
private boolean xhtmlSet = false;
// ---------------------------------------------------- Component Properties
/**
* Return the component family to which this component belongs.
*/
public String getFamily() {
return "org.apache.struts.faces.Html";
}
/**
* Return a flag indicating whether a locale should be created.
*/
public boolean isLocale() {
if (localeSet) {
return locale;
}
ValueExpression vb = getValueExpression("locale");
if (vb != null) {
Boolean value = (Boolean) vb.getValue(getFacesContext().getELContext());
if (null == value) {
return locale;
}
return value.booleanValue();
} else {
return locale;
}
}
/**
* Set the flag indicating whether a locale should be created.
*
* @param locale The new flag
*/
public void setLocale(boolean locale) {
this.locale = locale;
this.localeSet = true;
}
/**
* Return a flag indicating whether xhtml should be created.
*/
public boolean isXhtml() {
if (xhtmlSet) {
return xhtml;
}
ValueExpression vb = getValueExpression("xhtml");
if (vb != null) {
Boolean value = (Boolean) vb.getValue(getFacesContext().getELContext());
if (null == value) {
return xhtml;
}
return value.booleanValue();
} else {
return xhtml;
}
}
/**
* Set the flag indicating whether xhtml should be created.
*
* @param xhtml The new flag
*/
public void setXhtml(boolean xhtml) {
this.xhtml = xhtml;
this.xhtmlSet = true;
}
// ---------------------------------------------------- StateManager Methods
/**
* Restore the state of this component.
*
* @param context FacesContext
for the current request
* @param state State object from which to restore our state
*/
public void restoreState(FacesContext context, Object state) {
Object values[] = (Object[]) state;
super.restoreState(context, values[0]);
locale = ((Boolean) values[1]).booleanValue();
localeSet = ((Boolean) values[2]).booleanValue();
xhtml = ((Boolean) values[3]).booleanValue();
xhtmlSet = ((Boolean) values[4]).booleanValue();
}
/**
* Save the state of this component.
*
* @param context FacesContext
for the current request
*/
public Object saveState(FacesContext context) {
Object values[] = new Object[5];
values[0] = super.saveState(context);
values[1] = locale ? Boolean.TRUE : Boolean.FALSE;
values[2] = localeSet ? Boolean.TRUE : Boolean.FALSE;
values[3] = xhtml ? Boolean.TRUE : Boolean.FALSE;
values[4] = xhtmlSet ? Boolean.TRUE : Boolean.FALSE;
return values;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy