Question
· Dec 15, 2016

ZEN Class property 'list of Objects' on client (empty) on server (filled)

Hi,

I have a ZEN page class with the following annotation. What I try to accomplish is to display data from Object of Type MyPckg.Message. Each Message shall be displayed in a component of type <html>. The outline is somekind the following.

1) Call Method GetMessages() from client
1.1) Method GetMessages fills in my Zenpage property Messages (via insert)
1.2) returns to the client "I am ready"

2) Client invokes Callback method DrawMessages (referenced in OnDrawContent Property) on the html component via refreshContents();
2.1) The server side method DrawMessages is invoked
2.2) Test the Number of objects in ..Messages
2.3) for each one write out the desired html

My problem is, once I invoke the refreshContents() client goes to server and try to iterate the objectes contained in ..Messages but finds none and therefore display nothing.

Class MyPckg.MyClass Extends  %ZEN.Component.page [ Final ] {

Property Messages As list Of MyPckg.Message;

/// Definition of the message pane which contains the messages
XData messagePane [ XMLNamespace = "http://www.intersystems.com/zen" ]
{
<pane xmlns="http://www.intersystems.com/zen">
  <html id="messages" enclosingClass="messageView" OnDrawContent="DrawMessages" />
</pane>
}

/// start search
ClientMethod performSearch() [ Language = javascript ]
{
  // perform search
  var result = zenPage.GetMessages();
  zen('messages').refreshContents();
  return true;
}

Method GetMessages() As %Status[ ZenMethod ] {

  // 1. fill in ..Messages
  // messages found and pushed to ..Messages
  // got n messages

  Quit tStatus

}

/// Display the messages
Method DrawMessages(pSeed As %String) As %Status
{
  If $IsObject(..Messages) {

    // a ..Messages.Count() --> 0
    For tIdx=1:1:..Messages.Count() {
      &html<#(..Messages.GetAt(tIdx).content)#<br />> 
    }
  } else {
  }
  Quit $$$OK
}

}

Has anyone an idea why this doesn´t work? Could it be a timing problem? I call the GetMessage Method synchronous. Any help will be highly appreciated.

best regards,

sebastian

Discussion (3)1
Log in or sign up to continue

hi,

just to bring it back up. I tried different ways to solve my problem but couldn´t figure out a way to have the property 'Messages' be filled with objects of type Message once the client side component invoke it´s refreshContents(). The server method invoked still indicate that 'Messages' has zero elements.

Does anyone have an idea on how to tackle that issue?

best regards,

Sebastian

Hi Sebastian,

If you add an  onloadHandler() method (which gets called when the page is first loaded), this method could call to the GetMessages class method to load your page property named Messages with the message content you want displayed on the page.  Then, a little later in the ZEN page creation processing when the server processing renders the ZEN page components, the <html> component will call to the DrawMessages method to load the message data on the page.

Hope this helps and Have a Great Day!!!

John

Hi John,

this is exactly what I want to do. But I call the GetMessageList(...) a little later once the user completed a search form. GetMessageList(...) get the data requested and Insert the Objects of type MyPckg.Message into the page property Messages. ´Server gets back to the client tells "i am finished" and the client invokes the DrawMessages(...) method. But this method tells that the list of messages in page property Message has count 0 - so no messages to display. I am not able to figure out why cause the GetMessages(...) report that n message objects have been inserted to page property Messages.

best regards,

sebastian