1. #1
    Sencha User Oussama Mjihil's Avatar
    Join Date
    Mar 2013
    Location
    Morocco
    Posts
    3
    Vote Rating
    0
    Oussama Mjihil is on a distinguished road

      0  

    Default Answered: How to reference (manipulate) a widget from an other in gxt3

    Answered: How to reference (manipulate) a widget from an other in gxt3


    Im New Gxt user,
    In my application, I tried to use the provided exemples from sencha.com.
    I'm looking for a mécanisme to use a nested widgets in a same interface (RIA logic), And keep control between them.

    Code:
    public class BorderLayoutUiBinderDynamicAttribute implements IsWidget, EntryPoint { 
      interface MyUiBinder extends UiBinder<Component, BorderLayoutUiBinderDynamicAttribute> {
      }
     
      private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
      private static AccordionLayout alayout = new AccordionLayout();
      private static FilterGrid filterGrid = new FilterGrid();
      private static AjoutContact ajoutContact = new AjoutContact();
     
      @UiField
      BorderLayoutContainer con;
      @UiField 
      ContentPanel menu;
      @UiField
      ContentPanel center;
      @UiField
      ContentPanel center2;
      @UiField
      ContentPanel headerLogo;
    ........
    ........
     public void onModuleLoad() {
          Widget con = asWidget();
            Viewport viewport = new Viewport();
            menu.add(alayout);
            center.add(filterGrid);
            center2.add(ajoutContact);
            Image loadingImage = new Image(ExampleImages.INSTANCE.logo());
            headerLogo.add(loadingImage);
            viewport.add(con);
            RootPanel.get().add(viewport);
      }
    .......
    in the ContentPanel center2 I insert an Widget which contains :

    Code:
     panel.addButton(new TextButton("Enregistrer", new SelectHandler() {
            public void onSelect(SelectEvent event) {
                Contact c = new Contact();
                c.setNom(nom.getText());
                c.setPrenom(prénom.getText());
                c.setEmail(email.getText());
                c.setDate_naissance(birthday.getCurrentValue());
                ExampleServiceAsync service = GWT.create(ExampleService.class);
                AsyncCallback<String> callback = new AsyncCallback<String>() {
                    public void onFailure(Throwable caught) {
                         Window.alert("Contact n'est pas Ajouté avec succès ");
                    }
    
    
                    public void onSuccess(String result) {
                        // I Want To Refrech data of @UiField ContentPanel center in BorderLayoutUiBinderDynamicAttribute 
                      Window.alert("Contact Ajouté avec succès ");
                    }
                  };
                service.enregistrerContact(c, callback);
            }
        }));
    Rpc work fine, but i don't now how to get reference to "center" or others elements of rootPanel

    it should be like this : ContentPanel cp = rootPanel.getViewport().getCon().getCenter(); if we follow the logic swing.
    Capture.jpg

  2. Remember, even though you're doing GXT/GWT programming, you're working in Java land, so the same rules of Java apply. If you want a reference to something you will have to provide it or provide a means to get it.

    That said, your problem doesn't actually require this and the easiest way, given that you are in a handler is to use an application wide SimpleEventBus. I would declare it once and provide a static accessor to it in your main entry point (unless you want to pass it around). Custom events are easy and will let you have disparate parts of the application talk to each other without having to pass references around and making it very tightly coupled.

    Basically, you would add a handler to the bus reference in your BorderLayoutUiBinderDynamicAttribute class that tells the center panel to refresh and fire an event to this bus in the onSuccess method. This way, you don't need to have the two pieces have a reference to each other.

    Does this make sense? I can post an example of a custom event if you need.

  3. #2
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      1  

    Default


    Remember, even though you're doing GXT/GWT programming, you're working in Java land, so the same rules of Java apply. If you want a reference to something you will have to provide it or provide a means to get it.

    That said, your problem doesn't actually require this and the easiest way, given that you are in a handler is to use an application wide SimpleEventBus. I would declare it once and provide a static accessor to it in your main entry point (unless you want to pass it around). Custom events are easy and will let you have disparate parts of the application talk to each other without having to pass references around and making it very tightly coupled.

    Basically, you would add a handler to the bus reference in your BorderLayoutUiBinderDynamicAttribute class that tells the center panel to refresh and fire an event to this bus in the onSuccess method. This way, you don't need to have the two pieces have a reference to each other.

    Does this make sense? I can post an example of a custom event if you need.

  4. #3
    Sencha User Oussama Mjihil's Avatar
    Join Date
    Mar 2013
    Location
    Morocco
    Posts
    3
    Vote Rating
    0
    Oussama Mjihil is on a distinguished road

      0  

    Default


    Thank you for this nice reply.
    I tried to resolve this problem by adding some static declarations/invocations like that :
    HTML Code:
     public void onSuccess(ContactView contact) {    	        	FilterGridContacts.store.add(contact);    	        	for(ContactView c:FilterGridContacts.store.getAll()){    	        		if(c.getIdContact()==contact.getIdContact()) {    	        			FilterGridContacts.store.remove(c);    	        			FilterGridContacts.store.add(contact);    	        		}    	        	}    	            Window.alert("Contact Modifié avec succès ");    	        }
    Its not a profesional way, to do a binding.


    When I was still seeking, i found somme solution based on : EventBus ... FireEvent bat its a new terminology for me.


    If you can post an example of using this methode, or if you have some helpful documentation.

  5. #4
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    Sure.
    Code:
    // here's your event:
    public class FooEvent extends GwtEvent<FooEvent.FooHandler>
    {
      public static final Type<FooHandler> TYPE = new Type<FooHandler>();
    
      @Override
      protected void dispatch(FooHandler handler)
      {
        handler.onFooEvent(this);
      }
    
      @Override
      public Type<FooHandler> getAssociatedType()
      {
        return TYPE;
      }
    
      public interface FooHandler extends EventHandler
      {
        public void onFooEvent(FooEvent event);
      }
    }
    
    // now define your bus and register the handler
    SimpleEventBus bus = new SimpleEventBus();
    bus.addHandler(FooEvent.TYPE, new FooEvent.FooHandler()
    {
      @Override
      public void onFooEvent(FooEvent event)
      {
        // do something to respond to the vevent
      }
    });
    
    // finally, elsewhere in your code, you can do this and the handler will execute:
    bus.fireEvent(new FooEvent());
    Give that a go and see if it solves your problem. Remember, you'll most likely need to make the bus accessible to your entire application otherwise, you'll have to pass references to it around.

  6. #5
    Sencha User Oussama Mjihil's Avatar
    Join Date
    Mar 2013
    Location
    Morocco
    Posts
    3
    Vote Rating
    0
    Oussama Mjihil is on a distinguished road

      0  

    Default


    Thank you, its clear now

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar