3 Replies Latest reply on Apr 27, 2010 3:10 AM by Harut Sargsyan

    Validation of h:selectOneMenu component populated dynamically

    Leonid Sokolin Newbie

      I have a problem, which might be of interest to some people.

       

      I need to populate h:selectOneMenu component with the names of Sharepoint folders in my SP site.

       

      So, I do it on window load dynamically from Javascript function using Sharepoint API Web service.

       

      This part works just fine and I can see components populated properly.

       

      Then users could select folder and sub-folder they are interested in and click on the button, which opens popup window with the list of documents contained in this folder.

       

      Problem occurs after this window opens, I see the error:

       

      piPublisherForm:channel: Validation Error: Value is not valid

       

      on one of the components (the one which lists subfolder names). Note, that another one (that has folder names) passes the validation.

       

      I think, it is happening because the component is populated dynamically in Javascript using code as the one below:

       

      selectID.options[selectID.length] = new Option(filename, filename);

       

      It probably causes validation error during Process Validations phase.

       

      I am not sure though how to fix it and would appreciate the response.

       

      Please see attached XHTML page, supporting Java bean and JS function that it used to populate components.

       

      Would appreciate a response.

       

      Thanks,

       

      Leonid

        • 1. Re: Validation of h:selectOneMenu component populated dynamically
          Nick Belaevski Master

          Hi Leonid,

           

          In JSF all selects are validated against bean model and if there are submitted items that are not present in the model, validation fails due to security reasons. If you are absolutely sure that it's ok, then just build up select model from submitted data.

          • 2. Re: Validation of h:selectOneMenu component populated dynamically
            Leonid Sokolin Newbie

            Hi Nick,

             

            The problem here is that we are not supposed to know what should be the values obtained from Sharepoint.

             

            They are meant to be really dynamic and all communication should be handled by the client. There are actually some security problems in accessing SP from the server that runs on Linux. It is much easier to do in Javascript in the browser.

             

            So, how could I pass them back to the server to build up select model? Could you provide some example?

             

            Or maybe JSF just not needed here and I should build a simple jsp page, which wouldn't communicate to the server at all.

             

            What do you think?

             

            Leonid

            • 3. Re: Validation of h:selectOneMenu component populated dynamically
              Harut Sargsyan Apprentice

              Hi Leonid,

               

              Whether JSF needed or not depends on current project business requirement specification...


              So, how could I pass them back to the server to build up select model? Could you provide some example?

               

              You can create afj:jsFunction, and call it in you javascript method (where you have a functionality of getting filenames...), by passing needed data as method param, e.g. you can construct any String with specified format (delimetered by commas "filename1, filename2,....") and further get separated filenames in server side business logic....

               

              Here is similar functional from one of my projects:

              <a4j:jsFunction name="showMonth"
                                      reRender="fusMonthChrt"
                                      actionListener="#{metricsController.initMonthlyChart}"
                                      oncomplete="changeWindowPosition();">
                              <a4j:actionparam id="reportYearParam" name="reportYear"/>
                              <a4j:actionparam id="reportTypeParam" name="reportType"/>              

              </a4j:jsFunction>


              .................................

              function showChartByGivenParams(year, type)
                  {

                      ..............


                     showMonth(year, type);             
                  }

               

              ................................


              /**
                   * Action Listener method, called when user clicks on
                   * any column in yearly Fusion Chart.
                   * @param event
                   */
                  public void initMonthlyChart(ActionEvent event) {

                        ............................

                        FacesContext.getCurrentInstance().getExternalContext().getRequest().getParameter("reportType");

                        ..............................

                  }

              1 of 1 people found this helpful