D2: Publish an Event or Trigger an action from Custom Dialog

GhenadieS
edited October 24, 2017 in Documentum #1

Hello,

Requirement:

It is required to trigger a dialog from an external widget which will allow to switch the view in a multi view workspace on clicking on OK button. For example: when having Content and Task views, switch to Task view in case the user is on Content view.


Configurations:

We made a dialog which is called by an external custom widget and displayed using Open Ajax Hub in JavaScript sending a message on channel D2_ACTION_DISPLAY_DIALOG. In D2-Configuration we added our external custom widget and assigned him to workspace. Dialog is showed in D2 Client. Now, we need on pressing OK in dialog ( by overriding validDialog() method in Java code) to switch to another view.


Question:

In javascript we can do this publishing a message to the Hub, like this:

<span class="line"><span class="kd" style="color: #b294bb;">var</span> <span class="nx" style="color: #81a2be;">messageToSend</span> <span class="o" style="color: #8abeb7;">=</span> <span class="k" style="color: #b294bb;">new</span> <span class="nx" style="color: #81a2be;">OpenAjaxMessage</span><span class="p">();</span></span><br/><span class="line"> <span class="nx" style="color: #81a2be;">messageToSend</span><span class="p">.</span><span class="nx" style="color: #81a2be;">put</span><span class="p">(</span><span class="s2" style="color: #b5bd68;">"oam_id"</span><span class="p">,</span> <span class="s2" style="color: #b5bd68;">""</span><span class="p">);</span></span><br/><span class="line"> <span class="nx" style="color: #81a2be;">messageToSend</span><span class="p">.</span><span class="nx" style="color: #81a2be;">put</span><span class="p">(</span><span class="s2" style="color: #b5bd68;">"oam_value"</span><span class="p">,</span> <span class="s2" style="color: #b5bd68;">"Tasks"</span><span class="p">);</span></span><br/><span class="line"> <span class="nx" style="color: #81a2be;">d2OpenAjaxHub</span><span class="p">.</span><span class="nx" style="color: #81a2be;">sendMessage</span><span class="p">(</span><span class="s2" style="color: #b5bd68;">"D2_EVENT_VIEW_SWITCHED_MANUAL"</span><span class="p">,</span> <span class="nx" style="color: #81a2be;">messageToSend</span><span class="p">);</span></span>

Any ideas on how we can implement this in the java method validDialog() ?


I have seen that only Widgets objects in java could publish events to the Message Hub, there is any idea how to obtain the current widget from the Context ?

Any ideas are welcomed !

Thank you.

Best Answer

  • GhenadieS
    edited April 13, 2016 #2 Answer ✓

    The solution is very simple an undocumented as usual. From JAVA code the DynamicAction "Publish" could be called to publish an event. Or, the solution we used is to define the dynamic action inside the dialog xml definition as bellow:


    <buttons>
         <button id="buttonOk" type="reset" action="validDialog()">
            <dynamic-action class="com.emc.d2fs.dctm.ui.dynamicactions.events.Publish" event="D2_EVENT_VIEW_SWITCHED_MANUAL" oam_value="Tasks" />
            </button>
            <button id="buttonCancel" type="reset" action="cancelDialog()"/>
           
        </buttons>

Answers

  • Antal Bos
    edited February 11, 2016 #3

    Try this one first:

    Best regards,

    Antal

  • GhenadieS
    edited February 11, 2016 #4

    Hi ,

    Thank for your reply.

    Indeed, the solution we found is to implement a CustomActionManager. We did this, but when trying to call it we get an error. Bellow is the snippet of javascript we are using to publish the message and the error we receive.


    messageToSend = new OpenAjaxMessage();
    messageToSend.put("oam_id", "");
    messageToSend.put("MANAGER","CustomDialogManager");
    messageToSend.put("DIALOG_NAME","CustomDialog");
    messageToSend.put("unread_messages",unread_messages)
    messageToSend.put("DIALOG_LIST_PARAM","unread_messages");
    console.log("MESSAGE TO SEND - >"+messageToSend);
    d2OpenAjaxHub.sendMessage("D2_ACTION_EXECUTE_MANAGER", messageToSend);

    and the error


    Widget DialogWidget for event D2_ACTION_EXECUTE_MANAGER triggered an error during its onReceive() : KO  > The class CustomDialogManager is unknown in the factory ActionManagerFactoryImpl.
    java.lang.IllegalArgumentException: The class CustomDialogManager is unknown in the factory ActionManagerFactoryImpl.

    Seems Javascript doesn't know about this manager, is it required to register somehow this Manager ?

    Thank you.

  • Antal Bos
    edited February 12, 2016 #5

    Check the above post again for my reply.

  • GhenadieS
    edited February 12, 2016 #6

    I checked. We tried like that but with no success.

    Managers are the ones who communicate with events with JavaScript. Seems there is no way, or at least it is not documented how we can extend an IActionManager.

    My scope is to send and EVENT, D2_EVENT_VIEW_SWITCHED_MANUAL, from Java dialog. And I found that IActionManager classes are able to do that. But I'm not able to extend it in a way that D2 recognize it.

    Could you please help with extending an ActionManger or with any other solution I can apply to switch a view.

    Thank you.

  • GhenadieS
    edited April 13, 2016 #7 Answer ✓

    The solution is very simple an undocumented as usual. From JAVA code the DynamicAction "Publish" could be called to publish an event. Or, the solution we used is to define the dynamic action inside the dialog xml definition as bellow:


    <buttons>
         <button id="buttonOk" type="reset" action="validDialog()">
            <dynamic-action class="com.emc.d2fs.dctm.ui.dynamicactions.events.Publish" event="D2_EVENT_VIEW_SWITCHED_MANUAL" oam_value="Tasks" />
            </button>
            <button id="buttonCancel" type="reset" action="cancelDialog()"/>
           
        </buttons>
  • Nicklas.Nordlander
    edited June 14, 2016 #8

    Hi Ghenadie, I have a question. You write that you can publish an event from the dynamic action "publish" in Java, but how do you do this? This might be the wrong way for me to go about this, but I'm trying to trigger the "D2_ACTION_IMPORT_FROM_URL" event for a custom import-dialog.

  • GhenadieS
    edited June 14, 2016 #9

    Hi Nicklas,

    From java I wasn't able to publish an Event or Action, instead it is possible from a custom dialog. As I mentioned above you can publish an Event using buttons and dynamic-actions.


    <button id="buttonOk" type="reset" action="validDialog()"> 
    <dynamic-action class="com.emc.d2fs.dctm.ui.dynamicactions.events.Publish" event="D2_EVENT_VIEW_SWITCHED_MANUAL" oam_value="Tasks" /> 
    </button>

    You can use this action class (com.emc.d2fs.dctm.ui.dynamicactions.events.Publish) or use a specific action for Import.

    Let me know if it worked for you.

  • Nicklas.Nordlander
    edited June 14, 2016 #10

    Hello again,

    yes, I saw your solution above. The issue I was facing with that was that I wanted to supply a upload-url for the oam_value that isn't known before run time. So I was hoping I could set the value and then publish the event from an dialog, but haven't figured out how.

  • GhenadieS
    edited June 15, 2016 #11

    Hello,

    it is clear now.

    I don't know the exact solution but I would check the following:

    1. Add a hidden field on the dialog page and use $value() to  set it on the oam_value
    2. in the validateMethod in the class you can try to obtain the button actions and change the oam_value param value with java code

    Regards.

  • GhenadieS
    edited June 15, 2016 #12

    If the URL value could be calculated runtime before the dialog is displayed you can pass it in the method build dialog:


    publicclass UnreadTasksDialog extends AbstractDialog implements ID2Dialog {
      private static final Logger LOGGER = LoggerFactory.getLogger(UnreadTasksDialog.class);

    @Override
      public XmlNode buildDialog(D2fsContext context, List<Attribute> attributes) throws Exception {
      LOGGER.error("build Dialog" + context.getXmlDialogFile());
      XmlNode configDialog = XmlUtil.loadFromURL(context.getXmlDialogFile()).getRootXmlNode();
      DialogProcessor dialogProcessor = new DialogProcessor(context, configDialog);
      dialogProcessor.setLabelsBundle(context.getDialogBundle());
      Map<String, String> defaultValues = new HashMap<>();
      defaultValues.put("unread_messages", context.getParameterParser().getStringParameter("unread_messages"));
      LOGGER.error("UNREAD MESSAGES " + context.getParameterParser().toString());

      dialogProcessor.setDefaultValues(defaultValues);
      XmlNode dialogNode = dialogProcessor.getDialog();

      return dialogNode;
      }

    @Override
      public XmlNode validDialog(D2fsContext context) throws Exception {
      // TODO Auto-generated method stub
      return super.validDialog(context);
      }


    }

    or in case is required runtime after the dialog is displayed, you can try to execute the action in the method validDialog:


    @Override
      public XmlNode validDialog(D2fsContext context) throws Exception {
      // TODO Auto-generated method stub
      Publish action = new Publish();
      // ....
      return super.validDialog(context);
      }

    Let me know if it worked for you.

  • Nicklas.Nordlander
    edited June 15, 2016 #13

    I'm trying to publish the action in the validDialog-method but no luck so far. I can use your solution to trigger the action but then it doesn't seem to supply the oam_value as I said. I've tried setting the oam_value to the context parameterParser. I've tried creating new Publish() and setting it to the button. I've tried setting it to the returned xmlnode.

  • tejrajs
    edited October 19, 2016 #14

    Hello Nicklas,

    Did you found solution for this?

  • pankaj.pandey
    edited October 24, 2017 #15

    Hi,

    Sorry to wake up closed thread. Were you able to figure out a way to invoke Custom Dialog with Custom Manager?

    Thanks!

  • Someone solved it?
  • kfirswisa said:
    Someone solved it?
    The solution is to publish the event in the dialog XML on OK button, see my comment above: https://forums.opentext.com/forums/developer/discussion/comment/590091/#Comment_590091

  • GhenadieS said:
    kfirswisa said:
    Someone solved it?
    The solution is to publish the event in the dialog XML on OK button, see my comment above: https://forums.opentext.com/forums/developer/discussion/comment/590091/#Comment_590091

    i tried with this:

    <?xml version="1.0" encoding="utf-8"?>
    <dialog id="ConsDialog" width="800" height="480" resizable="true" buttons_right="false">
        <content>
    <tabs>
    <tab id="tabGeneral">
    <fieldset>
    <combo id="cons_factor_list" required="true" empty_option="false" assistance_type="java" assistance_java="com.emc.d2fs.dctm.ui.assistances.ListFormats" />
    </fieldset>
    </tab>
    </tabs>
        </content>
        <buttons>
          <button id="buttonOk" action="validDialog()">
            <dynamic-action class="com.emc.d2fs.dctm.ui.dynamicactions.actions.Generic" eMethod="sendEmailViaOutlook" eMode="MULTI" eService="EmailViaOutlookAction" rAction="eval(result);" rType="JS" />
            </button>
            <button id="buttonCancel" action="cancelDialog()" />
        </buttons>
    </dialog>

    and with this:

    public XmlNode validDialog(D2fsContext context) throws Exception {
    IDfSession session = context.getSession();
    ParameterParser parameterParser = context.getParameterParser();

    MultiResourceBundle bundle = context.getDialogBundle();
    String gorem_meiaech = parameterParser.getStringParameter("gorem_meiaech");
    List<String> gorem_meiaech_users = parameterParser.getListParameter("gorem_meiaech_users");
    if(!checkGroupIsExists(session, gorem_meiaech))
    throw new Exception(bundle.getString(GROUP_NOT_EXISTS_ERROR_KEY));
    String error = checkGroupUsersIsFill(session, bundle, gorem_meiaech, gorem_meiaech_users);
    if(error != null)
    throw new Exception(error);
    (new D2PropertyService()).saveProperties(context);
    return super.validDialog(context);
    }

    and every thing work except the dynamic-action... its not calling
  • any help please?