CodesJava

Easy learning with example program codes

JSF selectmanycheckbox html tag

JSF h:selectManyListbox tag is used to render a multiple select HTML input element of the type “select” with size and multiple specified.

JSF tag:

<h:selectManyListbox value="#{testBean.data}" />
<f:selectItem itemValue="1" itemLabel="Item 1" />
   <f:selectItem itemValue="2" itemLabel="Item 2" />
</h:selectManyListbox>

Rendered HTML tag:

<select name="j_idt6:j_idt8" size="2" multiple="multiple">  
   <option value="1">Item 1</option>
   <option value="2">Item 2</option>
</select>

Attributes of h:selectmanycheckbox tag.

AttributeDescription
idid for the tag
bindingReference to the component used in a backing bean
renderedA boolean value; false would suppress rendering
styleClassCascading stylesheet (CSS) class name
valuevalue binding
valueChangeListenerA method binding that responds to value changes
converterConverter class name
validatorClass name of a validator attached to the component
requiredA boolean; if true, marks the tag as required
accesskeygives focus to an element
acceptComma-separated list of content types for a form
accept-charsetComma- or space-separated list of character encodings for a form.
altAlternative text for nontextual elements such as images
borderPixel value for an element’s border width
charsetCharacter encoding for a linked resource
coordsCoordinates for an element whose shape is a rectangle, circle, or polygon
dirDirection for text. Valid values are ltr (left to right) and rtl (right to left).
disabledDisabled state of an input element or button
hreflangBase language of a resource specified with the href attribute;
langBase language of an element’s attributes and text
maxlengthMaximum number of characters for text fields
readonlyRead-only state of an input field
styleInline style information
tabindexNumerical value specifying a tab index
targetThe name of a frame in which a document is opened
titleA title used for accessibility. Browsers typically create tooltips for the title’s value
typeType of a link; for example, stylesheet
widthWidth of an element
onblurEvent handler for losing focus
onchangeEvent handler for value changes
onclickEvent handler for Mouse button clicked over the element
ondblclickEvent handler for Mouse button double-clicked
onfocusEvent handler for element received focus
onkeydownEvent handler for Key pressed
onkeypressEvent handler for Key pressed and released
onkeyupEvent handler for Key released
onmousedownEvent handler for Mouse button pressed
onmousemoveEvent handler for mouse moved
onmouseoutEvent handler for mouse left
onmouseoverEvent handler for mouse moved onto
onmouseupEvent handler for mouse button released
onresetEvent handler for form reset
onselectEvent handler for Text selected
immediateProcess validation early in the life cycle

Example:

test.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">
	<h:head>
		<title>JSF select many check box example.</title>
	</h:head>
    <h:body>
    	<h2>JSF select many check box example.</h2>
 
    	<h:form>
    	   <h:selectManyCheckbox value="#{test.checkBoxValues}">
    	   	<f:selectItem itemValue="MCA" itemLabel="MCA" />
    	   	<f:selectItem itemValue="CSE" itemLabel="CSE" />
    	   	<f:selectItem itemValue="IT" itemLabel="IT" />
    	   </h:selectManyCheckbox>
    	   <br/> <br/>
    	   <h:commandButton value="Check CheckBox Value" 
    	      action="#{test.checkCheckBoxValue}"/>	
    	</h:form>
 
    </h:body>    
</html>

Test.java

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
 
/**
 * Managed bean.
 * @author codesjava
 */
@ManagedBean(name="test")
@SessionScoped
public class Test {
	private String[] checkBoxValues;
 
	public String[] getCheckBoxValues() {
		return checkBoxValues;
	}
 
	public void setCheckBoxValues(String[] checkBoxValues) {
		this.checkBoxValues = checkBoxValues;
	}
 
	public String checkCheckBoxValue() {
		return "success";
	}
}

faces-config.xml

<?xml version="1.0" encoding="windows-1252"?>
<faces-config version="2.0" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xi="http://www.w3.org/2001/XInclude" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
 
<navigation-rule>
   <from-view-id>test.xhtml</from-view-id>
   <navigation-case>
      <from-outcome>success</from-outcome>
      <to-view-id>welcome.xhtml</to-view-id>
   </navigation-case>   
</navigation-rule>
 
</faces-config>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
    	xmlns="http://java.sun.com/xml/ns/javaee" 
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 
    <servlet>
        <servlet-name>faces</servlet-name>
        <servlet-class>
            javax.faces.webapp.FacesServlet
        </servlet-class>
    </servlet>
 
	<servlet-mapping>
        <servlet-name>faces</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
 
</web-app>

welcome.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">
	<h:head>
		<title>JSF select many check box example.</title>
	</h:head>
    <h:body> 
    	 <h3>Selected CheckBox values: </h3> 
    	 <ui:repeat value="#{test.checkBoxValues}" 
    	        var="selected">
    	 	<h:outputText value="#{selected}"/>
    	 	<br/>
    	 </ui:repeat>
    </h:body>
 
</html>

URL:

http://localhost:7001/JSFExample9/faces/test.xhtml

Output:

JSF example9-1
Check on checkboxes.
JSF example9-2
Click on Check CheckBox Value button.
JSF example9-3
Download this example.

Please follow and like us:
error
Posted in JSF   








Copyright © 2019 CodesJava DMCA.com Protection Status