
com.sun.webui.jsf.component.Alert Maven / Gradle / Ivy
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2007-2018 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://oss.oracle.com/licenses/CDDL+GPL-1.1
* or LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.webui.jsf.component;
import com.sun.faces.annotation.Component;
import com.sun.faces.annotation.Property;
import com.sun.webui.theme.Theme;
import com.sun.webui.jsf.theme.ThemeImages;
import com.sun.webui.jsf.util.ThemeUtilities;
import com.sun.webui.jsf.util.ComponentUtilities;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
/**
* The Alert component is used to render an inline alert message.
*/
@Component(type = "com.sun.webui.jsf.Alert", family = "com.sun.webui.jsf.Alert",
helpKey = "projrave_ui_elements_palette_wdstk-jsf1.2_alert",
propertiesHelpKey = "projrave_ui_elements_palette_wdstk-jsf1.2_propsheets_alert_props")
public class Alert extends UIOutput implements NamingContainer {
/**
* Facet name for alert image
*/
public static final String ALERT_IMAGE_FACET = "alertImage"; //NOI18N
/**
* Facet name for the alert link
*/
public static final String ALERT_LINK_FACET = "alertLink"; //NOI18N
/**
* Default Constructor.
*/
public Alert() {
super();
setRendererType("com.sun.webui.jsf.Alert");
}
/**
* Return the family for this component.
*/
@Override
public String getFamily() {
return "com.sun.webui.jsf.Alert";
}
/**
* Return a component that implements an alert image.
* If a facet named alertImage
is found
* that component is returned.
* If a facet is not found an Icon
* component instance is returned with the id
* alertImage
. The Icon
instance is
* intialized with the values from
*
*
* getType()
if a valid type, else
* ThemeImages.ALERT_ERROR_LARGE
* getAlt()
if not null
*
*
*
* If a facet is not defined then the returned Icon
* component is created every time this method is called.
*
* @return - alertImage facet or an Icon instance
*/
public UIComponent getAlertIcon() {
UIComponent imageFacet = getFacet(ALERT_IMAGE_FACET);
if (imageFacet != null) {
return imageFacet;
}
// No need to save it as a facet.
// Make sure to set parent, for clientId.
//
Theme theme =
ThemeUtilities.getTheme(FacesContext.getCurrentInstance());
String iconidentifier = getIconIdentifier();
Icon icon = ThemeUtilities.getIcon(theme, iconidentifier);
icon.setId(ALERT_IMAGE_FACET);
icon.setParent(this);
String iconalt = getAlt();
if (iconalt != null) {
icon.setAlt(iconalt);
}
return icon;
}
/**
* Return a component that implements an alert link.
* If a facet named alertLink
is found
* that component is returned.
* If a facet is not defined and getLinkText()
* returns non null, an IconHyperlink
* component instance is created with the id
* alertLink
and initialized with the values from:
*
* getLinkTarget()
* getLinkText()
* getLinkToolTip()
* getLinkURL()
* getLinkAction()
* ThemeImages.HREF_LINK
*
* If getLinkText()
returns null, null is returned.
*
* If a facet is not defined and if a IconHyperlink
* component is created, it is reinitialized every time this method
* is called.
*
* @return - alertLink facet or a IconHyperlink instance or null
*/
public UIComponent getAlertLink() {
UIComponent linkFacet = getFacet(ALERT_LINK_FACET);
if (linkFacet != null) {
return linkFacet;
}
// Get the private facet.
IconHyperlink h = (IconHyperlink) ComponentUtilities.getPrivateFacet(
this, ALERT_LINK_FACET, false);
// If getLinkText() returns null, null is returned.
//
String linktext = getLinkText();
if (linktext == null) {
// Remove the previously created private facet.
if (h != null) {
ComponentUtilities.removePrivateFacet(this, ALERT_LINK_FACET);
}
return null;
}
// Return the private facet or create one, but initialize
// it every time, except for the id.
//
if (h == null) {
h = new IconHyperlink();
h.setId(ALERT_LINK_FACET); // NOI18N
ComponentUtilities.putPrivateFacet(this, ALERT_LINK_FACET, h);
}
h.setIcon(ThemeImages.HREF_LINK);
h.setTarget(getLinkTarget());
h.setText(linktext);
h.setToolTip(getLinkToolTip());
h.setUrl(getLinkURL());
MethodExpression action = getLinkActionExpression();
if (action != null) {
h.setActionExpression(action);
}
return h;
}
private String getIconIdentifier() {
String type = getType();
if (type != null) {
String lower = type.toLowerCase();
if (lower.startsWith("warn")) { // NOI18N
return ThemeImages.ALERT_WARNING_LARGE;
} else if (lower.startsWith("ques")) { // NOI18N
return ThemeImages.ALERT_HELP_LARGE;
} else if (lower.startsWith("info")) { // NOI18N
return ThemeImages.ALERT_INFO_LARGE;
} else if (lower.startsWith("succ")) { // NOI18N
return ThemeImages.ALERT_SUCCESS_LARGE;
}
}
return ThemeImages.ALERT_ERROR_LARGE;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Tag attribute methods
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* The component identifier for this component. This value must be unique
* within the closest parent component that is a naming container.
*/
@Property(name = "id")
@Override
public void setId(String id) {
super.setId(id);
}
/**
* Use the rendered attribute to indicate whether the HTML code for the
* component should be included in the rendered HTML page. If set to false,
* the rendered HTML page does not include the HTML for the component. If
* the component is not rendered, it is also not processed on any subsequent
* form submission.
*/
@Property(name = "rendered")
@Override
public void setRendered(boolean rendered) {
super.setRendered(rendered);
}
// Hide converter
@Property(name = "converter", isHidden = true, isAttribute = false)
@Override
public Converter getConverter() {
return super.getConverter();
}
// Hide value
@Property(name = "value", isHidden = true, isAttribute = false)
@Override
public Object getValue() {
return super.getValue();
}
/**
* Alternative textual description of the image rendered by this component. The alt
* text can be used by screen readers and in tool tips, and when image display is turned off in
* the web browser.
*/
@Property(name = "alt", displayName = "Alt Text", category = "Accessibility", editorClassName = "com.sun.rave.propertyeditors.StringPropertyEditor")
private String alt = null;
/**
* Alternative textual description of the image rendered by this component. The alt
* text can be used by screen readers and in tool tips, and when image display is turned off in
* the web browser.
*/
public String getAlt() {
if (this.alt != null) {
return this.alt;
}
ValueExpression _vb = getValueExpression("alt");
if (_vb != null) {
return (String) _vb.getValue(getFacesContext().getELContext());
}
return null;
}
/**
* Alternative textual description of the image rendered by this component. The alt
* text can be used by screen readers and in tool tips, and when image display is turned off in
* the web browser.
* @see #getAlt()
*/
public void setAlt(String alt) {
this.alt = alt;
}
/**
* Optional detailed message text for the alert. This message might include more information about the alert and instructions for what to do about the alert.
*/
@Property(name = "detail", displayName = "Detail Message", category = "Appearance", editorClassName = "com.sun.rave.propertyeditors.StringPropertyEditor")
private String detail = null;
/**
* Optional detailed message text for the alert. This message might include more information about the alert and instructions for what to do about the alert.
*/
public String getDetail() {
if (this.detail != null) {
return this.detail;
}
ValueExpression _vb = getValueExpression("detail");
if (_vb != null) {
return (String) _vb.getValue(getFacesContext().getELContext());
}
return null;
}
/**
* Optional detailed message text for the alert. This message might include more information about the alert and instructions for what to do about the alert.
* @see #getDetail()
*/
public void setDetail(String detail) {
this.detail = detail;
}
/**
* The linkActionExpression attribute is used to specify the action to take when the
* embedded hyperlink component is activated by the user. The value of the
* linkActionExpression attribute must be one of the following:
*
* -
* an outcome string, used to indicate which page to display next, as defined by a
* navigation rule in the application configuration resource file
(faces-config.xml)
.
*
* - a JavaServer Faces EL expression that resolves
* to a backing bean method. The method must take no parameters and return
* an outcome string. The class that defines the method must implement the
* java.io.Serializable
interface or javax.faces.component.StateHolder
* interface.
*
*/
@Property(name = "linkActionExpression", isHidden = true, displayName = "Link Action Method Expression", category = "Navigation")
@Property.Method(signature = "java.lang.String action()")
private javax.el.MethodExpression linkActionExpression = null;
/**
* The linkActionExpression attribute is used to specify the action to take when the
* embedded hyperlink component is activated by the user. The value of the
* linkActionExpression attribute must be one of the following:
*
* -
* an outcome string, used to indicate which page to display next, as defined by a
* navigation rule in the application configuration resource file
(faces-config.xml)
.
*
* - a JavaServer Faces EL expression that resolves
* to a backing bean method. The method must take no parameters and return
* an outcome string. The class that defines the method must implement the
* java.io.Serializable
interface or javax.faces.component.StateHolder
* interface.
*
*/
public javax.el.MethodExpression getLinkActionExpression() {
if (this.linkActionExpression != null) {
return this.linkActionExpression;
}
ValueExpression _vb = getValueExpression("linkActionExpression");
if (_vb != null) {
return (javax.el.MethodExpression) _vb.getValue(getFacesContext().getELContext());
}
return null;
}
/**
* The linkActionExpression attribute is used to specify the action to take when the
* embedded hyperlink component is activated by the user. The value of the
* linkActionExpression attribute must be one of the following:
*
* -
* an outcome string, used to indicate which page to display next, as defined by a
* navigation rule in the application configuration resource file
(faces-config.xml)
.
*
* - a JavaServer Faces EL expression that resolves
* to a backing bean method. The method must take no parameters and return
* an outcome string. The class that defines the method must implement the
* java.io.Serializable
interface or javax.faces.component.StateHolder
* interface.
*
* @see #getLinkActionExpression()
*/
public void setLinkActionExpression(javax.el.MethodExpression linkActionExpression) {
this.linkActionExpression = linkActionExpression;
}
/**
* The window (target) in which to load the link that is specified with linkText.
*/
@Property(name = "linkTarget", displayName = "Link Target", category = "Navigation", editorClassName = "com.sun.webui.jsf.component.propertyeditors.FrameTargetsEditor")
private String linkTarget = null;
/**
* The window (target) in which to load the link that is specified with linkText.
*/
public String getLinkTarget() {
if (this.linkTarget != null) {
return this.linkTarget;
}
ValueExpression _vb = getValueExpression("linkTarget");
if (_vb != null) {
return (String) _vb.getValue(getFacesContext().getELContext());
}
return null;
}
/**
* The window (target) in which to load the link that is specified with linkText.
* @see #getLinkTarget()
*/
public void setLinkTarget(String linkTarget) {
this.linkTarget = linkTarget;
}
/**
* The text for an optional link that is appended to the detail message.
*/
@Property(name = "linkText", displayName = "Link Text", category = "Appearance", editorClassName = "com.sun.rave.propertyeditors.StringPropertyEditor")
private String linkText = null;
/**
* The text for an optional link that is appended to the detail message.
*/
public String getLinkText() {
if (this.linkText != null) {
return this.linkText;
}
ValueExpression _vb = getValueExpression("linkText");
if (_vb != null) {
return (String) _vb.getValue(getFacesContext().getELContext());
}
return null;
}
/**
* The text for an optional link that is appended to the detail message.
* @see #getLinkText()
*/
public void setLinkText(String linkText) {
this.linkText = linkText;
}
/**
* Sets the value of the title attribute for the HTML element. The specified text will display as a tooltip if the mouse cursor hovers over the link that is specified with linkText.
*/
@Property(name = "linkToolTip", displayName = "Link Tooltip", category = "Behavior", editorClassName = "com.sun.rave.propertyeditors.StringPropertyEditor")
private String linkToolTip = null;
/**
* Sets the value of the title attribute for the HTML element. The specified text will display as a tooltip if the mouse cursor hovers over the link that is specified with linkText.
*/
public String getLinkToolTip() {
if (this.linkToolTip != null) {
return this.linkToolTip;
}
ValueExpression _vb = getValueExpression("linkToolTip");
if (_vb != null) {
return (String) _vb.getValue(getFacesContext().getELContext());
}
return null;
}
/**
* Sets the value of the title attribute for the HTML element. The specified text will display as a tooltip if the mouse cursor hovers over the link that is specified with linkText.
* @see #getLinkToolTip()
*/
public void setLinkToolTip(String linkToolTip) {
this.linkToolTip = linkToolTip;
}
/**
* Absolute, relative, or context relative (starting with "/") URL to the
* resource to navigate to when the link that is specified with linkText is selected.
*/
@Property(name = "linkURL", displayName = "Link URL", category = "Navigation", editorClassName = "com.sun.webui.jsf.component.propertyeditors.SunWebUrlPropertyEditor")
private String linkURL = null;
/**
* Absolute, relative, or context relative (starting with "/") URL to the
* resource to navigate to when the link that is specified with linkText is selected.
*/
public String getLinkURL() {
if (this.linkURL != null) {
return this.linkURL;
}
ValueExpression _vb = getValueExpression("linkURL");
if (_vb != null) {
return (String) _vb.getValue(getFacesContext().getELContext());
}
return null;
}
/**
* Absolute, relative, or context relative (starting with "/") URL to the
* resource to navigate to when the link that is specified with linkText is selected.
* @see #getLinkURL()
*/
public void setLinkURL(String linkURL) {
this.linkURL = linkURL;
}
/**
* CSS style(s) to be applied to the outermost HTML element when this
* component is rendered.
*/
@Property(name = "style", displayName = "CSS Style(s)", category = "Appearance", editorClassName = "com.sun.jsfcl.std.css.CssStylePropertyEditor")
private String style = null;
/**
* CSS style(s) to be applied to the outermost HTML element when this
* component is rendered.
*/
public String getStyle() {
if (this.style != null) {
return this.style;
}
ValueExpression _vb = getValueExpression("style");
if (_vb != null) {
return (String) _vb.getValue(getFacesContext().getELContext());
}
return null;
}
/**
* CSS style(s) to be applied to the outermost HTML element when this
* component is rendered.
* @see #getStyle()
*/
public void setStyle(String style) {
this.style = style;
}
/**
* CSS style class(es) to be applied to the outermost HTML element when this
* component is rendered.
*/
@Property(name = "styleClass", displayName = "CSS Style Class(es)", category = "Appearance", editorClassName = "com.sun.rave.propertyeditors.StyleClassPropertyEditor")
private String styleClass = null;
/**
* CSS style class(es) to be applied to the outermost HTML element when this
* component is rendered.
*/
public String getStyleClass() {
if (this.styleClass != null) {
return this.styleClass;
}
ValueExpression _vb = getValueExpression("styleClass");
if (_vb != null) {
return (String) _vb.getValue(getFacesContext().getELContext());
}
return null;
}
/**
* CSS style class(es) to be applied to the outermost HTML element when this
* component is rendered.
* @see #getStyleClass()
*/
public void setStyleClass(String styleClass) {
this.styleClass = styleClass;
}
/**
* Summary message text for the alert. This brief message is prominently
* displayed next to the icon.
*/
@Property(name = "summary", displayName = "Summary Message", category = "Appearance", isDefault = true, editorClassName = "com.sun.rave.propertyeditors.StringPropertyEditor")
private String summary = null;
/**
* Summary message text for the alert. This brief message is prominently
* displayed next to the icon.
*/
public String getSummary() {
if (this.summary != null) {
return this.summary;
}
ValueExpression _vb = getValueExpression("summary");
if (_vb != null) {
return (String) _vb.getValue(getFacesContext().getELContext());
}
return null;
}
/**
* Summary message text for the alert. This brief message is prominently
* displayed next to the icon.
* @see #getSummary()
*/
public void setSummary(String summary) {
this.summary = summary;
}
/**
* Position of this element in the tabbing order of the current document.
* Tabbing order determines the sequence in which elements receive
* focus when the tab key is pressed. The value must be an integer
* between 0 and 32767.
*/
@Property(name = "tabIndex", displayName = "Tab Index", category = "Accessibility", editorClassName = "com.sun.rave.propertyeditors.IntegerPropertyEditor")
private int tabIndex = Integer.MIN_VALUE;
private boolean tabIndex_set = false;
/**
* Position of this element in the tabbing order of the current document.
* Tabbing order determines the sequence in which elements receive
* focus when the tab key is pressed. The value must be an integer
* between 0 and 32767.
*/
public int getTabIndex() {
if (this.tabIndex_set) {
return this.tabIndex;
}
ValueExpression _vb = getValueExpression("tabIndex");
if (_vb != null) {
Object _result = _vb.getValue(getFacesContext().getELContext());
if (_result == null) {
return Integer.MIN_VALUE;
} else {
return ((Integer) _result).intValue();
}
}
return Integer.MIN_VALUE;
}
/**
* Position of this element in the tabbing order of the current document.
* Tabbing order determines the sequence in which elements receive
* focus when the tab key is pressed. The value must be an integer
* between 0 and 32767.
* @see #getTabIndex()
*/
public void setTabIndex(int tabIndex) {
this.tabIndex = tabIndex;
this.tabIndex_set = true;
}
/**
* The type or category of alert. This type can be set to
* "information", "success", "warning" or "error". The type specified determines
* which icon is rendered for the alert.
*/
@Property(name = "type", displayName = "Alert Type", category = "Advanced", editorClassName = "com.sun.webui.jsf.component.propertyeditors.AlertTypesEditor")
private String type = null;
/**
* The type or category of alert. This type can be set to
* "information", "success", "warning" or "error". The type specified determines
* which icon is rendered for the alert.
*/
public String getType() {
if (this.type != null) {
return this.type;
}
ValueExpression _vb = getValueExpression("type");
if (_vb != null) {
return (String) _vb.getValue(getFacesContext().getELContext());
}
return null;
}
/**
* The type or category of alert. This type can be set to
* "information", "success", "warning" or "error". The type specified determines
* which icon is rendered for the alert.
* @see #getType()
*/
public void setType(String type) {
this.type = type;
}
/**
* Use the visible attribute to indicate whether the component should be
* viewable by the user in the rendered HTML page. If set to false, the
* HTML code for the component is present in the page, but the component
* is hidden with style attributes. By default, visible is set to true, so
* HTML for the component HTML is included and visible to the user. If the
* component is not visible, it can still be processed on subsequent form
* submissions because the HTML is present.
*/
@Property(name = "visible", displayName = "Visible", category = "Behavior")
private boolean visible = false;
private boolean visible_set = false;
/**
* Use the visible attribute to indicate whether the component should be
* viewable by the user in the rendered HTML page. If set to false, the
* HTML code for the component is present in the page, but the component
* is hidden with style attributes. By default, visible is set to true, so
* HTML for the component HTML is included and visible to the user. If the
* component is not visible, it can still be processed on subsequent form
* submissions because the HTML is present.
*/
public boolean isVisible() {
if (this.visible_set) {
return this.visible;
}
ValueExpression _vb = getValueExpression("visible");
if (_vb != null) {
Object _result = _vb.getValue(getFacesContext().getELContext());
if (_result == null) {
return false;
} else {
return ((Boolean) _result).booleanValue();
}
}
return true;
}
/**
* Use the visible attribute to indicate whether the component should be
* viewable by the user in the rendered HTML page. If set to false, the
* HTML code for the component is present in the page, but the component
* is hidden with style attributes. By default, visible is set to true, so
* HTML for the component HTML is included and visible to the user. If the
* component is not visible, it can still be processed on subsequent form
* submissions because the HTML is present.
* @see #isVisible()
*/
public void setVisible(boolean visible) {
this.visible = visible;
this.visible_set = true;
}
/**
* Restore the state of this component.
*/
@Override
public void restoreState(FacesContext _context, Object _state) {
Object _values[] = (Object[]) _state;
super.restoreState(_context, _values[0]);
this.alt = (String) _values[1];
this.detail = (String) _values[2];
this.linkActionExpression = (javax.el.MethodExpression) restoreAttachedState(_context, _values[3]);
this.linkTarget = (String) _values[4];
this.linkText = (String) _values[5];
this.linkToolTip = (String) _values[6];
this.linkURL = (String) _values[7];
this.style = (String) _values[8];
this.styleClass = (String) _values[9];
this.summary = (String) _values[10];
this.tabIndex = ((Integer) _values[11]).intValue();
this.tabIndex_set = ((Boolean) _values[12]).booleanValue();
this.type = (String) _values[13];
this.visible = ((Boolean) _values[14]).booleanValue();
this.visible_set = ((Boolean) _values[15]).booleanValue();
}
/**
* Save the state of this component.
*/
@Override
public Object saveState(FacesContext _context) {
Object _values[] = new Object[16];
_values[0] = super.saveState(_context);
_values[1] = this.alt;
_values[2] = this.detail;
_values[3] = saveAttachedState(_context, linkActionExpression);
_values[4] = this.linkTarget;
_values[5] = this.linkText;
_values[6] = this.linkToolTip;
_values[7] = this.linkURL;
_values[8] = this.style;
_values[9] = this.styleClass;
_values[10] = this.summary;
_values[11] = new Integer(this.tabIndex);
_values[12] = this.tabIndex_set ? Boolean.TRUE : Boolean.FALSE;
_values[13] = this.type;
_values[14] = this.visible ? Boolean.TRUE : Boolean.FALSE;
_values[15] = this.visible_set ? Boolean.TRUE : Boolean.FALSE;
return _values;
}
}