Table of contents
1.
Introduction
2.
h:outputLink
2.1.
Syntax
3.
Attributes of h:outputLink
4.
Example
4.1.
home.xhtml
4.1.1.
Output
5.
Frequently Asked Questions
5.1.
What is the JSF life cycle?
5.2.
What is meant by JSF?
5.3.
What is the prerequisite for running the JSF program?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

JSF h:outputLink

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

Introduction

JavaServer Faces or JSF is a new Java standard technology for building component-based and event-oriented web interfaces. Similar to JavaServer Pages (JSP), JSF allows server-side access to data and logic.

source: Link


In this article, we will understand the outputLink that displays some information or refers to the output screen on the next page. Here we will introduce the implementations and attributes of the h:outputLink tag in JSF.

h:outputLink

JSF offers a range of advanced tag libraries and APIs. Adding components to web pages and connecting them to backend objects is made simpler by tag libraries. For applying component tags, it has handles.

In JSF, the h:outputLink tag is used to render an HTML "anchor" element. The "href" attribute's value represents the component's value. The String to be produced as the value of the "href" attribute as query parameters before rendering is appended with any child UIParameter components whose disable property is false.

Syntax

<h:outputLink value="nextPage">Click Here</h:outputLink>

 

Rendered Output

<a href="nextPage.xhtml">Click Here</a>

Attributes of h:outputLink

There are several attributes for each tag. The JSF h:outputText tag's features are listed below.

  1. id: id for the tag
     
  2. binding: a reference of a backing bean component.
     
  3. rendered: A boolean value where false would suppress the rendering
     
  4. styleClass: Cascading stylesheet (CSS) class name
     
  5. value: a value binding
     
  6. valuechangeListener: a method binding that responds to changes in value
     
  7. converter: class name converter 
     
  8. validator: the component's attached validator's class name
     
  9. required: a boolean value where if the value is true, then it marks the tag as required
     
  10. accesskey: gives focus to an element
     
  11. accept: list of content types for a form, separated by commas
     
  12. accept-charset: character encodings for a form, separated by commas or spaces.
     
  13. alt: alternative text for nontextual elements such as images
     
  14. border: The width of an element's border in pixel value
     
  15. charset: Character encoding for a linked resource
     
  16. coords: Coordinates for an element whose shape is a circle, rectangle, or polygon
     
  17. dir: Direction for text. LTR (left to right) and RTL(right to left) are valid values .
     
  18. hreflang: a resource's href attribute-specified base language.
     
  19. lang: The attributes and text of an element's base language
     
  20. maxlength: maximum number of characters for text field
     
  21. readonly: Read-only state of an input field
     
  22. rel: the relationship between the linked page and the current page
     
  23. rev: reverse link the current document to the anchor you gave in the href attribute.
     
  24. style: For the component, it is used to apply CSS.
     
  25. tabindex: numerical value specifying a tab index
     
  26. target: the name of a frame that opens a document
     
  27. title: A title is made for accessibility. Usually, browsers create tooltips for the title's value.
     
  28. type: this is a type of link. Example: stylesheet
     
  29. width: Element's width
     
  30. onblur: losing focus's event handler
     
  31. onchange: Event handler for value changes
     
  32. onclick: Event handler for the element that was clicked with the mouse
     
  33. ondblclick: Event handler for a double-click on a mouse button
     
  34. onfocus: Event handler for elements received focus
     
  35. onkeydown: Event handler for the key pressed
     
  36. onkeypressed: Event handler for the key pressed or released
     
  37. onmousedown: Event handler for mouse button
     
  38. onmousemove: Event handler for mouse moved
     
  39. onmouseout: Event handler for mouse left
     
  40. onmouseover: Event handler for mouse moved onto
     
  41. onmouseup: Event handler for mouse button released
     
  42. onreset: Event handler for form reset
     
  43. onselect: Event handler for text select

Example

To test the above-mentioned tag, let's build a test JSF application.

home.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
   <head>
      <title>JSF Tutorial!</title>
   </head>
   <body>
      <h2>h:outputLink example</h2>
      <hr />
      <h:form>
         <h:outputLink value = "Welcome to Coding Ninjas.jsf" >Welcome to Coding Ninjas!</h:outputLink>
      </h:form>
   </body>
</html>

 

Output

Frequently Asked Questions

What is the JSF life cycle?

When the client sends an HTTP request for a page to the server, the JavaServer Faces application's lifecycle starts, and it ends when the server returns the page. There are two key stages to the JSF lifecycle: The phase of execution Rendering Stage.

What is meant by JSF?

JSF (Java Server Faces) is a Java-based web application framework designed to make the building of web-based user interfaces more accessible. The Java Community Process codified a definition for JavaServer Faces, a standardized display technology.

What is the prerequisite for running the JSF program?

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

Conclusion

This article extensively discussed the topic of JSF h:outputLink in detail. We started with an introduction and discussed the definition of outputLink with some examples. Later, we also discussed the Attributes of h:outputLink with example. 

We hope that this blog has helped you enhance your knowledge of the JSF h:outputLink and was helpful for you in your journey towards mastering JSF. If you want to learn more, check out our other articles on the topics like JSF f:attributeJSF ParametersJSF Life Cycle, and many more on our platform Coding Ninjas Studio.

For peeps out there who want to learn more about Data Structures, Algorithms, Power programming languages, JavaScript, interview questions, or any other upskilling, please refer to our guided paths on Coding Ninjas Studio. Enroll in our courses, go for mock tests, solve available problems, and interview puzzles. Also, you can focus on interview stuff- interview experiences and an interview bundle for placement preparations.

Do upvote our blog to help other ninjas grow.

Happy Coding!

Live masterclass