Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SmartGWT & Google MVP

    I have been working on a test application using SmartGWT and the Google MVP framework to evaluate SmartGWT to see if we will use it in a new product we are developing.

    I have managed to get the application to work, but i had to modify the following code in the <view>Presenter class (which is how is done in the Google MVP tutorial):

    public void go(final HasWidgets container) {
    container.clear();
    container.add(display.asWidget());
    }

    To:
    public void go() {
    display.show();
    }



    Note: My display class extends the SmartGWT Canvas object, which means that it is a widget. I call display.hide() to hide the view when i go to another view

    If i use the Goople MVP way i always get a pop-up box error,

    Has anyone managed to get the Google MVP approach working with SmartGWT?

    #2
    What does the pop box error say?

    Comment


      #3
      It displays a chunk of javascript which appears to say that an object is not defined.

      I will revert the code back and post to this thread the screen dump that shows the error.

      Let me know if you want me to provide the classes as well, perhaps you could use the code to add it to the Showcase section

      Comment


        #4
        Seeing the code would be helpful as to whether you adding smartgwt components to gwt components, whether the widgets are already part of a layout or your just calling show() and they aren't part of any container.

        Comment


          #5
          I have attached the pop up window jpeg

          The following is the error output in eclipse

          21:42:00.290 [ERROR] [sample] 21:42:00.290:TMR0:WARN:Log:Error: 'Object required' in http://127.0.0.1:8888/Sample.html?gwt.codesvr=127.0.0.1:9997 at line 1731
          [c]Element.getOffsetLeft(_1=>[HTMLElement]{nodeName:HTML}) [c]Element.$yw(_1=>"left", _2=>[DIVElement]{ID:isc_0}, _3=>[HTMLElement]{nodeName:HTML}, _4=>false) [c]Element.$s4(_1=>[DIVElement]{ID:isc_0}, _2=>[HTMLElement]{nodeName:HTML}, _3=>false) Canvas.$s4(_1=>undef) Canvas.getPageLeft() Canvas.$414(null, undef) [c]Page.handleEvent(_1=>null, _2=>"resize", _3=>undef) [c]EventHandler.$hr(_1=>undef) callback(undefined=>undef)
          "isc.EH.$hr()" [c]Class.fireCallback(_1=>"isc.EH.$hr()", _2=>undef, _3=>Array[0], _4=>Obj{length:2}, _5=>true) on [Class Timer] [c]Timer.$in(_1=>"$ir57") anonymous()
          "isc.Timer.$in('$ir57')"
          com.smartgwt.client.core.JsObject$SGWT_WARN: 21:42:00.290:TMR0:WARN:Log:Error: 'Object required' in http://127.0.0.1:8888/Sample.html?gwt.codesvr=127.0.0.1:9997 at line 1731
          [c]Element.getOffsetLeft(_1=>[HTMLElement]{nodeName:HTML}) [c]Element.$yw(_1=>"left", _2=>[DIVElement]{ID:isc_0}, _3=>[HTMLElement]{nodeName:HTML}, _4=>false) [c]Element.$s4(_1=>[DIVElement]{ID:isc_0}, _2=>[HTMLElement]{nodeName:HTML}, _3=>false) Canvas.$s4(_1=>undef) Canvas.getPageLeft() Canvas.$414(null, undef) [c]Page.handleEvent(_1=>null, _2=>"resize", _3=>undef) [c]EventHandler.$hr(_1=>undef) callback(undefined=>undef)
          "isc.EH.$hr()" [c]Class.fireCallback(_1=>"isc.EH.$hr()", _2=>undef, _3=>Array[0], _4=>Obj{length:2}, _5=>true) on [Class Timer] [c]Timer.$in(_1=>"$ir57") anonymous()
          "isc.Timer.$in('$ir57')"
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
          at java.lang.reflect.Constructor.newInstance(Unknown Source)
          at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
          at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
          at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
          at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
          at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
          at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
          at java.lang.Thread.run(Unknown Source)

          The following is the <View> and <View>Presenter objects for the Login Page display

          Code:
          package com.sample.client.view;
          
          import java.util.Map;
          
          import com.sample.client.presenter.LoginScreenPresenter;
          import com.google.gwt.user.client.ui.Widget;
          import com.smartgwt.client.widgets.EdgedCanvas;
          import com.smartgwt.client.widgets.form.DynamicForm;
          import com.smartgwt.client.widgets.form.fields.ButtonItem;
          import com.smartgwt.client.widgets.form.fields.PasswordItem;
          import com.smartgwt.client.widgets.form.fields.TextItem;
          import com.smartgwt.client.widgets.form.fields.events.HasClickHandlers;
          import com.smartgwt.client.widgets.layout.VLayout;
          
          public class LoginScreenView extends EdgedCanvas implements LoginScreenPresenter.Display
          {
          	private DynamicForm form;	
          	private PasswordItem password;
          	private TextItem username;
          	private ButtonItem addUserButton;
          	private ButtonItem loginButton;
          	
          	public LoginScreenView()
          	{
          		VLayout vlayout = new VLayout();
              	setSize("350px", "200px");
          
              	form = new DynamicForm();
                  form.setAutoFocus(true);   
                  form.setNumCols(2);   
                  form.setWidth(275);
                  form.setTitleField("Login Screen");
                  
                  username = new TextItem("username");   
                  username.setTitle("Username");   
                  username.setSelectOnFocus(true);   
                  username.setWrapTitle(false);      
            
                  password = new PasswordItem("password");   
                  password.setTitle("Password");      
                  password.setWrapTitle(false);   
            
                  loginButton = new ButtonItem("login", "Login");      
                  loginButton.setWidth(80);
                  
                  addUserButton = new ButtonItem("addUser", "Add User");      
                  addUserButton.setWidth(80);
                            
                  form.setFields(username, password, loginButton, addUserButton);
                  addChild(form);
                  
                  vlayout.addChild(this);
          	}
          
          	public HasClickHandlers getAddUserButton()
          	{
          		return addUserButton;
          	}
          
          	public HasClickHandlers getLoginButton()
          	{
          		return loginButton;
          	}
          
          	  public String getUserName()
          	  { 
          		  return username.getDisplayValue();  
          	  }
          
          	  public String getPassword()
          	  { 
          		  return password.getDisplayValue();  
          	  }
          	  
          	  public void setErrors(Map errors)
          	  { 
          		  form.setErrors(errors, true);  
          	  }
          
          	public Widget asWidget()
          	{
          		return this;
          	}
          }
          Code:
          package com.sample.client.presenter;
          
          import java.util.HashMap;
          import java.util.Map;
          
          import com.sample.client.event.AddUserEvent;
          import com.sample.client.event.UserLoggedInEvent;
          import com.sample.client.view.LoginScreenView;
          import com.sample.shared.UserDTO;
          import com.google.gwt.core.client.GWT;
          import com.google.gwt.event.shared.HandlerManager;
          import com.google.gwt.user.client.rpc.AsyncCallback;
          import com.google.gwt.user.client.ui.HasWidgets;
          import com.google.gwt.user.client.ui.Widget;
          import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
          import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
          import com.smartgwt.client.widgets.form.fields.events.HasClickHandlers;
          
          public class LoginScreenPresenter implements Presenter
          {  
          	  public interface Display
          	  {
          		  HasClickHandlers getLoginButton();
          		  HasClickHandlers getAddUserButton();
          		  String getUserName();
          		  String getPassword();
          		  Widget asWidget();
          	  }
          	  
          	  private final HandlerManager eventBus;
          	  private final LoginScreenView display;
          	  
          	  
          	  public LoginScreenPresenter(HandlerManager _eventBus, LoginScreenView _view)
          	  {
          	    eventBus = _eventBus;
          	    display = _view;
          	    bind();
          	  }
          	  
          	  public void bind()
          	  {
          		  
          	    display.getLoginButton().addClickHandler(new ClickHandler()
          	    {
          			public void onClick(ClickEvent event)
          			{
          				loginButtonClicked();
          			}
          		});    
          
          	    display.getAddUserButton().addClickHandler(new ClickHandler()
          	    {
          			public void onClick(ClickEvent event)
          			{
          				eventBus.fireEvent(new AddUserEvent());
          			}
          		});
          	  }
          	  
          	  private void loginButtonClicked()
          	  {
          		  eventBus.fireEvent(new UserLoggedInEvent(userDTO));
          	  }
          	  
          	  
          	  public void go(final HasWidgets container) {
          		    container.clear();
          		    container.add(display.asWidget());
          		  }
          }
          The AppController uses the following piece of code to display the LoginPage

          Code:
          loginView = new LoginScreenView();                        
          
          new LoginScreenPresenter(eventBus, loginView).go(container);
          Where container = RootPanel.get();
          Attached Files

          Comment


            #6
            Might want to check out http://forums.smartclient.com/showthread.php?t=7026&highlight=MVP, the entire thread has a lot of points and the second to last post has a working example. I think your current issue is container.add() call though, but I would have to look more at the whole MVP code base.

            Comment

            Working...
            X