2 Replies Latest reply on Jul 18, 2013 7:03 AM by Anton Hughes

    ListWidget and binding

    Anton Hughes Master

      Hi

       

      I have a list widget - RuleListWidget - and this is to get its list of rules from a service call response.

       

      My struggle is - how do I get my list of rules into the RuleListWidget?

      I'm setting the items at @PostConstruct - which does seem wrong - but what should I do?

       

       

       

      ruleService.call(new RemoteCallback<List<app.client.shared.datamodel.Rule>>() {
      
      
                                                                  @Override
                                                                  public void callback(List<app.client.shared.datamodel.Rule> response) {                                                                      
        
                                                                            rulesWidget.rules=response;
                                                                            rowContainer.add(rulesWidget);    
                                                                   }).getRules();
      
      

       

       

      package app.client.local;
      
      
      import java.util.List; 
      
      import javax.annotation.PostConstruct; 
      
      import org.jboss.errai.ui.client.widget.ListWidget;
      
      import app.client.shared.datamodel.Rule;
      
      
      public class RuleListWidget extends ListWidget<Rule, RuleWidget> {
        
                List<Rule> rules;
        
                @PostConstruct
                  public void init() { 
                   this.setItems(this.rules);
                  }
      
      
                @Override
                protected Class<RuleWidget> getItemWidgetType() {
                          return RuleWidget.class;
                }
      
      
      }
      
      
        • 1. Re: ListWidget and binding
          Erik Jan de Wit Novice

          Hi Anton,

           

          You don't need to extend the ListWidget to use it. There is a producer that can produce differenent list types: OrderdList, UnOrderdList or a Generic one if you don't specify a qualifier.

          Below an example:

           

          {code}

          @Inject      //will create a new listwidget for you

          @DataField

          @OrderedList      //orderd list

          ListWidget<Rule, RuleWidget> rules;


          ...


              @PostConstruct

              public void buildWidget() {

               ruleService.call(new RemoteCallback<List<app.client.shared.datamodel.Rule>>() {

                                                                     @Override

                                                                      public void callback(List<app.client.shared.datamodel.Rule> response) {                                                                     

           

                                                                                rules.setItems(response);

                                                                                rowContainer.add(rulesWidget);   

                                                                       }).getRules();

           

              }

          {code}

           

           

          Hope that helps,

               Erik Jan

          1 of 1 people found this helpful
          • 2. Re: ListWidget and binding
            Anton Hughes Master

            Hi Erik

             

            I have upgraded to 2.4 beta1, primarily to take advantage of your work on lists.

             

            Its a very elegant way of working with lists - nice work!

             

            I have a few questions:

             

            Is there documentation yet on this feature?

            In a template, should I add the <ul> tags or does Errai do that?