Announcement

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

    How to trigger custom code from recordClick events defined in ComponentXML

    Hi,

    How to trigger custom code (in Java) on RecordClick without using Java code (i.e. just from XML?) to define the trigger?

    There is an event Editor in Visual Builder that allows to trigger some built in Events (like fetchData), which creates XML like this:
    Code:
    <ListGrid dataSource="ref:SomeBean" ID="SomeBeanGrid" autoDraw="false">
        <fields>
            <ListGridField name="id" title="Id"/>
            <ListGridField name="anotherBeanId" title="Another Bean Id"/>
            <ListGridField name="aProperty" title="A Property"/>
            <ListGridField name="anotherBean" title="AnotherBean"/>
        </fields>
        <showFilterEditor>true</showFilterEditor>
        <recordClick>
                <Action>
                    <target>SomeBeanGrid</target>
                    <name>startEditing</name>
                    <title>Start Editing</title>
                </Action>
        </recordClick>
    </ListGrid>
    but I have no idea how to alter this to call Java/GWT code.

    Another option I could think of to accomplish the desired behavior would be to add implementations of RecordClickHandler (defined as class in Java) to the ListGrid (as it is done in Java code using addRecordClickHander()). However, how to do it (using a proper syntax) remains hidden to me as it seems to be documented (or showcased) nowhere.

    1. SmartClient Version: v8.3p_2013-04-24/PowerEdition Deployment (built 2013-04-24)

    2. FF 20.0.1 (dev and deployment mode), Chrome Version 26.0.1410.64 m, IE 10.0.9200.16540 (all on Windows 8)

    Regards,
    fatzopilot

    #2
    Just use Canvas.getById() to get the ListGrid then add the handler as normal. There's no special syntax. There are examples in the 4.0 Showcase.

    Comment


      #3
      Hi,

      Originally posted by Isomorphic View Post
      Just use Canvas.getById() to get the ListGrid then add the handler as normal. There's no special syntax. There are examples in the 4.0 Showcase.
      Sorry, I don't want to do this in Java but point to the code to be executed on RecordClick (written in Java/GWT) from within the ComponentXML.

      Thanks,
      fatzopilot

      Comment


        #4
        4.0 has the ability to declare, via the constructor attribute, that you want a specific Java subclass of ListGrid used when creating your <ListGrid>, and that subclass could have a RecordClick handler already installed. Is that the kind of thing you had in mind?

        This also is shown in the Showcase, just be aware, there are still a couple of known bugs with this particular feature (it's basically Java reflection for GWT), but they only affect development mode, not compiled mode.

        Comment


          #5
          Originally posted by Isomorphic View Post
          4.0 has the ability to declare, via the constructor attribute, that you want a specific Java subclass of ListGrid used when creating your <ListGrid>, and that subclass could have a RecordClick handler already installed. Is that the kind of thing you had in mind?
          Yeah, something like this. Unfortunately, I cannot resort to 4.0 at the moment.

          Originally posted by Isomorphic View Post
          Just use Canvas.getById() to get the ListGrid then add the handler as normal. There's no special syntax. There are examples in the 4.0 Showcase.
          I tried this as follows (Portal.ui.xml):
          Code:
          <IButton ID="AButton" width="100" autoDraw="true">
              <title>Console</title>
              <icon>[SKIN]/DynamicForm/text_control.gif</icon>
          </IButton>
          
          <PortalLayout ID="PortalLayout0" autoDraw="false">
              <portalColumns>
                  <PortalColumn>
                      <autoDraw>false</autoDraw>
                      <ID>PortalColumn0</ID>
                  </PortalColumn>
              </portalColumns>
          </PortalLayout>
          
          
          <TabSet ID="PortalTabSet" autoDraw="true" width="100%" height="100%" tabBarAlign="left">
              <tabs>
                  <Tab title="Tab0" canClose="true">
                      <pane><Canvas ref="PortalLayout0"/></pane>
                      <ID>Tab0</ID>
                  </Tab>
              </tabs>
              <tabBarControls>
                  <value>tabScroller</value>
                  <value>tabPicker</value>
                  <value>AButton</value>
              </tabBarControls>
          
              <canReorderTabs>true</canReorderTabs>
              <canCloseTabs>true</canCloseTabs>
              <destroyPanes>false</destroyPanes>
              <layoutAlign>right</layoutAlign>
          </TabSet>
          
          
          <DataView ID="PortalDataView" width="100%" height="100%" overflow="hidden" autoDraw="true">
              <members><Canvas ref="PortalTabSet"/>
              </members>
              <modulesDir>modules/</modulesDir>
          </DataView>
          Code:
          public class Scaffolding implements EntryPoint {
          	@Override
          	public void onModuleLoad() {
          		
          		RPCManager.loadScreen("Portal", new LoadScreenCallback() {
          			
          			@Override
          			public void execute() {
          				IButton aButton = (IButton) Canvas.getById("AButton");
          				if(aButton != null){
          					SC.say("Got the button");
          				}
          				aButton.addClickHandler(new ClickHandler() {
          			         public void onClick(ClickEvent event) {
          			        	 SC.say("Clicked the button");
          			         }
          			    });
          			}
          		});
                       }
          }
          The click handler is never triggered (neither in dev nor prod mode). Building everything in Java works as expected.

          The layout as observed through the watch tab of the dev console also looks weird to me, it seems, the screen has been loaded twice and the second instance is covering the first one...

          v8.3p_2013-04-28/PowerEdition Deployment (built 2013-04-28)
          Attached Files
          Last edited by fatzopilot; 2 May 2013, 10:42.

          Comment


            #6
            You're calling loadScreen() without specifying that anything should become global. This suggests your callback code is simply crashing with an NPE (because "AButton" would not be found and null would be returned).

            Be sure to watch the console to see things like this.

            Comment


              #7
              No, there is no NPE, the "Got the button" actually pops up.

              However, using
              Code:
              RPCManager.loadScreen("Portal", new LoadScreenCallback() {...}, new String[]{"AButton"});
              solves the original issue, thanks for the pointer!

              Just for the record: The watchTab shows a slightly different setup now, and there a warnings like:
              "[ERROR] - 23:31:19.870:XRP9:WARN:Log:ClassFactory.addGlobalID: ID:'aButton' for object '[IButton ID:aButton]' collides with ID of existing object '[IButton ID:aButton]'. The pre-existing widget will be destroyed." in debug mode.
              Attached Files
              Last edited by fatzopilot; 2 May 2013, 13:34.

              Comment


                #8
                Just to clear some things up:
                The screen has actually been loaded twice, one time using the screenLoader script, the other time using loadScreen.
                I originally included the screenLoader script thinking the screen loading mechanism works the same was as that of the Datasources.

                Comment


                  #9
                  It works similarly (as covered in the Component XML docs), however loading a screen *both* ways will predictably cause the screen to clobber each other's global widgets (as you've seen).

                  Comment

                  Working...
                  X