Easy learning with example program codes

JSF inputtext html tag

JSF h:inputText tag is used to render an HTML input element of the type “text”.

JSF tag:

<h:inputText value="Hello World" />

Rendered HTML tag:

<input name="j_idt6:j_idt8" type="text" value="Hello World" />

Attributes of h:inputText tag.

1. idid for the tag
2. bindingReference to the component used in a backing bean
3. renderedA boolean value; false would suppress rendering
4. styleClassCascading stylesheet (CSS) class name
5. valuevalue binding
6. valueChangeListenerA method binding that responds to value changes
7. converterConverter class name
8. validatorClass name of a validator attached to the component
9. requiredA boolean; if true, marks the tag as required
10. accesskeygives focus to an element
11. acceptComma-separated list of content types for a form
12. accept-charsetComma- or space-separated list of character encodings for a form.
13. altAlternative text for nontextual elements such as images
14. borderPixel value for an element’s border width
15. charsetCharacter encoding for a linked resource
16. coordsCoordinates for an element whose shape is a rectangle, circle, or polygon
17. dirDirection for text. Valid values are ltr (left to right) and rtl (right to left).
18. disabledDisabled state of an input element or button
19. hreflangBase language of a resource specified with the href attribute;
20. langBase language of an element’s attributes and text
21. maxlengthMaximum number of characters for text fields
22. readonlyRead-only state of an input field
23. styleInline style information
24. tabindexNumerical value specifying a tab index
25. targetThe name of a frame in which a document is opened
26. titleA title used for accessibility. Browsers typically create tooltips for the title’s value
27. typeType of a link; for example, stylesheet
28. widthWidth of an element
29. onblurEvent handler for losing focus
30. onchangeEvent handler for value changes
31. onclickEvent handler for Mouse button clicked over the element
32. ondblclickEvent handler for Mouse button double-clicked
33. onfocusEvent handler for element received focus
34. onkeydownEvent handler for Key pressed
35. onkeypressEvent handler for Key pressed and released
36. onkeyupEvent handler for Key released
37. onmousedownEvent handler for Mouse button pressed
38. onmousemoveEvent handler for mouse moved
39. onmouseoutEvent handler for mouse left
40. onmouseoverEvent handler for mouse moved onto
41. onmouseupEvent handler for mouse button released
42. onresetEvent handler for form reset
43. onselectEvent handler for Text selected
44. immediateProcess validation early in the life cycle

Example explanation:

On “helloworld.xhtml” page we have input text with id and value attribute. The value of the input text is binding with the userName property of the class. Click “Hello” button after entering the value in input text. JSF framework assign the input text value to the bean property and “sayHello” method returns the “success”. This return value is matched with the navigation rules defined in faces-config.xml file and renders the welcome.xhtml page.



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns=""
		<title>JSF input text example.</title>
    	<h2>JSF input text example.</h2> 
    	   <h:inputText id="name" value="#{test.userName}"/>
    	   <br/> <br/>
    	   <h:commandButton value="Hello" 

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
 * Managed bean.
 * @author codesjava
public class Test {
	private String userName;
	public String getUserName() {
		return userName;
	public void setUserName(String userName) {
		this.userName = userName;
	public String sayHello() {
		if(userName == null || userName.equals("")){
			return "fail";
			return "success";


<?xml version="1.0" encoding="windows-1252"?>
<faces-config version="2.0" 


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns=""
		<title>JSF input text example.</title>
    	 <h3>Hello <h:outputText value="#{test.userName}"/></h3> 




JSF example4-1
Enter value in text box.
JSF example4-2
Click on Hello button.
JSF example4-3
Download this example.

Please follow and like us:
Posted in JSF   

Copyright © 2019 CodesJava Protection Status