Using a “Please select” f:selectItem with null/empty value inside a p:selectOneMenu

When the select item value is null, then JSF won’t render <option value>, but only <option>. As consequence, browsers will submit the option’s label instead. This is clearly specified in HTML specification (emphasis mine): value = cdata [CS] This attribute specifies the initial value of the control. If this attribute is not set, the initial … Read more

Getting ViewExpiredException in clustered environment while state saving method is set to client and user session is valid

This will happen if the client side state is encrypted by one server and decrypted by other server and the servers don’t use the same AES key for this. Normally, you should also have seen below warning in server log: ERROR: MAC did not verify You need to ensure that you have set jsf/ClientSideSecretKey in … Read more

@ViewScoped bean recreated on every postback request when using JSF 2.2

This, import javax.faces.view.ViewScoped; is the JSF 2.2-introduced CDI-specific annotation, intented to be used in combination with CDI-specific bean management annotation @Named. However, you’re using the JSF-specific bean management annotation @ManagedBean. import javax.faces.bean.ManagedBean; You should then be using any of the scopes provided by the very same javax.faces.bean package instead. The right @ViewScoped is over there: … Read more

File upload doesn’t work with AJAX in PrimeFaces 4.0/JSF 2.2.x – javax.servlet.ServletException: The request content-type is not a multipart/form-data

As Kai rightfully pointed out in his answer on the current question, the problem is caused by the NativeFileUploadDecoder as used by FileUploadRenderer not checking whether the request is a multipart/form-data request or not. This will cause trouble when the component is present in a form on which a “regular” ajax request is being submitted. … Read more

How to upload file using JSF 2.2 ? Where is the saved File?

JSF won’t save the file in any predefined location. It will basically just offer you the uploaded file in flavor of a javax.servlet.http.Part instance which is behind the scenes temporarily stored in server’s memory and/or temporary disk storage location which you shouldn’t worry about. Important is that you need to read the Part as soon … Read more

Pass an object between @ViewScoped beans without using GET params

Depends on whether you’re sending a redirect or merely navigating. If you’re sending a redirect, then put it in the flash scope: Faces.setFlashAttribute(“car”, car); This is available in the @PostConstruct of the next bean as: Car car = Faces.getFlashAttribute(“car”); Or, if you’re merely navigating, then put it in the request scope: Faces.setRequestAttribute(“car”, car); This is … Read more