Questions tagged [jsf]

JSF, Jakarta Server Faces (formerly known as JavaServer Faces) is a model-view-presenter framework typically used to create HTML form based web applications. Using the standard components and render kit, stateful HTML views can be defined using Facelets or JSP tags and wired to model data and application logic via backing beans.

Information to provide when asking JSF questions

If you want good answers to your JSF questions, you will get it more quickly if you immediately include the following information in the question.

  • Which JSF implementation and version are you using?

    Mojarra or MyFaces? 1.0.x, 1.1.x, 1.2.x, 2.0.x, 2.1.x, 2.2.x, 2.3.x, 3.0.x or 4.0.x? You can usually find the exact implementation name and version in webapp's startup log or at least in JAR's filename, and/or MANIFEST.MF file. Also mention the exact version of any JSF component/utility library involved in the problem. If you don't mention anything, we will assume the latest version available to date.

    The difference between JSF 1.x and JSF 2.x/3.x/4.x is too big to be able to give a reliable answer which can cover both versions. Also, each of the JSF implementations/libraries may have its own set of version-specific bugs/quirks so that the answerer can, if necessary, take this into account. In case there is a newer version available, you should try upgrading and then re-test the problem.

  • Any warnings/errors/exceptions in faces messages, or browser console, or server logs?

    If the application appears to be failing silently, make sure that you've added a <h:messages> tag to your JSF page to avoid that you miss any faces messages. Also, make sure that you've set javax.faces.PROJECT_STAGE to Development in web.xml to avoid that you miss any development warnings/hints. Also, make sure that you have read the browser console (press F12 in Chrome/Firefox23+/IE9+) and server logs from top to bottom. Investigate any line which represents a warning or error or looks otherwise abnormal.

    When you get an exception, then always include the bottommost root cause of the stack trace along with all "at" lines (all other causes there above are just consequences). Exceptions are generally excellent search keywords. You can just search on the exception type+message and optionally the 1st "at" line of the trace without the parentheses+linenumber to see if it isn't already asked and answered before. Example 1, example 2, example 3.

  • Provide a minimal reproducible example!

    Try to isolate the problem as much as possible into the smallest possible but complete copy'n'paste'n'runnable example. As to Java (backing bean) code, you do not need to include imports and getters/setters. You also do not need to include any fields and methods which do not contribute to the actual problem. As to XHTML (view) code, you do not need to include any tags and attributes which do not contribute to the actual problem. You also do not need to include the whole business service layer (EJB/JPA/Spring/DAO/JDBC/etc), just a hardcoded model is sufficient (otherwise it's not necessarily a JSF related problem).

    You should assume that the potential answerer will copypaste the provided Java code into an empty test class and auto-organize imports and autogenerate getters/setters if necessary, and copypaste the provided XHTML code into a <h:body> of a templateless(!) test file in a blank project with everything set to default (i.e. no or empty XML configuration files!) and using currently latest versions of libraries/server, unless explicitly otherwise mentioned in the question itself (and you should also test it yourself this way beforehand!).

Without the above information and/or a proper MCVE, getting answers will depend more on luck (there's no ambiguity nor noise in the question as to possible causes) and educated guesses of the potential answerers (knowing the most common starter's mistakes). You may otherwise risk the question being closed as "Off-Topic, because there's no MCVE or there's only a full code dump", or "Too Broad, because it basically asks us to write code instead of to explain and solve a problem".


Minimum requirements

  • Faces 4.0 requires a minimum of Java 11, Servlet 6.0, EL 5.0 and CDI 4.0. Faces 4.0 is part of Jakarta EE 10.
  • JSF 3.0 requires a minimum of Java 1.8, Servlet 5.0, EL 4.0 and CDI 3.0. JSF 3.0 is part of Jakarta EE 9.
  • JSF 2.4 does actually not really exist even though this is accidentally present in Maven! See also Upgrading to JSF 2.4 and Do not use org.glassfish Mojarra 2.4.0! You need to pick the currently latest 2.3.x, or JSF 3.x or newer.
  • JSF 2.3 requires a minimum of Java 1.8, Servlet 3.0, EL 3.0 and CDI 1.2. Servlet 4.0 is optional and will enable JSF 2.3 to serve resources via HTTP/2 push. When <f:websocket> is used, JSONP 1.1 is required as well. CDI 1.2 is explicitly required because of the @ManagedBean being deprecated. JSF 2.3 is part of Java EE 8 / Jakarta EE 8.
  • JSF 2.2 requires a minimum of Java 1.6, Servlet 3.0 and EL 2.2. Servlet 3.0 is explicitly required because of the new file upload component which is internally using the standard Servlet 3.0 API without the need for 3rd party libraries. JSF 2.2 is part of Java EE 7.
  • JSF 2.1 requires a minimum of Java 1.5, Servlet 2.5 and EL 2.1. Servlet 3.0 is optional and will enable JSF 2.1 to automatically run on *.jsf without any necessary web.xml configuration as long as there's a faces-config.xml.
  • JSF 2.0 requires a minimum of Java 1.5, Servlet 2.5 and EL 2.1. You can use Servlet 2.4 if you supply your own EL 2.1 API/impl. JSF 2.0 is part of Java EE 6.
  • JSF 1.2 requires a minimum of Java 1.5, Servlet 2.5, JSP 2.1 and EL 2.1. If you replace JSP 2.1 by Facelets 1.x as default view technology, then you can use JSF 1.2 on Servlet 2.4. JSF 1.2 is part of Java EE 5.
  • JSF 1.0 and 1.1 requires a minimum of Java 1.4, Servlet 2.4 and JSP 2.0. JSF 1.0 is part of J2EE 1.4.

Examples of Java EE and Servlet containers

  • Servlet 6.0: Tomcat 10.1.x, GlassFish 7.x, WildFly 27.x.x
  • Servlet 5.0: Tomcat 10.0.x, GlassFish 6.x, Open Liberty 21.x.x.x, WildFly 23.x.x
  • Servlet 4.0: Tomcat 9.x, GlassFish/Payara 5.x
  • Servlet 3.1: Tomcat 8.x, WildFly 8/9/10/11.x, GlassFish/Payara 4.x, TomEE 7.x, WebSphere 9.x
  • Servlet 3.0: Tomcat 7.x, JBoss AS 6/7.x, GlassFish 3.x, TomEE 1.x, WebSphere 8.x
  • Servlet 2.5: Tomcat 6.x, JBoss AS 5.x, GlassFish 2.x, WebSphere 7.x
  • Servlet 2.4: Tomcat 5.5.x, JBoss AS 4.x, Sun Java Application Server, WebSphere 5/6.x

Installing JSF

Depending on the server used, JSF may already be built-in (full fledged Java EE containers such as WildFly, JBoss EAP, TomEE, Payara, GlassFish, WebSphere, 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 a JSF implementation to your choice (Mojarra or MyFaces). Don't forget JSTL, those barebones JSP/Servlet containers usually also don't even ship with JSTL.


Resources

Online tutorials

Offline tutorials ("books")

JSF implementations

  • Mojarra - Oracle's reference implementation (RI), standard part of e.g. WildFly
  • MyFaces - Apache's alternative, standard part of e.g. TomEE

JSF component/utility libraries

Frequently asked questions

More links:

Related tags

35737 questions
7
votes
2 answers

Injecting one view scoped bean in another view scoped bean causes it to be recreated

I need to use some data saved in a view scoped bean in an other view scoped bean. @ManagedBean @ViewScoped public class Attivita implements Serializable { // } and @ManagedBean @ViewScoped public class Nota implements Serializable { …
supertarmax
  • 111
  • 1
  • 4
  • 10
7
votes
1 answer

ViewExpiredException after identity.logout(); in JBoss Seam

After my AuthenticationFilter redirect to login page, I would like to logout to user. That's why, I put identity.logout(); in my pre-render method checkPermission(...) of login.xhtml. But, I get the ViewExpiredException when the user login again. My…
Zaw Than oo
  • 9,651
  • 13
  • 83
  • 131
7
votes
3 answers

Conditional update in Primefaces/jsf

First of all, so that there are no misunderstandings, while this is the same question as PrimeFaces: conditional update on validation I am asking it again, because the answer to that question is not acceptable to me, because while it may have given…
Creature
  • 131
  • 1
  • 1
  • 6
7
votes
2 answers

How to get request parameters from view scoped JSF bean?

I have the view scoped bean which should access on init (@PostConstruct) the values from request URL and store them within its lifetime. I've learned, that in order to get the values from http request, I need the following…
Danubian Sailor
  • 1
  • 38
  • 145
  • 223
7
votes
2 answers

How do I access the current TreeNode in primefaces tree (in mark-up or programmatically) without binding to UI component in managed bean?

I am using Primefaces 3.4.1 with the 2.2.0-m05 milestone build of Oracle's JSF 2.2 implementation. I am also using Spring 3.1 for dependency injection and some AOP. I am trying to use the Primefaces tree component to display a composite of logical…
user1838501
  • 71
  • 1
  • 3
7
votes
2 answers

Duplicate text in summary and detail

When the email address is invalid the message displayed is "Invalid email.Invalid email.". I know that the message has two parts: summary and a details. I need both of these, but I want to have different info in each. How can I change the message to…
Seitaridis
  • 4,459
  • 9
  • 53
  • 85
7
votes
1 answer

Obtaining Facelets templates/files from an external filesystem or database

I am able to successfully get this to work with the template in my app: I am also able to move template to /META-INF/templates/mytemplate.xhtml of a JAR and get this to work:
JeffJak
  • 2,008
  • 5
  • 28
  • 40
7
votes
2 answers

Using return/enter key to save edited cell in Primefaces 3.4 in-cell editable datatable

As the title says, instead of clicking on the "Save" button after switching to edit-mode, I would like to have the same functionality when pressing the enter/return-key. I attempted to do this with p:hotkey but apparently p:hotkey will not work…
javaMS
  • 401
  • 4
  • 9
  • 20
7
votes
1 answer

Timeout set in the web.xml is not working in java

I am trying to set my application timeout on Tomcat 7 app server.First I am testing with my timeout as one minute in web.xml as 1 and I am using HttpSessionListener…
SRy
  • 2,901
  • 8
  • 36
  • 57
7
votes
2 answers

JSF 2.0. Unable to get POST parameters and cookies in preRenderView event handler

I am trying to develop a service. The point is that my index.xhtml should get parameters (either POST and GET) and cookies from HTTP Request. I tried combination with and like this:
Jerome
  • 2,397
  • 2
  • 12
  • 8
7
votes
2 answers

How to update multiple components (selectOneMenu) with depending objects relations?

i have the following (self-explanatory) entity-relation: * Manufacturer * Car (Manufacturer.getCars()) * Tire (Car.getTires()) MyBean private List allManufacturers private Manufacturer selectedManufacturer private Car…
jimmybondy
  • 2,092
  • 3
  • 21
  • 33
7
votes
2 answers

Is Facelets page generated to Servlet as JSP generated to Servlet

As all JSPs are generated / translated to Servlets before their execution, is its true for Facelets too? I am working with JSF 2.0 and Facelets and wanted to see its generated Java Code which might be Servlet.
Faisal Basra
  • 1,624
  • 4
  • 25
  • 40
7
votes
3 answers

Convert string to lowercase for property binding within xhtml?

How could I always convert the property username to lower case? This does not work: as target gets "unreachable" by this. How could I else do this?
membersound
  • 81,582
  • 193
  • 585
  • 1,120
7
votes
3 answers

Dynamically change CSS style of cell in column

how to calculate cell values of B column and how to change their css style dynamically my java object : public class MyObject{ private Date date; private int A; private int C; //Getters & Setters } my managed bean : public class…
Karim Oukara
  • 2,638
  • 8
  • 38
  • 51
7
votes
1 answer

JSF 1.2 - iterate over a Map that contains Collections

Using JSF 1.2 and JSP.... Is it possible to iterate over a Map whose values contain Collections? I have a Map that looks like this: Map> myMap; I would like to iterate over myMap and draw a separate table for each key. Each table…
jahroy
  • 22,322
  • 9
  • 59
  • 108
1 2 3
99
100