CodesJava

Easy learning with example program codes

JSF inputtextarea html tag

JSF h:inputTextarea tag is used to render a HTML textarea field.

JSF tag:

<h:inputTextarea rows=15” cols=20” value="Hello world" />

Rendered HTML tag:

<textarea name="j_idt6:j_idt8" rows=15” cols=20” value="Hello world" />

Attributes of h:inputSecret tag.

AttributeDescription
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.Coordinates 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
21. readonlyRead-only state of an input field
22. styleInline style information
23. tabindexNumerical value specifying a tab index
24. targetThe name of a frame in which a document is opened
25. titleA title used for accessibility. Browsers typically create tooltips for the title’s value
26. typeType of a link; for example, stylesheet
27. widthWidth of an element
28. onblurEvent handler for losing focus
29. onchangeEvent handler for value changes
30. onclickEvent handler for Mouse button clicked over the element
31. ondblclickEvent handler for Mouse button double-clicked
32. onfocusEvent handler for element received focus
33. onkeydownEvent handler for Key pressed
34. onkeypressEvent handler for Key pressed and released
35. onkeyupEvent handler for Key released
36. onmousedownEvent handler for Mouse button pressed
37. onmousemoveEvent handler for mouse moved
38. onmouseoutEvent handler for mouse left
39. onmouseoverEvent handler for mouse moved onto
40. onmouseupEvent handler for mouse button released
41. onresetEvent handler for form reset
42. onselectEvent handler for Text selected
43. immediateProcess validation early in the life cycle

 

Example explanation:

On “test.xhtml” page we have inputtextarea with value attribute. The value of the inputtextarea is binding with the description property of the Test.java class. Click “Check Description” button after entering the value in inputtextarea. JSF framework assign the inputtextarea value to the bean property and “inputtextarea ” 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 which shows the entered description value.

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 input area example.</title>
	</h:head>
    <h:body>
    	<h2>JSF input area example.</h2>
 
    	<h:form>
    	   <h:inputTextarea row="5" col="20" 
    	      value="#{test.description}"/>
    	   <br/> <br/>
    	   <h:commandButton value="Check Description" 
    	      action="#{test.checkDescription}"/>	
    	</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 description;
 
	public String getDescription() {
		return description;
	}
 
	public void setDescription(String description) {
		this.description = description;
	}
 
	public String checkDescription() {
		if(description == null || description.equals("")){
			return "fail";
		}else{
			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-case>
      <from-outcome>fail</from-outcome>
      <to-view-id>test.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">
	<h:head>
		<title>JSF input area example.</title>
	</h:head>
    <h:body> 
    	 <h3>Description: <h:outputText value="#{test.description}"/></h3> 
    </h:body>
</html>

URL:

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

Output:

JSF example6-1
Enter Description.
JSF example6-2
Click on Check Description button.
JSF example6-3
 
Download this example.
 

Please follow and like us:
error
Posted in JSF   








Copyright © 2019 CodesJava DMCA.com Protection Status