2 Replies Latest reply on Dec 20, 2011 4:47 AM by Adrien Adrien

    RF4.1-Final : rich:PickList problem ajax&requestScope (work viewscope)

    Adrien Adrien Apprentice

      Hi

      I ve a strange behaviour with a picklist updated with ajax, all work when the back bean is viewscope but validation error appears when the bean is request scope (I m currently migrate from RF 3.3 to RF 4.1.final, and it worked in RF3.3).

       

      I ve put a simple example :

      - a select which on value change update a picklist (choices: c0, c1)

      -a picklist : display selected list

      -a h:commandButton to execute anything

       

      Process:

      -Load the page, choice is c0, change  it to c1

      -picklist is updated

      -dbl click on a left item from picklist  to add it as selected

      -click the button search

      if  scope bean  is view => all work

      if scope bean is request =>error of validation is displayed


      If any body has an idea ....

      Thanks for your help

      Adrien

       

      {code}

      <?xml version="1.0" encoding="UTF-8"?>

      <!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:f="http://java.sun.com/jsf/core"

                xmlns:ui="http://java.sun.com/jsf/facelets"

                xmlns:h="http://java.sun.com/jsf/html"

                xmlns:rich="http://richfaces.org/rich"

                xmlns:a4j="http://richfaces.org/a4j"

                

                >

      <h:head>

       

       

      </h:head>

      <h:body>

                <f:view contentType="text/html">

                          <h:form id="advSearchForm">                              

                                    <h:selectOneMenu id="c" value="#{CtrlTestPickList.currentchoice}"    valueChangeListener="#{CtrlTestPickList.choiceChanged}">

                                                        <f:selectItems value="#{CtrlTestPickList.choices}" />

                                                        <a4j:ajax event="valueChange" execute="@this" render="dpts    />

                                    </h:selectOneMenu>

                                    <br />

                                                         

       

                    <rich:pickList  id="dpts"  value="#{CtrlTestPickList.selectedItem}"  listWidth="170px" listHeight="100px"      >

                                              <f:selectItems  value="#{CtrlTestPickList.currentlist}" />

                                      </rich:pickList>

                 <br />

                                 

                

              

                                    <h:commandButton id="search" value="search" action="#{CtrlTestPickList.search}" >

                                              <f:ajax    execute="@form" render="@form" />

                                    </h:commandButton>

       

                                    <rich:messages></rich:messages>

       

                          </h:form>

                </f:view>

      </h:body>

      </html>

       

      {code}

       

       

      {code}

        

      import java.io.Serializable;

      import java.util.ArrayList;

      import java.util.Hashtable;

      import java.util.List;

      import java.util.Map;

       

       

      import javax.faces.bean.ManagedBean;

      import javax.faces.bean.RequestScoped;

      import javax.faces.bean.ViewScoped;

      import javax.faces.event.ValueChangeEvent;

      import javax.faces.model.SelectItem;

       

       

      @ManagedBean(name="CtrlTestPickList")

      //error on request

      @RequestScoped

      //work viewscope

      // @ViewScoped

      public class CtrlTestPickList implements Serializable {

                /**

                 *

                 */

                private static final long serialVersionUID = 1L;

                List<SelectItem> choices= new ArrayList<SelectItem>();

       

       

                String currentchoice="c0";

                List<String> selected;

                List<String> selectedItem;

                Map<String,List<SelectItem>> model=new Hashtable<String, List<SelectItem>>();

           public CtrlTestPickList() {

                    for (int i = 0; i < 2; i++) {

                              ArrayList<SelectItem> l = new ArrayList<SelectItem>();

                              choices.add(new SelectItem("c"+i, "c"+i));

                              model.put("c"+i, l);

                                    for (int j = 0; j < 5+i; j++) {

                                              l.add(new SelectItem("l"+i+"-"+j, "list"+i+"-"+j));

                                    }

         

         

                          }

                    

         

                }

                public String getCurrentchoice() {

                          return currentchoice;

                }

                public void setCurrentchoice(String currentchoice) {

                          this.currentchoice = currentchoice;

                }

                public List<SelectItem> getCurrentlist() {

                          return model.get(currentchoice);

                }

       

                public List<SelectItem> getChoices() {

                          return choices;

                }

                public void setChoices(List<SelectItem> choices) {

                          this.choices = choices;

                }

          

                public void choiceChanged(ValueChangeEvent event) {

       

                          System.out.println("choiceChanged(ValueChangeEvent) new value-->"+event.getNewValue()+"  "+this.getClass().getName());

       

                          if (null != event.getNewValue()) {

                                    currentchoice=(String) event.getNewValue();

       

                          }

       

                }

                public String search(){

                          System.out.println("search");

                          return "";

                }

                public List<String> getSelectedItem() {

                          return selectedItem;

                }

                public void setSelectedItem(List<String> selectedItem) {

                          this.selectedItem = selectedItem;

                }

       

       

      }

       

      {code}