• This repository has been archived on 20/Mar/2021
  • Stars
    star
    164
  • Rank 230,032 (Top 5 %)
  • Language
    Java
  • License
    Other
  • Created over 9 years ago
  • Updated almost 4 years ago

Reviews

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

Repository Details

PLEASE NOTE: This project has moved to Eclipse Foundation and will be archived under the JavaEE GitHub Organization. After Feb. 1, 2021, the new location will be github.com/javaee/mojarra. Mojarra - Oracle's implementation of the JavaServer Faces specification

⚠️This project is now part of the EE4J initiative. The activity on this project has been paused while it is being migrated to the Eclipse Foundation. See here for the overall EE4J transition status.


Mojarra

Oracle's implementation of the JavaServer Faces specification

Minimum Requirements

  • Java 1.8
  • Servlet 3.0 (4.0 recommended)
  • EL 3.0
  • CDI 1.2 (2.0 recommended)
  • JSTL 1.2
  • JSONP 1.1 (optional, only when <f:websocket> is used)
  • BV 1.1 (optional, only when <f:validateBean> or <f:validateWholeBean> is used; 2.0 recommended)

Servlet 4.0 will enable JSF 2.3 to serve resources via HTTP/2 push. CDI is explicitly required because since JSF 2.3 the javax.faces.bean.* annotations such as @ManagedBean are deprecated, and several implicit EL objects are produced via CDI producers, and <f:websocket> manages the WS sessions and events via CDI.

Installation

Depending on the server used, JSF may already be built-in (full fledged Java EE containers such as WildFly, JBoss EAP, TomEE, Payara, GlassFish, Liberty, etc.), or not (barebones JSP/Servlet containers such as Tomcat, Jetty, etc.). If the server doesn't ship with JSF built-in, then you need to manually install JSF 2.3 along with CDI 1.2+, JSONP 1.1+ and JSTL 1.2+ as those servlet containers usually also don't even ship with those JSF 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>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>8.0</version>
        <scope>provided</scope>
    </dependency>

    In case you're targeting a Java EE 7.0 runtime, then you should manually upgrade any runtime-provided JSF 2.2 library to JSF 2.3 depending on the server used. In case of WildFly/JBoss EAP, you need to manually package jsf-api.jar and jsf-impl.jar based on javax.faces.jar first. In case of TomEE, just swap the myfaces*.jar files with javax.faces.jar in server's /lib folder. In case of Payara/GlassFish, just swap the javax.faces.jar file in server's /glassfish/modules folder.

  • Servletcontainers (Tomcat, Jetty, etc)

    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version><!-- Use latest 2.3.x version. --></version>
    </dependency>
    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet-shaded</artifactId>
        <version>3.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency> <!-- Optional, only when <f:websocket> is used. -->
        <groupId>org.glassfish</groupId>
        <artifactId>javax.json</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency> <!-- Optional, only when <f:validateBean> or <f:validateWholeBean> is used. -->
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.1.Final</version>
    </dependency>

    You can check org.glassfish:javax.faces repository to find current latest Mojarra 2.3.x version.

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 1.2+ 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 3.0+ compatible deployment descriptor file /WEB-INF/web.xml as below:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    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"
    version="3.1"
>
    <servlet>
        <servlet-name>facesServlet</servlet-name>
        <servlet-class>javax.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 JSF 2.2+ is already "implicitly" registered and mapped on *.jsf, *.faces and /faces/* when running on a Servlet 3.0+ container. This will be overridden altogether when explicitly registering as above. The *.xhtml URL pattern is preferred over above for security and clarity reasons. JSF 2.3+ adds *.xhtml to set of default patterns, hence the FacesServlet registration being optional. But when you don't explicitly map it on *.xhtml, then people can still access JSF pages using *.jsf, *.faces or /faces/* URL patterns. This is not nice for SEO as JSF by design doesn't 301-redirect them to a single mapping.

The JSF deployment descriptor file /WEB-INF/faces-config.xml is fully optional, but if any it must be JSF 2.3 compatible, otherwise JSF 2.3 will run in a fallback modus matching the exact version as declared in <faces-config> root element.

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    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_3.xsd"
    version="2.3"
>
    <!-- Put any faces config here. -->
</faces-config>

Model

Then create a backing bean class as below:

package com.example;

import javax.enterprise.context.RequestScoped;
import javax.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 Java EE application the above "model" is further breakdown into a JPA entity, an EJB service and a smaller backing bean. The JPA entity and EJB 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 JSF MVC framework? and JSF Controller, Service and DAO.

View

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

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/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 JSF 2.3

By default, JSF 2.3 will run in JSF 2.2 modus as to CDI support. Even when you use a JSF 2.3 compatible faces-config.xml. In other words, the new JSF 2.3 feature of injection and EL resolving of JSF artifacts (spec issue 1316) won't work until you explicitly activate this. In other words, @Inject FacesContext doesn't work by default. This is necessary in order for JSF 2.3 to be fully backwards compatible.

There is currently only one way to activate CDI in JSF 2.3 and herewith make JSF 2.3 to run in full JSF 2.3 modus. Put the @FacesConfig annotation on an arbitrary CDI managed bean. For example, a general startup/configuration bean.

@FacesConfig
@ApplicationScoped
public class YourApplicationConfig {
    // ...
}

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:

JSF 2.4 (JSF.next)

  1. Make sure that you have JDK 1.8, 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/javax.faces-2.4.x-SNAPSHOT.jar.

JSF 2.3

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

  2. Checkout branch MOJARRA_2_3X_ROLLING.

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

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

JSF 2.2

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

  2. Checkout branch MOJARRA_2_2X_ROLLING.

  3. Edit build.properties according to your environment. If build.properties does not exist, then create a copy of build.properties.glassfish, build.properties.tomcat or build.properties.weblogic, depending on your target server. Below example assumes GlassFish or Payara:

    cp build.properties.glassfish build.properties

    Only the jsf.build.home property is mandated to be edited in your build.properties. It must represent the absolute path to the root directory of the project.

  4. Run the following command from the root directory of the project:

    # under the root dir of project
    ant main clean main
  5. The binary is now available as jsf-ri/build/mvn/target/javax.faces-2.2.x-SNAPSHOT.jar.

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

JSF 2.4 (JSF.next)

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

JSF 2.3

  1. Checkout branch master using File -> import -> Git
  2. Switch to 2.3 rolling branch using Team -> Switch to -> Other -> Remote Tracking -> origin/MOJARRA_2_3X_ROLLING -> New Branch
  3. Go to the commandline and cd into the directory where Mojarra was checked-out.
  4. Follow the instructions for build JSF 2.2 from the build instructions above from step 3 (copy/edit properties, run ant)
  5. Go back to Eclipse and refresh the Eclipse project

Pull Requests

Pull requests are accepted on following branches:

Note that it's okay to send a PR to the master branch, but these are for JSF.next and not the current 2.3.x version!

Resources

More Repositories

1

jersey

This is no longer the active Jersey repository. Please see the README.md
Java
2,863
star
2

glassfish

The Open Source Java EE Reference Implementation
Java
763
star
3

javamail

JavaMail API Reference Implementation
Java
577
star
4

javaee-spec

Java EE Platform Specification
HTML
389
star
5

tutorial-examples

Java
313
star
6

servlet-spec

The API and Issue Tracker for the JCP Standard Java Servlet Specification
Java
253
star
7

cargotracker

Applied domain-driven design blueprints for Java EE
Java
247
star
8

grizzly

Writing scalable server applications in the Java™ programming language has always been difficult. Before the advent of the Java New I/O API (NIO), thread management issues made it impossible for a server to scale to thousands of users. The Grizzly NIO framework has been designed to help developers to take advantage of the Java™ NIO API.
Java
222
star
9

tutorial

The Java EE Tutorial
CSS
220
star
10

jaxb-v2

Java
210
star
11

javaee.github.io

Java Enterprise Edition Development
SCSS
207
star
12

jax-rs-api

JAX-RS API Source Code
Java
192
star
13

tyrus

Tyrus - Reference implementation of Java API for WebSocket - JSR 356
Java
172
star
14

metro-jax-ws

Java
132
star
15

security-soteria

Java EE Security (JSR-375) Reference Implementation
Java
117
star
16

hk2

A light-weight and dynamic dependency injection framework
Java
112
star
17

jpa-spec

Java
90
star
18

glassfish-samples

GlassFish samples has been migrated to Eclipse Foundation https://github.com/eclipse-ee4j/glassfish-samples
Java
89
star
19

jsonp

Java API for JSON Processing (JSON-P)
Java
83
star
20

jax-rs-spec

JAX-RS Specification Sources
TeX
75
star
21

firstcup-examples

Java
56
star
22

jsonb-spec

Java API for JSON Binding (JSON-B)
Java
55
star
23

jstl-api

Java
46
star
24

javaserverfaces-spec

JavaServer(TM) Faces Specification web site
SCSS
43
star
25

javax.annotation

Repository for javax.annotation api
Java
42
star
26

jaxb-codemodel

CodeModel is a Java library for code generators. This content is migrated into JAXB RI. This is for legacy viewing only
Java
40
star
27

websocket-spec

Java API for WebSocket (JSR-356) defines a standard API for creating web socket applications.
TeX
38
star
28

javaee7-samples

javaee7-samples
Java
37
star
29

firstcup

First Cup of Java EE Tutorial
CSS
35
star
30

security-spec

Java EE Security (JSR-375) Specification
31
star
31

grizzly-ahc

The Grizzly Async Http Client (GAHC) library purpose is to allow Java applications to easily execute HTTP requests and asynchronously process the HTTP responses
Java
30
star
32

openmq

Java
29
star
33

security-examples

Examples demonstrating deficiencies in the current EE Security API, or demonstrating proposed EE Security API improvements.
Java
29
star
34

jersey-1.x

Jersey 1.x repository migrated to Git (synchronized with the Jersey 1.x Git repository on java.net).
Java
27
star
35

wadl

Web Application Description Language (WADL) project. This legacy project is available for review only
Java
26
star
36

batchlab

Batch API (JSR 352) Hands-on Lab
HTML
26
star
37

security-api

Java EE Security (JSR-375) API
Java
25
star
38

j1-hol

Java EE 8 Hands On Lab
Java
24
star
39

javaee-jsp-api

javaee-jsp-api
Java
22
star
40

jms-spec

Repository for the JMS specification, the JMS API source and the JMS specification website
Java
21
star
41

jersey-hol-sse-websocket

Hands-on-lab on using server-sent events and web socket with Jersey and Tyrus.
Java
21
star
42

security-proposals

Legacy scratch workspace for Java EE Security. Please check out Jakarta EE Security at the link below
Java
20
star
43

el-spec

Expression Language 3.0 specification, JSR341
Java
20
star
44

activation

Java
19
star
45

jaxb2-commons

JAXB Implementation project has been contributed to Eclipse Foundation. This repository is for legacy review only. Please refer to the Eclipse EE4J Metro project for the very latest
Java
17
star
46

javax.ejb

Repository for javax.ejb api. Issues at https://github.com/javaee/ejb-spec/issues
Java
15
star
47

jsr311

Legacy JAX-RS (JSR-311) spec. development. Please use the link below for the latest project details
Java
15
star
48

javahelp

javahelp
HTML
14
star
49

uel-ri

Legacy archive for Expression Language (JSR 341) Reference Implementation. Please browse to https://github.com/eclipse-ee4j/el-ri for current activity
Java
14
star
50

jax-rpc-ri

jax-rpc-ri
Java
11
star
51

jersey-old

Obsolete unmaintained mirror of Jersey 1.x SVN repository on jersey.java.net
Java
11
star
52

javax.transaction

Repository for javax.transaction api (JSR 907).
Java
11
star
53

jta-spec

Preliminary and non-final documentation for JTA Specification (JSR 907)
11
star
54

metro-jaxws-commons

Metro has been contributed to Eclipse Foundation. This repository is for legacy review only. Please refer to the Eclipse EE4J Metro project for the very latest
Java
10
star
55

metro

Metro has been contributed to Eclipse Foundation. Please use the link below to find the latest project
SCSS
10
star
56

javax.jms

Repository for javax.jms api, repackaged from jms-spec
Java
9
star
57

glassfish-corba

Formerly the home of GlassFish CORBA ORB. Please follow the link below for the current project page
Java
9
star
58

jaxb-spec

Formerly jsr222.java.net
Java
9
star
59

metro-wsit

Java
9
star
60

jersey-1.x-old

Read-only mirror of Jersey 1.x svn repository from jersey.java.net
Java
9
star
61

json-processing-spec

Legacy JSON Processing spec. Please use the link below to find the current JSON P project
HTML
8
star
62

jax-ws-spec

Java
8
star
63

javax.xml.soap

Repository for javax.xml.soap api
Java
8
star
64

grizzly-thrift

grizzly-thrift
Java
8
star
65

javadb

Java
7
star
66

jax-rs.github.io

legacy jax-rs website. Please use the link below for the latest
HTML
7
star
67

javax.jws

Repository for javax.jws api
Java
6
star
68

website-template

Common site template for Java EE related projects.
6
star
69

javax.interceptor

Repository for javax.interceptor api
Java
6
star
70

ejb-spec

See javax.ejb project for API. Contains legacy issues only.
6
star
71

jaxb-dtd-parser

Library for parsing XML DTDs
Java
6
star
72

interceptors-spec

interceptors-spec~interceptors-spec-repository
6
star
73

mvc-spec

This is a Read-Only mirror repository for JSR 371. For ongoing work, issue tracker and latest versions, go to https://github.com/jakartaee/mvc
Java
6
star
74

metro-policy

metro-policy
Java
5
star
75

grizzly-memcached

grizzly~memcached
Java
5
star
76

metro-saaj

Java
5
star
77

modularity-tools

modularity-tools
Java
5
star
78

jsf-extensions

JSF has been contributed to Eclipse Foundation and this repository is now called mojarra-jsf-extensions. Please follow the link below for the current repository
Java
5
star
79

schemas

The JCP-defined XML schemas for many Java EE specs.
JavaScript
5
star
80

shoal

Shoal Framework - For scalable dynamic clustering infrastructure to build fault tolerance, reliability and availability.
Java
5
star
81

logging-annotation-processor

A Java annotation processor that handles logging-related annotations.
Java
5
star
82

woodstock

Java
4
star
83

javax.resource

Repository for javax.resource api
Java
4
star
84

concurrency-ee-spec

concurrency-ee-spec~source-code-repository
Java
4
star
85

javax.xml.rpc

Repository for javax.xml.rpc api
Java
4
star
86

findbugs-tools

The common FindBugs exclude list used by GlassFish projects, as well as related tools used in scripts in Hudson jobs.
Shell
4
star
87

copyright-maven-plugin

The maven plugin that checks for the correct copyright/license notice in files related to the GlassFish project.
Java
4
star
88

connector-spec

4
star
89

metro-fi

Fast Infoset Project, an Open Source implementation of the Fast Infoset Standard for Binary XML.
Java
4
star
90

javaserverfaces

PLEASE NOTE: This project has moved to Eclipse Foundation and will be archived under the JavaEE GitHub Organization. After Feb. 1, 2021, the new location will be github.com/javaee/javaserverfaces-web
HTML
4
star
91

grizzly-npn

grizzly-npn
Java
3
star
92

fighterfish

Modules supporting use of OSGi by Java EE applications.
Java
3
star
93

jaxb-istack-commons

jaxb-istack-commons
Java
3
star
94

glassfish-license-tool

glassfish-license-tool
Java
3
star
95

gmbal-pfl

Primitive Function Library
Java
3
star
96

javax.xml.registry

Repository for javax.xml.registry api
Java
3
star
97

glassfish-docs

Documentation resources (online help, etc.) for the GlassFish project.
HTML
3
star
98

metro-maven-jaxb2-plugin

Metro has been contributed to Eclipse Foundation. This repository is for legacy review only. Please refer to the Eclipse EE4J Metro project for the very latest
Java
3
star
99

repackaged

Copies of third party open source projects that are used in the build of GlassFish, along with tools to build those projects. GlassFish depends on the versions of these projects that we build, not directly on binaries produced by the originating project.
Shell
3
star
100

metro-package-rename-task

metro-package-rename-task
Java
2
star