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
106
votes
6 answers

Get JSF managed bean by name in any Servlet related class

I'm trying to write a custom servlet (for AJAX/JSON) in which I would like to reference my @ManagedBeans by name. I'm hoping to map: http://host/app/myBean/myProperty to: @ManagedBean(name="myBean") public class MyBean { public String…
Konrad Garus
  • 53,145
  • 43
  • 157
  • 230
104
votes
4 answers

How can I pass selected row to commandLink inside dataTable or ui:repeat?

I'm using Primefaces in a JSF 2 application. I have a , and instead of selecting rows, I want the user to be able to directly execute various actions on individual rows. For that, I have several s in the last column. My…
Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
101
votes
2 answers

When to use f:viewAction / preRenderView versus PostConstruct?

When should one use the f:viewAction or preRenderView event to initialize data for a page versus using the @PostConstruct annotation? Is the rationale to use one or the other based on the type of scope of the backing bean e.g. If the backing bean is…
BestPractices
  • 12,738
  • 29
  • 96
  • 140
101
votes
4 answers

What components are MVC in JSF MVC framework?

In JSF MVC framework who is Model, View, and Controller?
yegor256
  • 102,010
  • 123
  • 446
  • 597
101
votes
2 answers

ViewParam vs @ManagedProperty(value = "#{param.id}")

What is the difference between defining View Params like this: And defining the property in the ManagedBean like this: @Inject @ManagedProperty(value =…
ehsun7b
  • 4,796
  • 14
  • 59
  • 98
100
votes
5 answers

Error Parsing /page.xhtml: Error Traced[line: 42] The entity "nbsp" was referenced, but not declared

I'd like to use non breaking spaces in my JSF page. I know, in plain HTML I could use   for this and this works fine. However, when I put those   in a Facelets page, then it errors as follows: Error Parsing /page.xhtml: Error Traced[line:…
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
95
votes
5 answers

How to provide a file download from a JSF backing bean?

Is there any way of providing a file download from a JSF backing bean action method? I have tried a lot of things. Main problem is that I cannot figure how to get the OutputStream of the response in order to write the file content to. I know how to…
zmeda
  • 2,909
  • 9
  • 36
  • 56
93
votes
2 answers

How does EL empty operator work in JSF?

In JSF an component can be rendered or not using the EL empty operator rendered="#{not empty myBean.myList}" As I've understood the operator works both as null-check, but also check checks if the list is empty. I want to do empty checks on some…
Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
91
votes
1 answer

What is the use of faces-config.xml in JSF 2?

After the JSF 2 big support for annotations, I'm wondering what I would use the faces-config.xml for. What is its importance now? In other words, what are the configurations that can only be done through faces-config.xml and not via…
Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
91
votes
16 answers

Java EE 6 vs. Spring 3 stack

I'm starting a new project now. I have to choose technologies. I need something light, so no EJB or Seam. On the other hand I need JPA (Hibernate or alternative) and JSF with IceFaces. Do you think that such a stack on Spring 3 deployed on Tomcat is…
Piotr Gwiazda
  • 12,080
  • 13
  • 60
  • 91
91
votes
10 answers

How do I insert non breaking space character   in a JSF page?

How do I insert a non breaking space character in JSF page like I can in HTML using  ? Is there such a tag in JSF?
Suresh
  • 38,717
  • 16
  • 62
  • 66
91
votes
2 answers

When to use valueChangeListener or f:ajax listener?

What's the difference between the following two pieces of code - with regards to listener placement? and
Danijel
  • 8,198
  • 18
  • 69
  • 133
89
votes
2 answers

How to use && in EL boolean expressions in Facelets?

I am having a little trouble figuring out how to do and's on EL expressions in Facelets. So basically I have: But I keep…
Landister
  • 2,194
  • 7
  • 38
  • 56
89
votes
1 answer

Internationalization in JSF, when to use message-bundle and resource-bundle?

When and how should I use and tags for localization in faces-config.xml? The differences between those two are not very clear to me.
jsfQ
  • 925
  • 1
  • 8
  • 8
85
votes
3 answers

Validation Error: Value is not valid

I have a problem with a p:selectOneMenu, no matter what I do I cannot get JSF to call the setter on the JPA entity. JSF validation fails with this message: form:location: Validation Error: Value is not valid I have this working on several other…
klonq
  • 3,535
  • 4
  • 36
  • 58