Spring Boot JSF Integration

This is the way I have JSF working with Spring Boot (full sample project at Github, updated with JSF 2.3 and Spring Boot 2): 1. Dependencies In addition to the standard web starter dependency, you’ll need to include the tomcat embedded jasper marked as provided (thanks @Fencer for commenting in here). Otherwise you’ll get an … Read more

How can I get a message bundle string from inside a managed bean?

You can get the full qualified bundle name of <message-bundle> by Application#getMessageBundle(). You can get the current locale by UIViewRoot#getLocale(). You can get a ResourceBundle out of a full qualified bundle name and the locale by ResourceBundle#getBundle(). So, summarized: FacesContext facesContext = FacesContext.getCurrentInstance(); String messageBundleName = facesContext.getApplication().getMessageBundle(); Locale locale = facesContext.getViewRoot().getLocale(); ResourceBundle bundle = ResourceBundle.getBundle(messageBundleName, … Read more

Why Facelets is preferred over JSP as the view definition language from JSF 2.0 onwards?

True, JSP has some templating capabilities, but the biggest disadvantage of using JSP in JSF is that JSP writes to the response as soon as it encounters template text content, while JSF would like to do some pre/post processing with it. In JSF 1.0/1.1 the following JSF code <h:outputText value=”first”/> second <h:outputText value=”third”/> fourth would … Read more

Skip required validation and invoke the application

Just put that condition straight in the required attribute. <h:inputText … required=”#{someCondition}” /> It namely just accepts any EL expression like as many other attributes. Many starters think that you can only hardcode a “true” or “false” string in it. This is untrue. For example, when you want to let it evaluate true only when … Read more

f:viewParam doesn’t pass required parameter when new xmlns.jcp.org namespace is used

The way how the new xmlns.jcp.org XML namespaces are been handled is broken in the first Mojarra releases 2.2.0 and 2.2.1. It has been fixed in Mojarra 2.2.2 (note: ticket in the link describes different problem symptom, but under the covers, it’s essentially the same cause). It’s recommended to upgrade to Mojarra 2.2.2. GlassFish 4.0 … Read more

Prevent accessing restricted page without login in Jsf2

That depends on how you have programmed the login. You seem to be using homegrown authentication wherein you set the logged-in user as a property of a session scoped managed bean. Because with Java EE provided container managed login, preventing access to restricted pages is already taken into account. Assuming that you’ve all restricted pages … Read more

JSF resource versioning

If I do like this resources/js/1_0_0/mainscript.js It does not work. It says RESOURCE_NOT_FOUND This will work if you specify js as library name. <h:outputScript library=”js” name=”mainscript.js” /> However, this is not the proper usage of a resource library. Rather introduce one. resources/default/1_0_0/js/mainscript.js Then you can specify it as follows: <h:outputScript library=”default” name=”js/mainscript.js” /> They did … Read more

Ajax update and submission using h:commandButton

This is to be done by nesting a <f:ajax> in it. In effects, <p:commandButton … process=”@form” update=”:statusBlock” /> does exactly the same as <h:commandButton …> <f:ajax execute=”@form” render=”:statusBlock” /> </h:commandButton> Note that the subtle difference with the PrimeFaces equivalent is that PrimeFaces defaults to @form in the process/execute, while the <f:ajax> one defaults to @this, … Read more