Table of contents
1.
Introduction
2.
JSF h:inputTextarea
2.1.
Tag
2.2.
Attribute Table
2.3.
Example
2.4.
Output
3.
Frequently Asked Questions
3.1.
When is this tag used?
3.2.
Can its width and height vary?
3.3.
Does it have a scrollbar for long texts?
4.
Conclusion
Last Updated: Mar 27, 2024

JSF h:inputTextarea

Author Gurleen Kaur
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

A Java-based web application framework called Java Server Faces (JSF) was created to make it easier to construct and integrate web-based user interfaces. A standardized display technology known as JavaServer Faces was defined in a specification by the Java Community Process.

JSF gives you:

  • Basic library
  • UI foundation components consist of typical HTML input elements
  • To create new UI component libraries or to expand already existing components by extending the foundation UI components
  • JSF UI components can render themselves in a variety of ways depending on the sorts of clients due to multiple rendering capabilities.

Now, coming to this tag is an HTML input element with the type "text" shown by the h:inputText tag. We will further discuss it in detail later.

JSF h:inputTextarea

This is displayed by JSF as an HTML "textarea" element. A multi-line string can be entered by the user using it.

Tag

JSF Tag:

<h:inputTextarea rows=”6” cols=”12” value=" Welcome to Coding Ninjas" />

Rendered HTML tag:

<textarea name="random value" rows=”6” cols=”12” value=" Welcome to Coding Ninjas" />

Attribute Table

Example

index.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://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:form>
            <h:inputTextarea rows="4" cols="12" value="${controlDemo.address}"/><br/><br/>
        <h:commandButton value="Click Me"/> <br/><br/>
        <h:outputText value="${controlDemo.address}"/>
        </h:form>
    </h:body>
</html>

ControlDemo.java

package com.codingninjas;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class ControlDemo {
    // address used as string
    private String address;
    // to return the address value
    public String getAddress()
    {
        return address;
    }
    // to set the address value
    public void setAddress(String address){
        this.address = address;
    }   
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" 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-app_3_1.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

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">
    <managed-bean>
        <managed-bean-name>test</managed-bean-name>
        <managed-bean-class>com.codingninjas.Test</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
</faces-config>

Output

The textarea looks like this:

 

Enter some text as shown: 

 

After clicking the button, the output is:

 

Frequently Asked Questions

When is this tag used?

It is used when the written lines are high and need multi-line.

Can its width and height vary?

Yes, one can make inputTextarea according to the need, and the display user wants.

Does it have a scrollbar for long texts?

Yes, it has a scrollbar.

Conclusion

In this article on JSF, we have extensively discussed the inputTextarea tag. We started with a brief introduction to JSF, the tag, and why to use them, along with an example.

You can refer to our guided paths given on Coding Ninjas Studio to train yourself in JavaScriptCompetitive ProgrammingData Structures and AlgorithmsSystem Design, and many more! To test your competency in coding, check several mock test series and participate in the contests on Coding Ninjas Studio! Even if you have just started your learning process and are simply looking for tech giants like Microsoft, Amazon, Uber, etc. It would help to look at the problemsinterview experiences, and interview bundles for placement preparations.

Do upvote our blogs if you find them helpful and engaging!

Happy learning!

Live masterclass