0 Replies Latest reply on May 23, 2014 3:52 AM by qakane

    ListShuttle and validation

    qakane

      Hello,

      I know that this problem was already discussed, but solution from those topics doesn't work in my situation....

      So... Could you help me by some tips or something same, if possible? I will be greatly pleased.

      Well, I have form:

      <h:form>

          <h:outputText value="Select Location" />

          <h:selectOneMenu value="#{myBean.mainLocation}"

              valueChangeListener="#{myBean.changeMainLocation}"

              >

              <f:selectItems value="#{myBean.locationsList}" />

          </h:selectOneMenu>

          <h:panelGroup rendered="#{myBean.isMainLocationExists}">

              <br>

              <rich:separator align="left" />

              <br>

              <rich:listShuttle sourceValue="#{myBean.locationsForCascading}" id="ls"

                  targetValue="#{myBean.cascadedLocations}" var="items"

                  sourceListWidth="180" targetListWidth="180"

                  sourceCaptionLabel=" "

                  targetCaptionLabel="Locations that cascade <br>through #{myBean.mainLocation}"

                  fastOrderControlsVisible="false" orderControlsVisible="false"

                  converter="LocationDataConverter">

                  <rich:column>

                      <h:outputText value="#{items.location}" />

                  </rich:column>

              </rich:listShuttle>

              <br>

              <h:panelGroup styleClass="leftalignclass">

                  <h:commandButton value="Save"

                      action="#{myBean.saveChanges}"

                      styleClass="leftalignclass">

                  </h:commandButton>

              </h:panelGroup>

          </h:panelGroup>

      </h:form>

         with bean:

      <a4j:keepAlive beanName="myBean" />

      (faces-config:)

      <managed-bean>

            <description>MyBean</description>

            <managed-bean-name>myBean</managed-bean-name>

            <managed-bean-class>

               com.MyBBean

            </managed-bean-class>

            <managed-bean-scope>request</managed-bean-scope>

            <managed-property>

               <property-name>portletTabProperty</property-name>

               <property-class>

                  com.PortletTabs

               </property-class>

               <value>#{portletTabs}</value>

            </managed-property>

         </managed-bean>

       

       

      and code:

      public abstract class MyBBean extends DomainDataBB implements Serializable{

       

         private static final long serialVersionUID   = 1L;

         private MgmtIF  mgmt = getMgmt();

         private PortletTabs       portletTabProperty = null;

         private String            mainLocation  = null;

         private String        oldMainLocation  = null;

       

         private List<LocationData> locationsForCascading;

       

         private List<LocationData> cascadedLocations;

         List<SelectItem>           locationsList;

       

         public MyBBean() {

            locationsList = new ArrayList<SelectItem>();

         }

       

         /**

          *

          * @return INITIAL_VIEW

          */

         public String saveChanges() throws Exception {

             ...

       

           saving

       

            return INITIAL_VIEW;

         }

       

         /**

          */

         private void validateCascadedLocations(){

            LocationData mLocation = new LocationData(this.mainLocation);

            if ((cascadedLocations.size() > 0)  && (cascadedLocations.contains(mainLocation))) {

               cascadedLocations.remove(mainLocation);

            }

         }

       

         /**

          */

         public boolean isMainLocationExists() throws Exception {

            if (mainLocation == null) {

               initializeLocationsLists();

               return false;

            }

            return true;

         }

       

         /**

          */

         public void setMainLocationExists(boolean hlNull) {

            // Do nothing

         }

       

         /**

          */

         public void changeMainLocation(ValueChangeEvent event) throws Exception {

      getPortletTabProperty().setSelectedTab(getTabName());
      setMainLocation0((String) event.getNewValue());
      return INITIAL_VIEW;

         }

       

         /**

          */

         public List<SelectItem> getLocationsList() throws Exception {

            updateLocationsList();

            if(locationsList.size() == 0){

               initializeLocationsLists();

            }

            return locationsList;

         }

       

         /**

          *

          */

         synchronized private void updateLocationsList()throws Exception {

       

            List<LocationData> locations  = getMgmt().getLocations();  

            Collections.sort(locations, new Comparator<LocationData>(){

               @Override

               public int compare(LocationData o1, LocationData o2) {

                  return o1.getName().compareTo(o2.getName());

               }});

       

            String sLocation;

            locationsList.clear();

            for(Object location : locations){

               sLocation = ((LocationData)location).getName();

               if(getMainLocation() == null && sLocation!=null){

                 setMainLocation0(sLocation);

               }

               locationsList.add(new SelectItem(sLocation, sLocation));

            }

         }

       

         /**

          */

         private void updateLocationsForCascading() throws Exception {

       

               List<LocationData> locationsForCascading = getMgmt().getLocationsForCascading();

               Arrays.sort(locationsForCascading, new Comparator<LocationNaturalKeyDO>() {

                  @Override

                  public int compare(LocationData o1, LocationData o2) {

                     return o1.getName().compareTo(o2.getName());

                  }

               });

               this.locationsForCascading = locationsForCascading;

        

               LocationData mainLocation = new LocationData(this.mainLocation);

               if (this.locationsForCascading.contains(mainLocation)) {

                  this.locationsForCascading.remove(mainLocation);

               }

         }

       

         /**

          */

         private void updateCascadedLocationsList() throws Exception  {

       

               LocationData cascadingLoc = new LocationData();

               cascadingLoc.setName(this.mainLocation);

               List<LocationData> cascadedLocations;

               try {

                  cascadedLocations = getMgmt().getCascadedLocations(domNatKey, cascadingLoc);

                  Arrays.sort(cascadedLocations, new Comparator<LocationData>() {

                     @Override

                     public int compare(LocationData o1, LocationData o2) {

                        return o1.getName().compareTo(o2.getName());

                     }

                  });

                  this.cascadedLocations = cascadedLocations;

               }

               catch (Exception e) {

                  PortletLogger.debugLog("Error", e, this.getClass());

               }

         }

       

       

         /**

          */

         public String getMainLocation()throws Exception {

            return mainLocation;

         }

       

         /**

          */

         public void setMainLocation(String mainLocation) {

         }

       

         /**

          */

         synchronized private void setMainLocation0(String mainLocation) throws Exception{

            oldMainLocation = this.mainLocation;

            this.mainLocation = mainLocation;

         }

       

         /**

          */

         private void initializeLocationsLists()

         {

            locationsForCascading = new ArrayList<LocationData>();

            cascadedLocations = new ArrayList<LocationData>();

         }

       

         /**

          * Get method for  SelectedTab to get the tab page in the JSF page

          */

         public PortletTabs getPortletTabProperty() {

            return portletTabProperty;

         }

       

         /**

          * Set method for SelectedTab to set the tab page in the JSF page to display the message

          *

          * @param portletTabProperty

          */

         public void setPortletTabProperty(PortletTabs portletTabProperty) {

            this.portletTabProperty = portletTabProperty;

         }

       

         public MgmtIF getMgmt() {

            return mgmt;

         }

       

       

         public List<LocationData> getLocationsForCascading() {

            return locationsForCascading;

         }

       

         public void setLocationsForCascading(List<LocationData> locationsForCascading) {

            if (oldMainLocation!=null && mainLocation!=null && oldMainLocation.equals(mainLocation)||oldMainLocation==null) {

            this.locationsForCascading = locationsForCascading;

            }

         }

       

         public List<LocationData> getCascadedLocations() {

            return cascadedLocations;

         }

       

         public void setCascadedLocations(List<LocationData> cascadedLocations) {

            if (oldMainLocation!=null && mainLocation!=null && oldMainLocation.equals(mainLocation)||oldMainLocation==null) {

               this.cascadedLocations = cascadedLocations;

            }

         }

       

      }

       

      public class LocationDataConverter implements Converter {

         public Object getAsObject(FacesContext context, UIComponent component, String value) {

            String[] split = value.split("[&=]");

       

            LocationData obj = new LocationData(split[1]);

            System.out.println("MyConverter getAsObject: " + value);

            return obj;

         }

       

         public String getAsString(FacesContext context, UIComponent component, Object value) {

            LocationData obj = (LocationData) value;

            System.out.println("MyConverter getAsString: " + value);

            return obj.toString();

         }

      }

       

      public class LocationData implements Serializable {

         /**

          *

          */

         private static final long serialVersionUID = 1L;

         private String location;

       

         public LocationData(String location) {

            this.location = location;

         }

       

         /**

          * @return the location

          */

         public String getLocation() {

            return location;

         }

       

         /**

          * @param location

          *           the location to set

          */

         public void setLocation(String location) {

            this.location = location;

         }

       

         /**

          * Returns the hashcode for this LocationData.

          */

         @Override

         public int hashCode() {

            return 37 * getLocation().hashCode();

         }

       

         /**

          * Returns whether this LocationData is equal to the LocationData passed in.

          */

         @Override

         public boolean equals(Object o) {

            LocationData obj = (LocationData) o;

            if(o == null) return false;

            if(this.getLocation() == null){

               return obj.getLocation() == null;

            }

            return this.getLocation().equals(obj.getLocation());

         }

       

         @Override

         public String toString() {

            StringBuffer a = new StringBuffer();

            a.append("location=" + this.getLocation());

       

            return a.toString();

         }

      }

       

      When page is loaded slowly and we have enough time to send multiple request choosing several lines in h:selectOneMenu, we can see this message:
      "Component _js_MainMenuPortlet__dp_2__MSRSMgmtPortlet_:j_id_jsp_566537391_0:viewMyBean:j_id_jsp_626996794_1pc6:ls has invalid value expression location=Clients Location"

      about value location=Clients Location" for rich:listShuttle

      And I have no idea how to avoid this.
      Could you give me any advices please?
      thank you in advance anyway.