• Stars
    star
    160
  • Rank 234,703 (Top 5 %)
  • Language
    Java
  • License
    Other
  • Created over 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mojarra, a Jakarta Faces implementation

Eclipse Mojarra

Eclipse's implementation of the Jakarta Faces specification

For Mojarra 2.3 and earlier please contact your vendor for support (RedHat, IBM, Oracle, Omnifish, Payara, etceteras)

Minimum Requirements

  • Java 11
  • Jakarta Servlet 6.0
  • Jakarta Expression Language 5.0
  • CDI 4.0
  • Jakarta Standard Tag Library 2.0
  • Jakarta Web Socket 2.0 (optional, only when <f:websocket> is used)
  • Jakarta JSON Processing 2.0 (optional, only when <f:websocket> is used)
  • Jakarta Validation 3.0 (optional, only when <f:validateBean> or <f:validateWholeBean> is used)

CDI is explicitly required because since Jakarta Faces 2.3 the javax.faces.bean.* annotations such as @ManagedBean are deprecated, and in 4.0 these have been removed. Several implicit Jakarta Expression Language objects are produced via CDI producers, and <f:websocket> manages the Jakarta WebSocket sessions and events via CDI.

Installation

Depending on the server used, Jakarta Faces may already be built-in (full fledged Jakarta EE containers such as WildFly, JBoss EAP, TomEE, Payara, GlassFish, Liberty, etc.), or not (barebones Jakarta Server Pages/Jakarta Servlet containers such as Tomcat, Jetty, etc.). If the server doesn't ship with Jakarta Faces built-in, then you need to manually install Jakarta Faces 4.0 along with CDI 4.0+, Jakarta JSON Processing 2.0+ and Jakarta Standard Tag Library 2.0+ as those Jakarta Servlet containers usually also don't even ship with those Jakarta Faces dependencies.

Non-Maven

In case you're manually carrying around JARs:

Maven

In case you're using Maven, you can find below the necessary coordinates:

  • Java EE containers (WildFly, JBoss EAP, TomEE, Payara, GlassFish, Liberty, etc)

    <dependency>
       <groupId>jakarta.platform</groupId>
       <artifactId>jakarta.jakartaee-api</artifactId>
       <version>10.0.0</version>
       <scope>provided</scope>
    </dependency>

In case of WildFly/JBoss EAP, you need to manually package jsf-api.jar and jsf-impl.jar based on jakarta.faces.jar first. In case of TomEE, just swap the myfaces*.jar files with jakarta.faces.jar in the server's /lib folder. In case of Payara/GlassFish, just swap the jakarta.faces.jar file in the server's /glassfish/modules folder.

  • Servletcontainers (Tomcat, Jetty, etc)

    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>jakarta.faces</artifactId>
        <version><!-- Use latest 4.0.x version. --></version>
    </dependency>
    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet-shaded</artifactId>
        <version>4.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>jakarta.servlet.jsp.jstl</groupId>
        <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency> <!-- Optional, only when <f:websocket> is used. -->
        <groupId>org.glassfish</groupId>
        <artifactId>jakarta.json</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency> <!-- Optional, only when <f:validateBean> or <f:validateWholeBean> is used. -->
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version><!-- Use latest 8.0.x version. --></version>
    </dependency>

    You can check org.glassfish:jakarta.faces repository to find the latest Mojarra 4.0.x version.

Testing

Since Mojarra 4, tests have been moved to the Faces project.

Hello World Example

We assume that you already know how to create an empty Maven WAR Project or Dynamic Web Project in your favourite IDE with a CDI 4.0+ compatible /WEB-INF/beans.xml deployment descriptor file (which can be kept fully empty). Don't forget to add JARs or configure pom.xml if necessary, as instructed in previous chapter.

Controller

Optionally, register the FacesServlet in a Servlet 6.0+ compatible deployment descriptor file /WEB-INF/web.xml as below:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="https://jakarta.ee/xml/ns/jakartaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
    version="6.0"
>
    <servlet>
        <servlet-name>facesServlet</servlet-name>
        <servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>facesServlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>

Noted should be that Jakarta Faces is already "implicitly" registered and mapped on *.xhtml, *.jsf, *.faces and /faces/* when running on a Jakarta Servlet container. This will be overridden altogether when explicitly registering as above. The *.xhtml URL pattern is preferred over above for security and clarity reasons. When you don't explicitly map it on *.xhtml, then people can still access Faces pages using *.jsf, *.faces or /faces/* URL patterns. This is not nice for SEO as Faces by design doesn't 301-redirect them to a single mapping.

The Faces deployment descriptor file /WEB-INF/faces-config.xml is fully optional.

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="https://jakarta.ee/xml/ns/jakartaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_4_0.xsd"
    version="4.0"
>
    <!-- Put any faces config here. -->
</faces-config>

Model

Then create a backing bean class as below:

package com.example;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;

@Named
@RequestScoped
public class Hello {

    private String name;
    private String message;

    public void createMessage() {
        message = "Hello, " + name + "!";
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMessage() {
        return message;
    }

}

Noted should be that in reality in the average Jakarta EE application the above "model" is further breakdown into a Jakarta Persistence entity, a Jakarta Enterprise Beans service and a smaller backing bean. The Jakarta Persistence entity and Jakarta Enterprise Beans service then basically act as a true "model" and the backing bean becomes a "controller" for that model. This may in first place be confusing to starters, but it all depends on the point of view. See also What components are MVC in Faces MVC framework? and Faces Controller, Service and DAO.

View

Finally create a Facelets file /hello.xhtml as below:

<!DOCTYPE html>
<html lang="en"
    xmlns:f="jakarta.faces.core"
    xmlns:h="jakarta.faces.html">
    <h:head>
        <title>Hello, World!</title>
    </h:head>
    <h:body>
        <h:form>
            <h:outputLabel for="name" value="Enter your name" required="true" />
            <h:inputText id="name" value="#{hello.name}" />
            <h:message for="name" />
            <br />
            <h:commandButton value="Say hello" action="#{hello.createMessage}">
                <f:ajax execute="@form" render="@form" />
            </h:commandButton>
            <br />
            #{hello.message}
        </h:form>
    </h:body>
</html>

Start the server and open it by http://localhost:8080/contextname/hello.xhtml.

Activating CDI in Jakarta Faces 4.0

CDI is activated by default in Jakarta Faces 4.0 and can´t be deactivated.
It´s not required anymore to add @FacesConfig to a CDI managed bean to accomplish this. As of Jakarta Faces 4.0 @FacesConfig still removes the need to explicitly add a FacesServlet entry to web.xml.

Building

In case you want to checkout this repository and manually build from source yourself (if necessary after editing source code), here are the instructions:

Jakarta Faces.Next

  1. Make sure that you have JDK 11, Ant and Maven installed.

  2. Checkout branch master.

  3. Run the following commands from the root directory of the project:

    # under the root dir of project
    mvn clean install
  4. The binary is now available as impl/target/jakarta.faces-4.x.x-SNAPSHOT.jar.

Jakarta Faces 4.0

  1. Make sure that you have JDK 11, Ant and Maven installed.

  2. Checkout branch 4.0.

  3. Run the following commands from the root directory of the project:

    # under the root dir of project
    mvn clean install
  4. The binary is now available as impl/target/jakarta.faces-4.0.x-SNAPSHOT.jar.

Jakarta Faces 3.0

  1. Make sure that you have JDK 1.8, Ant and Maven installed.

  2. Checkout branch 3.0.

  3. Run the following commands from the root directory of the project:

    # under the root dir of project
    mvn clean install
  4. The binary is now available as impl/target/jakarta.faces-3.0.x-SNAPSHOT.jar.

Jakarta Faces 2.3

  1. Make sure that you have JDK 1.8, Ant and Maven installed.

  2. Checkout branch 2.3.

  3. Run the following commands from the root directory of the project:

    # under the root dir of project
    mvn clean install
  4. The binary is now available as impl/target/jakarta.faces-2.3.x-SNAPSHOT.jar.

Jakarta Faces 2.2

Jakarta Faces 2.2 and lower are not supported by Eclipse. If such support is needed, consult your Jakara EE vendor of choice.

Editing source code with IDE

In case you want to checkout to edit the source code of Mojarra with full IDE support, here are the instructions. Note that this only allows you to edit the code. Actually building the Mojarra artefacts still has to be done using the instructions provided above.

Eclipse

Jakarta Faces 4.0

  1. Checkout branch 4.0 using File -> import -> Git
  2. Right click the Mojarra project after checkout, choose Configure -> Convert to Maven Project

Jakarta Faces 3.0

  1. Checkout branch 3.0 using File -> import -> Git
  2. Right click the Mojarra project after checkout, choose Configure -> Convert to Maven Project

Jakarta Faces 2.3

  1. Checkout branch 2.3 using File -> import -> Git
  2. Right click the Mojarra project after checkout, choose Configure -> Convert to Maven Project

Pull Requests

Pull requests are accepted on following branches:

Note that it's okay to send a PR to the master branch, but this one is for Faces.next and not the current 2.3.x or 3.0.x version.

Releasing

pom.xml versions can be adjusted as follows

mvn versions:set -DgroupId=* -DartifactId=* -DoldVersion=* -DgenerateBackupPoms=false -DnewVersion=4.0.1-SNAPSHOT

Resources

More Repositories

1

jersey

Eclipse Jersey Project - Read our Wiki:
Java
689
star
2

glassfish

Eclipse GlassFish
Java
377
star
3

cargotracker

The project demonstrates how you can develop applications with Jakarta EE using widely adopted architectural best practices like Domain-Driven Design (DDD).
JavaScript
342
star
4

ee4j

Eclipse EE4J Top-level Project and community related issues
276
star
5

jaxb-ri

Jaxb RI
Java
202
star
6

yasson

Eclipse Yasson project
Java
201
star
7

eclipselink

Eclipselink project
Java
196
star
8

grizzly

Grizzly
Java
147
star
9

jakartaee-examples

Jakarta EE Examples
Java
124
star
10

tyrus

Tyrus
Java
112
star
11

jakartaee-tutorial

Jakarta EE Tutorial
Ruby
96
star
12

glassfish-hk2

Dynamic dependency injection framework
Java
84
star
13

metro-jax-ws

metro-jax-ws
Java
71
star
14

soteria

Soteria, a Jakarta Security implementation
Java
57
star
15

angus-mail

Angus Mail
Java
53
star
16

krazo

Java
50
star
17

openmq

OpenMQ
Java
50
star
18

starter

Eclipse Starter for Jakarta EE
HTML
50
star
19

glassfish-samples

Java
32
star
20

jakartaee-firstcup-examples

Java
31
star
21

orb

Eclipse ORB is a CORBA orb for use in Jakarta EE and GlassFish and other projects that still need an ORB.
Java
23
star
22

glassfish-concurro

Eclipse Concurrō project
Java
14
star
23

jaxb-istack-commons

Java
13
star
24

metro-saaj

Java
13
star
25

jakartaee-firstcup

First Cup of Jakarta EE Tutorial
CSS
13
star
26

exousia

Exousia, a Jakarta Authorization implementation
Java
11
star
27

parsson

Parsson Project
Java
10
star
28

expressly

Expressly, a Jakarta Expression Language implementation
Java
9
star
29

odi

Open DI
Java
8
star
30

jaxb-fi

Java
8
star
31

jakartaee-tck-tools

Java
7
star
32

wasp

WaSP, a Jakarta Pages implementation
Java
7
star
33

jaxb-stax-ex

Java
7
star
34

grizzly-ahc

Java
7
star
35

jaxb-dtd-parser

Java
7
star
36

metro-wsit

metro-wsit
Java
6
star
37

glassfish-fighterfish

FighterFish project
Java
6
star
38

ee4j-website

Website for the Eclipse EE4J Top Level Project
PHP
6
star
39

eclipselink-workbench

eclipselink-workbench
Java
6
star
40

epicyro

Epicyro, a Jakarta Authentication implementation
Java
6
star
41

angus-activation

Angus Activation
Java
5
star
42

glassfish-shoal

Shoal
Java
5
star
43

glassfish.docker

Official supported GlassFish docker
Dockerfile
5
star
44

jakartaee-release

This repository will be used to help manage the various Jakarta EE releases. No deliverable code will be housed in this repository -- only Issues, PRs, Tools, etc in support of delivering a release
Shell
5
star
45

orb-gmbal-pfl

Java
4
star
46

eclipselink-examples

eclipselink-examples
Java
4
star
47

glassfish-maven-embedded-plugin

Glassfish maven embedded plugin
Java
4
star
48

glassfish-jsftemplating

JSFTemplating project
Java
4
star
49

glassfish-security-plugin

Java
4
star
50

glassfish-repackaged

GlassFish repackaged 3rd party
3
star
51

glassfish-hk2-extra

HK2 extra
Java
3
star
52

glassfish-woodstock

GlassFish Woodstock UI components
Java
3
star
53

jersey.github.io

Jersey project
3
star
54

metro-mimepull

Metro mimepull
Java
3
star
55

glassfish-build-maven-plugin

GlassFish Build Maven Plugin
Java
3
star
56

glassfish-logging-annotation-processor

Java
2
star
57

glassfish-cdi-porting-tck

Java
2
star
58

glassfish-copyright-plugin

Java
2
star
59

glassfish-spec-version-maven-plugin

API Specification Version Maven Plugin
Java
2
star
60

jax-rpc-ri

JAX RPC Implementation (Eclipse Metro Project)
Java
2
star
61

eclipselink-oracleddlparser

eclipselink-oracleddlparser
Java
2
star
62

orb-gmbal-commons

Java
2
star
63

genericmessagingra

Java
2
star
64

grizzly-memcached

Grizzly-memcached
Java
2
star
65

glassfish-doc-plugin

Java
2
star
66

mojarra-jsf-extensions

Java
1
star
67

grizzly-thrift

Grizzly-thrift
Java
1
star
68

jersey-web

The source repository for
HTML
1
star
69

management-api

Jakarta Management
Java
1
star
70

glassfish-ha-api

glassfish-ha-api
Java
1
star
71

metro-xmlstreambuffer

Metro xmlstreambuffer
Java
1
star
72

metro-package-rename-task

Metro package rename
Java
1
star
73

jax-rpc-api

Jakartaee-stable project
Java
1
star
74

jakartaee-renames

1
star
75

glassfish-docs

HTML
1
star
76

gransasso

Eclipse Gransasso Repository
1
star
77

krazo-extensions

Java
1
star
78

debugging-support-for-other-languages-tck

Java
1
star
79

cditck-porting

Standard ML
1
star
80

ditck-porting

Shell
1
star
81

bvtck-porting

Glassfish Bean Validation 2.0 porting kit
Standard ML
1
star