Skip to content

Mis en ligne par admin - 23 janvier 2014 - Web Applications

Primefaces: an OrderList including inputs

There is no way of putting inputs inside a PrimeFaces (orderList is not a UIData component). Therefore, the solution to do it is through… dataTable !

Here is a meaningful example:


<h:panelGroup id="panelGroup">
<p:dataTable styleClass="ui-datatable-sortable" value="#{myBean.values}" var="layer" converter="#{myBean.converter}" id="myTable">
  <p:column>
      <p:selectBooleanCheckbox id="checkBox" value="#{layer.shown}" >
              <p:ajax update="checkBox"/>
      </p:selectBooleanCheckbox>
  </p:column>
</p:dataTable>
 <p:remoteCommand name="reorderTable" action="#{myBean.reorderTable}" update="panelGroup"/>
                  <script type="text/javascript">
                  $(".ui-datatable-sortable tbody").sortable(
                      {
                             update: function(event, ui) {
                                var x = ui["item"].parent().children().map(
                                   function() {
                                      return $(this).attr("data-ri");
                                   }
                                ).get().join(",");
                                reorderTable([{name: 'newOrder', value: x}]);
                             }                  
                          }    
        );
   </script>
   </h:panelGroup>

And in the Managed Bean (where XXX is the Array Object class):


public void reorderTable() {
       String newOrder = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("newOrder");
       String[] noArr = newOrder.split(",");

       List<XXX> n = new ArrayList<XXX>();
       for ( String s : noArr ) {
          n.add( this.getValues().get( Integer.parseInt(s)) );
       }
       this.setValues(n);
    }

Articles similaires

Les articles suivants abordent des thèmes communs.

Commentaires

Partagez vos remarques.

Il n'y a pas de commentaires pour cet article.

Add a Comment

Fill in the form and submit.