0

Windows and inter-application communication [closed]

asked 2017-03-10 12:56:38 +0800

pocca gravatar image pocca
1

Hi everybody!

I'm new here so, first of all, thanks community for sharing solutions, tips&tricks and workarounds! I always found something useful for me around this forum. ;)

I've different web applications (we call them appA, appB, appC, appD) that manage different aspects. The appD is a app for consultation and it has a zul page that allows to examine item information and surf through several tabs. The zul page is connected to a viewmodel, that calls web services and take all the information. When I'm in one of the apps (AppA, AppB, AppC) and there's a list of items, I would like to be able to open (like a popup window) that zul page of the appD, passing the id of the selected item.

I read the documentation about Inter-Application Communication, but I'm able to view the window, only if it's not connected to any viewmodel.

This is something like I did:

In the AppA:

// showListItems.zul

<zk>
    <window id="main" apply="org.zkoss.bind.BindComposer" 
            viewModel="@id('vm') @init('viewmodel.showListItemsViewModel')" >
        ......

        <window title="ALL ITEM INFORMATION"  id="myItemDetailWindow" 
                            width="95%" height="95%" visible="false"
                            border="normal" position="center" closable="true" 
                            onClose="myItemDetailWindow.setSrc(null); self.visible = false; event.stopPropagation();" 
                            contentStyle="overflow:auto" sizable="true" >
                        <include  id="innerItemDetail"  />
        </window>
      .....
      <listbox  checkmark="true" rows="10"  model="@bind(vm.myListItems)"   emptyMessage="No items found" selectedItem="@bind(vm.mySelectedItem)" onDoubleClick="@command('showItemWindow')"> 
           <listhead sizable="true">
              <listheader width="5%"  />
              <listheader label="Id Item" width="20%" />
              <listheader label="Descr. Item" width="75%" />
           </listhead>
           <template name="model" >
              <listitem >
                 <listcell />
                 <listcell label="@bind(each.myIdItem)"/> 
                 <listcell label="@bind(each.myDescrItem)"/> 
              </listitem>
           </template>
       </listbox>
  ..........
  </window>
</zk>

// showListItemsViewModel.java

package viewmodel;
public class showListItemsViewModel{
   private List<MyItem> myListItems;
   private MyItem mySelectedItem;
   //....

   public showListItemsViewModel() {
      myListItems = getItemsByFilter(...)
      //...
   }

   @AfterCompose
   public void initSetup(@ContextParam(ContextType.VIEW) Component view) throws InterruptedException {
        Selectors.wireComponents(view, this, false);
        innerItemDetail = (Include) myItemDetailWindow.getFellow("innerItemDetail");
   }

  @Command
  public void showItemWindow() {
     if (mySelectedItem != null) {
        try{
           //  post message to send the selected item id to the other application       
           HttpClient client = HttpClientBuilder.create().build();
           HttpPost post = new HttpPost(http://" + host + ":8080/AppD/surfOnItemDetail.zul);
           List<NameValuePair> arguments = new ArrayList<>();
           arguments.add(new BasicNameValuePair("idSelectedItem", String.valueOf(mySelectedItem.getId())));
           post.setEntity(new UrlEncodedFormEntity(arguments));
           HttpResponse response = client.execute(post);
        } catch (IOException e) {
             e.printStackTrace();
        }
        innerItemDetail.setSrc("~AppD/surfOnItemDetail.zul");
        myItemDetailWindow.doHighlighted();
     }
     else
       Messagebox.show("No item selected");
 }                               

 //...

}

In the AppD:

// surfOnItemDetail.zul

<zk>
   <window id="itemWin"  apply="org.zkoss.bind.BindComposer" 
            viewModel="@id('vmi') @init('viewmodel.consult.surfOnItemDetailViewModel')" >
      .....
      <label value="ITEM REPORT - TEST" />
      <image src="~AppD/images/generalItemIcon.png" />
      <tabbox  orient="vertical" >
          <tabs width="15%" sclass="myTabsItem">
             ....
          </tabs>
          <tabpanels >
            ...
          </tabpanels>
      </tabbox>
   </window>
</zk>

// surfOnItemDetailViewModel.java

package viewmodel.consult;
public class surfOnItemDetailViewModel{
  //....

  public surfOnItemDetailViewModel() {
     System.out.println("I'm in surfOnItemDetailViewModel");
     // retrieve selected item id from HttpServletRequest
     // web service calls..
  }
}

If I had in surfOnItemDetail.zul

<zk>
   <window id="itemWin">
      <label value="something" />
      <image src="~AppD/images/generalItemIcon.png" />
   </window>
</zk>

the appA would be able to show me the window in surfOnItemDetail.zul with label and image.

But if I add the attribute viewModel="@id('vmi') @init('viewmodel.consult.surfOnItemDetailViewModel')" at the window, it doesn't work, because it doesn't looks for the java file into appD source directory..

Is it possible to do what I'm trying to? Any suggestion to do it?

Thanks!

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by cor3000
close date 2017-03-22 03:04:30

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-03-14 03:10:54 +0800

MDuchemin gravatar image MDuchemin
2535 1 6
ZK Team

Hi Pocca, Welcome on the forum!

But if I add the attribute viewModel="@id('vmi') @init('viewmodel.consult.surfOnItemDetailViewModel')" at the window, it doesn't work, because it doesn't looks for the java file into appD source directory..

From your description, this makes sense. The ViewModel from appD isn't available in appA, so appA cannot instantiate it.

From your description, I understand 2 possible things you might be trying to do: 1 - Are you trying to "embed" a screen from appD in an appA page? 2 - Are you trying to use the same code between 2 different, non-intersecting applications?

Assuming you are trying to insert a screen from appD in appA, the current approach isn't going to work. The simplest scenario to do this would be to use iframes and url parameters.

in appA:

<iframe src="@load(vm.myUri)"></iframe>

Where vm.myUri is a string looking like ~appD/mypage.zul?myparam=myvalue

and in appD, use mvvm to retrieve the URI parameter in the target page in the viewmodel used in mypage.zul:

http://books.zkoss.org/zk-mvvm-book/8.0/syntax/queryparam.html

This will let you retrieve the value from the iframe parameters I made a quick fiddle here to illustrate how this works:

http://zkfiddle.org/sample/3aritru/1-pass-args-through-iframe-params

Have a look, and good coding!

link publish delete flag offensive edit
0

answered 2017-03-15 12:41:05 +0800

pocca gravatar image pocca
1

Sorry for my late replay, but I worked on another project in the meantime.. I've just had the time to try your suggestion and.. It works! Thanks a lot, MDuchemin! :)

[For completeness I'll write the changes I made:

In the AppA, in file showListItems.zul I just replaced <include id="innerItemDetail" /> with the component <iframe id="frameItemDetail" />.

In showListItemsViewModel.java I made the consequent changes:

package viewmodel;
public class showListItemsViewModel{
   //...

   public showListItemsViewModel() {
      //...
   }

   @AfterCompose
   public void initSetup(@ContextParam(ContextType.VIEW) Component view) throws InterruptedException {
        //....
        frameItemDetail = (Iframe) myItemDetailWindow.getFellow("frameItemDetail");
   }

  @Command
  public void showItemWindow() {
     if (mySelectedItem != null) {
        try{
           //  post message to send the selected item id to the other application       
           // ... 
        } catch (IOException e) {
             e.printStackTrace();
        }
        frameItemDetail.setSrc("~AppD/surfOnItemDetail.zul");
        myItemDetailWindow.doHighlighted();
     }
     // ...
 }                               
// ...
}

In the AppD, in surfOnItemDetail.zul

<window id="itemWin" title="Item Detail" apply="org.zkoss.bind.BindComposer" 
         viewModel="@id('vmi') @init('viewmodel.consult.surfOnItemDetailViewModel')">
    <label value="@bind(vmi.something)" />   
    <label value="something" />
    <image src="~AppD/images/generalItemIcon.png" />     
</window>

and it works fine! ]

link publish delete flag offensive edit

Question tools

Follow
1 follower

RSS

Stats

Asked: 2017-03-10 12:56:38 +0800

Seen: 46 times

Last updated: Mar 15 '17

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More