Table of contents
1.
Introduction
2.
inputHidden Tag
3.
Attributes
4.
Sample Program
5.
Frequently Asked Questions
5.1.
What is JSF?
5.2.
What is a UI?
5.3.
What is a tag?
5.4.
What is localhost?
5.5.
What is the prerequisite to running the JSF program?
6.
Conclusion
Last Updated: Mar 27, 2024

JSF inputHidden Tag

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

Introduction

Every one of us has filled out an online application at least once. You might not be aware that other than details you fill yourself, some hidden data also gets passed through. These can include your machine's local time, IMEI numbers, browser version etc. All these functionalities are achieved through the use of JSF's inputHidden tag. So what are you waiting for? Let's get into the working of this tag. 

inputHidden Tag

It is similar to the 'hidden' element in HTML. It allows you to pass confidential information while submitting forms. Similar to HTML elements, you can provide it with an ID, class name, value, required fields etc. The class name can be targeted using CSS.

Syntax: 

<h:inputHidden value="I love Coding Ninjas" />

Attributes

Attribute

Description

id Defines ID for the tag.
value Holds the current value of the tag.
required Specifies whether the user mandatorily needs to submit data for this tag or not.
class CSS classname for this element.
binding Reference to the component that can be used in a backing bean.
style Used to specify inline styling

Sample Program

A JSF example to render <h:inputHidden/> tag, and access hidden value using JavaScript.

User-managed bean code

package com.coding_ninjas.form;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable;
@ManagedBean(name="ninja")
@SessionScoped
public class UserBean implements Serializable {
String answer = "I'm Hidden value!";
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
} 
}

 

XHTML Page Code

If the button is clicked, print the hidden value using JS.

<?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">
<h:head>
<script type="text/javascript">
function printHiddenValue(){
alert(document.getElementById('myform:hiddenId').value); 
}
</script>
</h:head>
   <h:body>
    <h1>JSF 2 hidden value example</h1>

<h:form id="myform">
    <h:inputHidden value="#{ninja.answer}" id="hiddenId" />
    <h:commandButton type="button" value="ClickMe" onclick="printHiddenValue()" />
     </h:form>

   </h:body>
</html>

Output:

Frequently Asked Questions

What is JSF?

JSF is a UI development framework similar to React. It is based on components as its building blocks. It connects parts to data sources, directly improving security and efficiency.

What is a UI?

It is the space of user and machine interaction. It forms an integral part of user experience (UX), consisting of visual and functional design. UI aims to make it easier for users to interact with the product.

What is a tag?

A tag is a syntactical way of implementing program logic. These tags are like keywords which define how to display elements on the web browser. For example <html>, <img> etc.

What is localhost?

Localhost defines the machine's address, also known as the loopback address. While setting up a local test environment, localhost address's come in handy. For example, if you would ping localhost, it will reflect 127.0.0.1.

What is the prerequisite to running the JSF program?

Java Runtime Environment, JDK, Maven and Apache tomcat facilitate the running of JSF applications.

Conclusion

Finally, you have made it to the end of this article. Congratulations!! In this blog, you learnt about the inputHidden tag in JSF. You went through the tag, its attributes and a sample program.

Source: thecoderpedia.com


After reading about the inputHidden tag, are you not feeling excited to read more articles on the topic of JSF? Don't worry; Coding Ninjas has you covered. To learn, see the JSF.

Please refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. And also, enrol in our courses and refer to the mock test and problems available. Have a look at the interview experiences and interview bundle for placement preparations.

Please do upvote our blogs if you find them helpful and informative!

Happy learning!

Live masterclass