Last active
August 29, 2015 14:23
-
-
Save jyeary/1188d01f30d77f0dbc24 to your computer and use it in GitHub Desktop.
Customized SelectItem with additional attributes from HTML specification that are not present in JSF 2.2 RI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2015 John Yeary <[email protected]>. | |
* | |
* 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 com.bluelotussoftware.component; | |
import javax.faces.model.SelectItem; | |
/** | |
* An extension of the {@link SelectItem} which allows setting of additional | |
* attributes. | |
* | |
* @author John Yeary <[email protected]> | |
* @version 1.0 | |
*/ | |
public class HtmlOption extends SelectItem { | |
private static final long serialVersionUID = -266606679814647297L; | |
/** | |
* Defines a unique identifier (ID) which must be unique in the whole | |
* document. Its purpose is to identify the element when linking (using a | |
* fragment identifier), scripting, or styling (with CSS). | |
*/ | |
private String id; | |
/** | |
* Contains a text representing advisory information related to the element | |
* it belongs to. Such information can typically, but not necessarily, be | |
* presented to the user as a tooltip. | |
*/ | |
private String title; | |
/** | |
* Provides a hint for generating a keyboard shortcut for the current | |
* element. This attribute consists of a space-separated list of characters. | |
* The browser should use the first one that exists on the computer keyboard | |
* layout. | |
*/ | |
private String accesskey; | |
/** | |
* Default constructor. | |
*/ | |
public HtmlOption() { | |
} | |
/** | |
* | |
* @param id The ID to set for the {@literal <option>}. | |
* @param title The title attribute to set. | |
* @param value Value to be delivered to the model if this item is selected | |
* by the user | |
*/ | |
public HtmlOption(String id, String title, Object value) { | |
super(value); | |
this.id = id; | |
this.title = title; | |
} | |
/** | |
* | |
* @param id The ID to set for the {@literal <option>}. | |
* @param title The title attribute to set. | |
* @param value The value to be delivered to the model if this item is | |
* selected by the user. | |
* @param label The label to be rendered for this item in the response. | |
*/ | |
public HtmlOption(String id, String title, Object value, String label) { | |
super(value, label); | |
this.id = id; | |
this.title = title; | |
} | |
/** | |
* | |
* @param id The ID to set for the {@literal <option>}. | |
* @param title The title attribute to set. | |
* @param value The value to be delivered to the model if this item is | |
* selected by the user. | |
* @param label The label to be rendered for this item in the response. | |
* @param description Description of this item, for use in tools. | |
*/ | |
public HtmlOption(String id, String title, Object value, String label, String description) { | |
super(value, label, description); | |
this.id = id; | |
this.title = title; | |
} | |
/** | |
* | |
* @param id The ID to set for the {@literal <option>}. | |
* @param title The title attribute to set. | |
* @param value The value to be delivered to the model if this item is | |
* selected by the user. | |
* @param label The label to be rendered for this item in the response. | |
* @param description Description of this item, for use in tools. | |
* @param disabled Flag indicating that this option is disabled. | |
*/ | |
public HtmlOption(String id, String title, Object value, String label, String description, boolean disabled) { | |
super(value, label, description, disabled); | |
this.id = id; | |
this.title = title; | |
} | |
/** | |
* | |
* @param id The ID to set for the {@literal <option>}. | |
* @param title The title attribute to set. | |
* @param value The value to be delivered to the model if this item is | |
* selected by the user. | |
* @param label The label to be rendered for this item in the response. | |
* @param description Description of this item, for use in tools. | |
* @param disabled Flag indicating that this option is disabled. | |
* @param escape Flag indicating that the text of this option should be | |
* escaped when rendered. | |
*/ | |
public HtmlOption(String id, String title, Object value, String label, String description, boolean disabled, boolean escape) { | |
super(value, label, description, disabled, escape); | |
this.id = id; | |
this.title = title; | |
} | |
/** | |
* | |
* @param id The ID to set for the {@literal <option>}. | |
* @param title The title attribute to set. | |
* @param value The value to be delivered to the model if this item is | |
* selected by the user. | |
* @param label The label to be rendered for this item in the response. | |
* @param description Description of this item, for use in tools. | |
* @param disabled Flag indicating that this option is disabled. | |
* @param escape Flag indicating that the text of this option should be | |
* escaped when rendered. | |
* @param noSelectionOption Flag indicating that the current option is a "no | |
* selection" option. | |
*/ | |
public HtmlOption(String id, String title, Object value, String label, String description, boolean disabled, boolean escape, boolean noSelectionOption) { | |
super(value, label, description, disabled, escape, noSelectionOption); | |
this.id = id; | |
this.title = title; | |
} | |
public String getId() { | |
return id; | |
} | |
public void setId(String id) { | |
this.id = id; | |
} | |
public String getTitle() { | |
return title; | |
} | |
public void setTitle(String title) { | |
this.title = title; | |
} | |
public String getAccesskey() { | |
return accesskey; | |
} | |
public void setAccesskey(String accesskey) { | |
this.accesskey = accesskey; | |
} | |
} |
This is the faces_config.xml.
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<render-kit>
<renderer>
<component-family>javax.faces.SelectOne</component-family>
<renderer-type>javax.faces.Menu</renderer-type>
<renderer-class>com.bluelotussoftware.renderer.CustomMenuRenderer</renderer-class>
</renderer>
</render-kit>
</faces-config>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is an example of how to use the code.