How to dynamically add JSF components

Use an iterating component like <h:dataTable> or <ui:repeat> to display a dynamically sized List of entities. Make the bean @ViewScoped to ensure that the list is remembered across postbacks on the same view instead of recreated over and over. Kickoff example with <h:dataTable> (when using <ui:repeat> simply replace <h:dataTable> by <ui:repeat>, and <h:column> by e.g. … Read more

What is the function of @this exactly?

The PrimeFaces process and standard JSF execute attributes should point to spaceseparated component identifiers of components which JSF should process during the entire JSF lifecycle upon an ajax request (get request parameters, validate them, update model, execute action). The process defaults to @form, the current form, and the execute defaults to @this, the current component. … Read more

Upgrade JSF / Mojarra in JBoss AS / EAP / WildFly

The below procedure applies to JBoss AS 7.2+, JBoss EAP 6.1+, and JBoss WildFly 8+ and assumes that you’ve full control over the server installation and configuration. This upgrades the server-wide default JSF version: Download the individual Mojarra API and impl files (and thus not the single javax.faces.jar file). Current latest 2.1.x version is 2.1.29 … Read more

How to find indication of a Validation error (required=”true”) while doing ajax command

Not specifically for required=”true”, but you can check by #{facesContext.validationFailed} if validation has failed in general. If you combine this with checking if the button in question is pressed by #{not empty param[buttonClientId]}, then you can put it together in the rendered attribute of the <h:outputScript> as follows: <h:commandButton id=”add_something_id” binding=”#{add}” value=”Add” action=”#{myBean.addSomething(false)}”> <f:ajax execute=”@form” … Read more

How to inject in @FacesValidator with @EJB, @PersistenceContext, @Inject, @Autowired

JSF 2.3+ If you’re already on JSF 2.3 or newer, and want to inject CDI-supported artifacts via e.g. @EJB, @PersistenceContext or @Inject, then simply add managed=true to the @FacesValidator annotation to make it CDI-managed. @FacesValidator(value=”emailExistValidator”, managed=true) JSF 2.2- If you’re not on JSF 2.3 or newer yet, then you basically need to make it a … Read more

Email validation using regular expression in JSF 2 / PrimeFaces

All regular expression attempts to validate the email format based on Latin characters are broken. They do not support internationalized domain names which were available since May 2010. Yes, you read it right, non-Latin characters are since then allowed in domain names and thus also email addresses. That are thus extremely a lot of possible … Read more

What is the difference between redirect and navigation/forward and when to use what?

First of all, the term “redirect” is in web development world the action of sending the client an empty HTTP response with just a Location header with therein the new URL on which the client has to send a brand new GET request. So basically: Client sends a HTTP request to somepage.xhtml. Server sends a … Read more

JSF 2.0 File upload

First of all, this (old) question and answer assumes JSF 2.0/2.1. Since JSF 2.2 there’s a native <h:inputFile> component without the need for 3rd party component libraries. See also How to upload file using JSF 2.2 <h:inputFile>? Where is the saved File? The easiest way would be using Tomahawk for JSF 2.0. It offers a … Read more

How to conditionally render plain HTML elements like s?

The right JSF component to represent a HTML <div> element is the <h:panelGroup> with the layout attribute set to block. So, this should do: <h:panelGroup layout=”block” … rendered=”#{someCondition}”> … </h:panelGroup> Alternatively, wrap it in an <ui:fragment>: <ui:fragment rendered=”#{someCondition}”> <div> … </div> </ui:fragment> Or when you’re already on JSF 2.2+, make it a passthrough element: <div … Read more

tech