1. #1
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    139
    Vote Rating
    4
    jvahabzadeh is on a distinguished road

      0  

    Default Unanswered: Trying the Appearance Design Pattern - what am I doing wrong?

    Unanswered: Trying the Appearance Design Pattern - what am I doing wrong?


    All,

    Ok, so I've NEVER dealt with the Appearance Design Pattern before - in GXT or in GWT. I'm reasonably new to GWT as it is, and newer still to GXT, having dealt only with GXT 3.0 DP5 and GXT 3.0 Beta 1.

    So, I've taken a look at the Appearance Design Pattern article, and tried to, well, try it out. However, this throws an exception when I try to run it, and I have no idea whatsoever what I'm doing wrong. Can anyone point me in the right direction? I really want to try this and learn it!

    I am using Eclipse as a development environment.

    My classes all exist in package com.joev.gwttests.client

    I created an AppearancePushButton class that consists of the AppearancePushButton code (near the bottom of the article), and includes the Appearance interface and DefaultAppearance implementation of it, as provided in the article.

    I also put in a simplified version of the Appearance-substitution code in the project's gwt.xml file. After all the inherits, but before the entry point info, I put:
    HTML Code:
      <replace-with class="AppearancePushButton.DefaultAppearance">
        <when-type-is class="AppearancePushButton.Appearance"/>
      </replace-with>
    In the same package, I created the DefaultAppearance.html and DefaultAppearance.css files, though I had to modify the latter slightly - it appears that the ".testButton .testImage" line is really supposed to read ".testButtonImage"

    I then created a VERY short bit of code that implements EntryPoint just to see what the button would look like:

    My entry point code:
    PHP Code:
      public void onModuleLoad() {
        
    RootPanel.get().add(new AppearancePushButton("My appearance pushbutton"));
      } 


    The exception is as follows (note that my EntryPoint class is called GWT3BetaTest1):
    Code:
    11:43:57.115 [ERROR] [gwt3betatest1] Failed to create an instance of 'com.joev.gwttests.client.AppearancePushButton$DefaultAppearance' via deferred binding 
    
    java.lang.RuntimeException: Deferred binding failed for 'com.joev.gwttests.client.AppearancePushButton$DefaultAppearance$Template' (did you forget to inherit a required module?)
        at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
        at com.google.gwt.core.client.GWT.create(GWT.java:97)
        at com.joev.gwttests.client.AppearancePushButton$DefaultAppearance.<init>(AppearancePushButton.java:63)
        at com.joev.gwttests.client.AppearancePushButton$DefaultAppearance.<init>(AppearancePushButton.java:56)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:465)
        at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
        at com.google.gwt.core.client.GWT.create(GWT.java:97)
        at com.joev.gwttests.client.AppearancePushButton.<init>(AppearancePushButton.java:85)
        at com.joev.gwttests.client.GWT3BetaTest1.onModuleLoad(GWT3BetaTest1.java:9)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
        at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
        at java.lang.Thread.run(Thread.java:662)
    Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
        at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:595)
        at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:455)
        at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
        at com.google.gwt.core.client.GWT.create(GWT.java:97)
        at com.joev.gwttests.client.AppearancePushButton$DefaultAppearance.<init>(AppearancePushButton.java:63)
        at com.joev.gwttests.client.AppearancePushButton$DefaultAppearance.<init>(AppearancePushButton.java:56)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:465)
        at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
        at com.google.gwt.core.client.GWT.create(GWT.java:97)
        at com.joev.gwttests.client.AppearancePushButton.<init>(AppearancePushButton.java:85)
        at com.joev.gwttests.client.GWT3BetaTest1.onModuleLoad(GWT3BetaTest1.java:9)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
        at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
        at java.lang.Thread.run(Thread.java:662)

    My DefaultAppearance.css file:
    Code:
    .testButton {
      border: 1px solid navy;
      font-size: 12px;
      padding: 4px;
    }
     
    .testButtonImage {
      float: left;
    }
     
    .testButtonText {
      text-align: center;
    }
    My DefaultAppearance.html file (copied straight from the article):
    HTML Code:
    <div class="{style.testButton}">
        <div class="{style.testImage}"></div>
        <div class="{style.testText}"></div>
    </div>
    My AppearancePushButton.java file (copied from the article, including the Appearance interface and implementation parts)
    PHP Code:
    public class AppearancePushButton extends Component implements HasClickHandlers {
      private final 
    Appearance appearance;

      public interface 
    Appearance {
        
    void render(SafeHtmlBuilder sb);

        
    void onUpdateText(XElement parentString text);

        
    void onUpdateIcon(XElement parentImage icon);
      }

      public static class 
    DefaultAppearance implements Appearance {

        public interface 
    Template extends XTemplates {
          @
    XTemplate(source "DefaultAppearance.html")
          
    SafeHtml template(Style style);
        }

        public interface 
    Style extends CssResource {

          
    String testButton();

          
    String testButtonText();

          
    String testButtonImage();
        }

        private final 
    Style style;
        private final 
    Template template;

        public interface 
    Resources extends ClientBundle {

          @
    Source("DefaultAppearance.css")
          
    Style style();
        }

        public 
    DefaultAppearance() {
          
    this((Resources)GWT.create(Resources.class));
        }

        public 
    DefaultAppearance(Resources resources) {
          
    this.style resources.style();
          
    this.style.ensureInjected();

          
    this.template GWT.create(Template.class);
        }

        @
    Override
        
    public void onUpdateIcon(XElement parentImage icon) {
          
    XElement element parent.selectNode("." style.testButtonImage());
          
    element.removeChildren();
          
    element.appendChild(icon.getElement());
        }

        @
    Override
        
    public void onUpdateText(XElement parentString text) {
          
    parent.selectNode("." style.testButtonText()).setInnerText(text);
        }

        @
    Override
        
    public void render(SafeHtmlBuilder sb) {
          
    sb.append(template.template(style));
        }
      }

      public 
    AppearancePushButton(String text) {
        
    this(text, (Appearance)GWT.create(DefaultAppearance.class));
      }

      public 
    AppearancePushButton(String textAppearance appearance) {
        
    this.appearance appearance;

        
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
        
    this.appearance.render(sb);

        
    setElement(XDOM.create(sb.toSafeHtml()));
        
    setText(text);
        
    sinkEvents(Event.ONCLICK);
      }

      @
    Override
      
    public HandlerRegistration addClickHandler(ClickHandler handler) {
        return 
    addDomHandler(handlerClickEvent.getType());
      }

      public 
    void setText(String text) {
        
    appearance.onUpdateText(getElement(), text);
      }

      public 
    void setImage(Image icon) {
        
    appearance.onUpdateIcon(getElement(), icon);
      }


  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,640
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    The error message indicates that GWT is unable to figure out how to rebind your Template interface. Since that extends XTemplates, the rebind rule in com.sencha.gxt.core.Core should take care of this:

    Code:
      <generate-with class="com.sencha.gxt.core.rebind.XTemplatesGenerator">
        <when-type-assignable class="com.sencha.gxt.core.client.XTemplates" />
      </generate-with>
    The fact that it is not doing so suggests that either an inherits statement is missing in your module file - can you post that file? If you were missing an inherits for Core or GXT though, you shouldn't even be able to subclass Component, or use XElement...

    Can you also post a full gwt compile log? Sanitize where necessary, but I suspect there is some other error or warning that may shed some light on this.

    With the exception of the error, I think you've got the right idea - have you tried making alternate appearances for gxt components?

  3. #3
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    139
    Vote Rating
    4
    jvahabzadeh is on a distinguished road

      0  

    Default


    Here is my module file:
    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <module rename-to='gwt3betatest1'>
      <inherits name='com.sencha.gxt.ui.GXT'/>
      <inherits name='com.google.gwt.user.User'/>
      <inherits name='com.google.gwt.user.theme.clean.Clean'/>
    
      <!-- Bind the default ButtonCell.Appearance. -->
      <replace-with class="AppearancePushButton.DefaultAppearance">
        <when-type-is class="AppearancePushButton.Appearance"/>
      </replace-with>
    
      <entry-point class='com.joev.gwttests.client.GWT3BetaTest1'/>
      <source path='client'/>
      <source path='shared'/>
    </module>

    I just have the inherits for com.sencha.gxt.ui.GXT . . but that inherits all modules, so I think I'm good there.

    As to the build log, where is it? I'm building via Eclipse, and running in development mode. I thought maybe it was in ${projectname}/.gwt/.gwt-log, so I cleared that file and did a clean and build, but after the build, the .gwt-log file was still empty.

  4. #4
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,640
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    Clean shouldn't be necessaryunless you are actually using it (from some other GWT widget), and I would place GXT after User.

    Is the class in the replace-with correct? Shouldn't there be a package to go with it? Something like

    Code:
      <replace-with class="com.joev.gwttests.client.AppearancePushButton.DefaultAppearance">
         <when-type-is class="com.joev.gwttests.client.AppearancePushButton.Appearance"/>   
    </replace-with>

  5. #5
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    139
    Vote Rating
    4
    jvahabzadeh is on a distinguished road

      0  

    Default


    I had gotten the impression that the fully-qualified name wasn't necessary from the Appearance Design Pattern article on the Sencha blogs... at the bottom with the PushButton references.

    I tried putting in the fully qualified names in for replace-with, and I also switched the order of inherits for GXT and User... still the same issue.

    Where is the gwt compile log file located?

  6. #6
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,640
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    When you run the 'GWT Compile' within eclipse, it should be printed to the Console view, still in eclipse. If you use maven or ant, the output of those commands is the log.

    Like I said, everything else looks correct, so I'll try with your code to build a sample project, see if I get the same issue. The log will help to see what other setup or config option might be stopping this from building correctly.

  7. #7
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    139
    Vote Rating
    4
    jvahabzadeh is on a distinguished road

      0  

    Default


    Colin,

    Thanks - let me know your results.

    As to the compile log, all I get is the following, if it's of any help:
    DataNucleus Enhancer (version 1.1.4) : Enhancement of classes
    DataNucleus Enhancer completed with success for 0 classes. Timings : input=45 ms, enhance=0 ms, total=45 ms. Consult the log for full details
    DataNucleus Enhancer completed and no classes were enhanced. Consult the log for full details

  8. #8
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,640
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    That log appears to be the messages emitted by eclipse as it generates classes to work with the Google App Engine and it's data store. When in the Console, make sure you have the GWT compile log opened - there is a blue monitor icon on the right side of the Console view that lets you switch between all of the active consoles. With the console open, run the GWT compile, and use the blue icon's menu to find the correct log.

    It should include at least the error message you posted above, and hopefully more errors as well.

  9. #9
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    139
    Vote Rating
    4
    jvahabzadeh is on a distinguished road

      0  

    Default


    Unfortunately, that is the only console I get.

    I know what you mean about the blue monitor icon, I usually use that when I am running more than one program that dumps info to the console . . but when I compile the code we've been talking about in this thread, I only have just the one console - that displays the DataNucleus information I quoted in my previous post.

  10. #10
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,640
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    That's interesting/annoying...

    Here is what I get when clicking the red toolbox 'GWT Compile Project...' button in my Console view:
    Code:
    Compiling module com.example.Appearance_sample
       Scanning for additional dependencies: file:/home/colin/workspaces/sencha/appearance-sample/src/com/example/client/AppearancePushButton.java
          Computing all possible rebind results for 'com.example.client.AppearancePushButton.DefaultAppearance.Template'
             Rebinding com.example.client.AppearancePushButton.DefaultAppearance.Template
                Invoking generator com.sencha.gxt.core.rebind.XTemplatesGenerator
                   Creating XTemplate method template
                      Running class com.sencha.gxt.data.rebind.ValueProviderCreator
                         [WARN] Method getTestImage could not be found
                         [ERROR] No getter can be found, unable to proceed
          [WARN] For the following type(s), generated source was never committed (did you forget to call commit()?)
             [WARN] com.example.client.AppearancePushButton_DefaultAppearance_Style_testImage_ValueProviderImpl
             [WARN] com.example.client.AppearancePushButton_DefaultAppearance_TemplateImpl
       [ERROR] Errors in 'file:/home/colin/workspaces/sencha/appearance-sample/src/com/example/client/AppearancePushButton.java'
          [ERROR] Line 63:  Failed to resolve 'com.example.client.AppearancePushButton.DefaultAppearance.Template' via deferred binding
       [ERROR] Cannot proceed due to previous errors
    Notice the earlier error from the one you posted - the template can't compile correctly. Your template tries to use style.testImage, but there is no method called testImage (or getTestImage) in your Style, so compilation fails.

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