p:fileUpload calls bean constructor for each file - ajax

I'm trying to use <p:fileUpload> to upload a file. Here's the view:
<h:form enctype="multipart/form-data">
<p:growl id="messages" showDetail="true" />
<p:fileUpload
fileUploadListener="#{viewscopedBean.handleFileUpload}"
mode="advanced" dragDropSupport="true" multiple="true"
update="messages" />
</h:form>
Bean:
#ManagedBean
#ViewScoped
public class ViewscopedBean implements Serializable{
private List<UploadedFile> uploadedFiles; //to remember which files have been uploaded
public ViewscopedBean() {
super();
System.out.println("#constructor");
uploadedFiles = new ArrayList<UploadedFile>();
}
public void handleFileUpload(FileUploadEvent event) {
System.out.println("! HANDLE FILE UPLOAD !");
// do something
}
public List<UploadedFile> getUploadedFiles() {
return uploadedFiles;
}
public void setUploadedFiles(List<UploadedFile> uploadedFiles) {
this.uploadedFiles = uploadedFiles;
}
}
web.xml
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>512000</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
When I click on the upload button, the progressbar is filling up to 100% (like it does something), but then the page is reloaded (constructor is being called for every uploaded file) - the handleFileUpload method is never called.
There aren't any errors or warnings, it just doesn't do what it should. I have JSF 2.0 and use Primefaces 4, maybe there is a problem?
How is this caused and how can I solve it?

First things first, ensure that you have commons-fileupload and its compile-time dependency commons-io on your classpath. The handler not being called suggests that you have these dependencies missing.
Since 4.0, there is now an optional context-param which specifies the server-side engine for handling FileUpload uploads:
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto|native|commons</param-value>
</context-param>
In the absence of the context-param, PrimeFaces otherwise selects the most appropriate uploader engine by detection.
Given that you are not using JSF 2.2, this means that it will first select auto, and therefore will redirect to use commons.
So you can see how important it is that you have commons-fileupload and commons-io in your project.
When I copied and pasted your code into a Primefaces 3.5 project containing these dependencies, your code worked for me. The constructor was called once and only once, and the handle method was called each time I uploaded a file.
I repeated the test using 4.0 and again, the constructor was called once and only once.
Here's the configuration that I used in web.xml (needed by commons-fileupload):
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
Here's the backing bean:
package uk;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;
#ManagedBean(name = "tempBean")
#ViewScoped
public class TempBean {
private List<UploadedFile> uploadedFiles; //to remember which files have been uploaded
public TempBean() {
super();
System.out.println("#constructor");
uploadedFiles = new ArrayList<UploadedFile>();
}
public void handleFileUpload(FileUploadEvent event) {
System.out.println("! HANDLE FILE UPLOAD !");
// do something
}
public List<UploadedFile> getUploadedFiles() {
return uploadedFiles;
}
public void setUploadedFiles(List<UploadedFile> uploadedFiles) {
this.uploadedFiles = uploadedFiles;
}
}
Here's the page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:body>
<h:form enctype="multipart/form-data">
<p:growl id="messages" showDetail="true" />
<p:fileUpload
fileUploadListener="#{tempBean.handleFileUpload}"
mode="advanced" dragDropSupport="true" multiple="true"
update="messages" />
</h:form>
</h:body>
</html>
And finally here is the snippet of my POM that contains the dependencies and versions for Apache Commons:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>

Related

http status 500-Error instantiating servlet class org.springframework.web.servlet.DispatcherServlet

Above is the directory hierarchy of my program
I am new to spring and learning MVC concepts I have written a program which takes input(Name) into a text box and prints Hello...'name'. Tha following is my directory structure and the various files I have created.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>MVC_HelloWorld</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- default configuration -->
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>*.ap</url-pattern> <!-- this same extension should bbe used in form action -->
</servlet-mapping>
</web-app>
HelloWorld-servlet.xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!-- default handler mapping -->
<!-- file should be created under web inf annd it's view resolver file -->
<!-- handler(Not rqd in case of default handler) -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<!-- controller configuration -->
<bean name="/HelloWorld.ap" class="controller.HelloController"> <!-- mapping url pattern to controller class using 'name' -->
<!-- view resolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" vlaue="/"/> <!-- default location (prefix used foor rqd page locations) -->
|<property name="sufix" value=".jsp"/> <!-- sufix used forr rqd page extensions -->
</bean>
</bean>
</beans>
HelloController.java
package controller;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.sun.javafx.collections.MappingChange.Map;
public class HelloController implements Controller {
#Override
public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse res) throws Exception {
String name=req.getParameter("name");
Map m= new HashMap(); // creating output object
m.put("msg","Hello..."+name);
ModelAndView mav=new ModelAndView("success"+m);
return mav;
}
}
index.jsp
<h1> Hello World</h1>
<form action="./hello.ap">
NAME: <input type="text" name="name">
<input type="Submit" value="Say Hello">
</form>
success.jsp
${msg}
when I am running this code the index.jsp page is running properly bur upon further execution It shows Error 500. what's wrong with the code..?? I am using Eclipse oxygen in that apache 8.5
You configuration in web.xml are wrong.
You are trying to map the dispatch servlet as the controller.
In spring mvc like in other mvc frameworks (struts etc.) there is one major servlet that use to dispatch all requests.
org.springframework.web.servlet.DispatcherServlet is usually named “dispatcher” and should be mapped to a top level url usually “\”
e.g.
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
And the controller is mapped under this url e.g. HelloWorld
#Controller
#RequestMapping("/HelloWorld");"
public class HelloController implements Controller {}
As your initial project is far from the classic vanilla starter Spring MVC project and it looks like you are using a very old Spring version (or spring tutorial). I suggest to start fresh from some online tutorial.
E.g.
http://www.journaldev.com/2433/spring-mvc-tutorial
http://www.mkyong.com/spring-mvc/gradle-spring-mvc-web-project-example/
Try below edit to web.xml.
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>*.ap</url-pattern> <!-- this same extension should bbe used in form action -->
</servlet-mapping>

Spring MVC http 500 error apache

Above is the directory hierarchy of my program
I am new to spring and learning MVC concepts I have written a program which takes input(Name) into a text box and prints Hello...'name'. Tha following is my directory structure and the various files I have created.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>MVC_HelloWorld</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- default configuration -->
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>*.ap</url-pattern> <!-- this same extension should bbe used in form action -->
</servlet-mapping>
</web-app>
HelloWorld-servlet.xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!-- default handler mapping -->
<!-- file should be created under web inf annd it's view resolver file -->
<!-- handler(Not rqd in case of default handler) -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<!-- controller configuration -->
<bean name="/HelloWorld.ap" class="controller.HelloController"> <!-- mapping url pattern to controller class using 'name' -->
<!-- view resolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" vlaue="/"/> <!-- default location (prefix used foor rqd page locations) -->
|<property name="sufix" value=".jsp"/> <!-- sufix used forr rqd page extensions -->
</bean>
</bean>
</beans>
HelloController.java
package controller;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.sun.javafx.collections.MappingChange.Map;
public class HelloController implements Controller {
#Override
public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse res) throws Exception {
String name=req.getParameter("name");
Map m= new HashMap(); // creating output object
m.put("msg","Hello..."+name);
ModelAndView mav=new ModelAndView("success"+m);
return mav;
}
}
index.jsp
<h1> Hello World</h1>
<form action="./hello.ap">
NAME: <input type="text" name="name">
<input type="Submit" value="Say Hello">
</form>
success.jsp
${msg}
when I am running this code the index.jsp page is running properly bur upon further execution It shows Error 404.
what's wrong with the code..??
I am using Eclipse oxygen in that apache 8.5
Your servlet name in definition is HelloWorld
but in mapping servlet, is hello.
These names must be the same.
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>*.ap</url-pattern> <!-- this same extension should bbe used in form action -->
</servlet-mapping>
</web-app>
here you have used HelloWorld as the servlet name previously and you referring to that as hello later on which is not correct so please correct that just change the hello in servelt-mapping to HelloWorld and access the servlet as HelloWorld.ap it will work.

Ajax poll does not work in my project

First of all, I'm sorry for my bad English.
I´m new working with JSF, so I am sure that this is really stupid question but I couldn't find any post that help me. I´m using ajax poll in my project because I need refresh components in the page. I founded an example in the primefaces 5 showcase. In this example there is a counter that increments every 3 seconds. I used the code of the example in the exactly same way but the counter never increments. I think that this could be a bad configuration that I used in my project. Also, its showed the next message in the Eclipse console (I don´t know if this has something to do with my problem):
Información: No state saving method defined, assuming default server
state saving
Here is my sorce code:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"></meta>
<title>Insert title here</title>
</h:head>
<h:body>
<h:form>
<h:outputText id="txt_count" value="#{globalCounterView.count}"/>
<p:poll interval="3" listener="#{globalCounterView.increment}" update="txt_count"/>
</h:form>
</h:body>
</html>
In the bean:
import java.io.Serializable;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.event.ActionEvent;
#ManagedBean
#ApplicationScoped
public class GlobalCounterView implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private int count;
public int getCount() {
return count;
}
public void increment(ActionEvent actionEvent) {
count++;
}
public void setCount(int count) {
this.count = count;
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SAEGraph</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
In the end, the thing what I want to do is update a primeface component from backing bean periodically. Also, Can you tell me if exists any other way to do this not using poll ????
Thanks and sorry again for the bad english.
I'm using primefaces 5.0, Tomcat 7, Eclipse Version: 4, JDK 7
Just remove the argument in increment method.
public void increment(ActionEvent actionEvent) {
count++;
}
to:
public void increment() {
count++;
}

Managed bean not working after adding Spring configuration

I really do not know what's the cause of the problem. I created a website with hibenate and JSF and later decided to integrate Spring framework as well, but eventually faced a problem.
My managed bean "loginbean" was working perfectly. It also recognizes the method within a JSF page, but when I run the application I see an "error excusion" message.
My bean:
#ManagedBean(name="loginBean")
#SessionScoped
public class LoginBean {
private String username;
private String password;
private int activeindex;
public String Dirige(int a){
setActiveindex(a);
if (a == 0){
return "/Menu.jsf";
}else{
if (a == 1) {
return "/pagess/pagesFabricant/Fabricant.jsf";
}else{
if (a == 2) {
return "/pagess/pagesComposant/Composant.jsf";
}else{
if(a == 3){
return "/pagess/pagesDeq/DEQ.jsf";
}
}
}
}
return null;
}
}
I added SpringBeanFacesELResolver in faces-config.xml:
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application> on faces.config.xml
and I also included the relevant listeners in web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/application.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
My view:
<p:tabMenu activeIndex="#{loginBean.activeindex}">
<p:menuitem value="Home" icon="ui-icon-star" action="#{loginBean.Dirige(0)}" />
<p:menuitem value="Fabricants" icon="ui-icon-wrench" action="#{loginBean.Dirige(1)}" />
<p:menuitem value="Composants" icon="ui-icon-search" action="#{loginBean.Dirige(2)}"/>
<p:menuitem value="Dossier d'equivalence" icon="ui-icon-document" action="#{loginBean.Dirige(3)}"/>
</p:tabMenu>
And finally this is the error I've got:
Grave: javax.el.MethodNotFoundException: /templates/template.xhtml #42,95 action="#{loginBean.Dirige(1)}": Method not found: com.ardia.beans.LoginBean#1af73b2.Dirige(java.lang.Long)
javax.faces.el.MethodNotFoundException: javax.el.MethodNotFoundException: /templates/template.xhtml #42,95 action="#{loginBean.Dirige(1)}": Method not found: com.ardia.beans.LoginBean#1af73b2.Dirige(java.lang.Long)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:92)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
the problem is that I start the application in another tomcat server .. it works well it accepts bean method with parameters
Thx all for your cooperation

JSF2 disabled attribute for validator evaluated only for first cycle?

I found that disabled attribute for any validator I use in JSF2 is evaluated only in the first cycle if my managed bean is ViewScoped.
But I would like to make use of disabled attribute for my validators based on data I get from 4th update phase. So I would expect it reevaluated in all cycles performed on the same view.
Example xhtml page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head></h:head>
<h:body>
<h:form>
<h:panelGrid id="pnlGrid">
<h:inputText id="someValueId" value="#{testPageBean.someValue}">
<f:validateLength minimum="2" maximum="4"
disabled="#{testPageBean.disableValidateLength}"/>
</h:inputText>
<h:messages for="someValueId"/>
<h:commandButton action="#{testPageBean.doSomething}"
value="Do something" />
</h:panelGrid>
</h:form>
</h:body>
</html>
and its view scoped managed bean
package cz.kamosh;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
#ManagedBean
#ViewScoped
public class TestPageBean implements Serializable {
boolean disableValidateLength = false;
private String someValue;
public TestPageBean() {
System.out.println("Constructor TestPageBean");
}
public String getSomeValue() {
return someValue;
}
public void setSomeValue(String someValue) {
this.someValue = someValue;
}
/**
* Some action without any navigation as a result
*/
public void doSomething() {
disableValidateLength = !disableValidateLength;
System.out.printf(
"DoSomething, someValue: %1$s, disableValidateLength: %2$b\n",
someValue, disableValidateLength);
}
public boolean isDisableValidateLength() {
System.out.printf("IsValidateLength, disableValidateLength: %1$b\n",
disableValidateLength);
return disableValidateLength;
}
}
I know that I should blame implementation com.sun.faces.facelets.tag.jsf.ValidatorTagHandlerDelegateImpl:
private void applyNested(FaceletContext ctx,
UIComponent parent) {
// only process if it's been created
if (!ComponentHandler.isNew(parent)) {
return;
}
...
}
These three rows cause validator not being reevaluated its disabled attribute when I perform action:-(
Could some please give me a hint, what was the motivation for JSF2 guys to implement this way or even better how to solve my problem?
EDIT:
Version of JSF2: 2.0.3-SNAPSHOT
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>JSF2Testing</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
</web-app>
EDIT2 Attempt to follow BalusC' suggestion
Changes on page:
<h:inputText id="someValueId" value="#{testPageBean.someValue}">
<f:validator validatorId="myLengthValidator"/>
<f:attribute name="disableMyLengthValidator" value="#{testPageBean.disableValidateLength}"/>
<f:attribute name="minimum" value="2" />
<f:attribute name="maximum" value="4" />
</h:inputText>
Own validator used instead of standard :
import java.io.Serializable;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.LengthValidator;
import javax.faces.validator.ValidatorException;
#FacesValidator("myLengthValidator")
public class MyLengthValidator extends LengthValidator implements Serializable {
public MyLengthValidator() {
System.out.println("MyLengthValidator constructor");
}
#Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
if((Boolean)component.getAttributes().get("disableMyLengthValidator")) {
return;
}
setMinimum(Integer.valueOf((String)component.getAttributes().get("minimum")));
setMaximum(Integer.valueOf((String)component.getAttributes().get("maximum")));
super.validate(context, component, value);
}
}
My notes about this solution:
requires own implementation even if for standard validators
is dependent on attributes on component (inputText) level
validator is triggered even if it should not be
I am pretty sure it will not behave as we expect when client side validation is provided for validator
I consider is as very ugly and not following JSF2 :-(
You've become another victim of the chicken-egg issue with partial state saving and view scoped beans as described in issue 1492 which is to be fixed in the upcoming Mojarra 2.2.
You should also immediately have realized that something's not entirely right when you saw the constructor of a view scoped bean being invoked on every request instead of only once at the first request of a view.
One of the ways to fix it is to disable the partial state saving altogether:
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
See also:
Communication in JSF 2 - #ViewScoped fails in tag handlers
Why does f:validateDoubleRange only work for #SessionScoped?

Resources