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

    ListWidget and binding

    magick93

      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
          edewit

          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
            magick93

            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?