0

Possible to create and display window from a Java object?

asked 2008-09-30 08:33:14 +0800

Col gravatar image Col
135 1 6

I'd like something like the following to happen:

1) User clicks 'Start' button from start.zul which triggers Start.onStart() function (Start is a Java object)
2) onStart() instantiates a Java Session object
3) Session object replaces start.zul with session.zul (<--- the bit which I'm not sure is possible and difficult to research in forums)

The reason for this is that I need to pass parameters from Start object to Session object. Maybe there is a better way to achieve this? (I could get Session object to request the information from the Start object but that means Session needs to know about Start which is clunky.) Hopefully my explanation is understandable. Thanks for any ideas.

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2008-10-01 12:55:44 +0800

ansancle gravatar image ansancle
317 9

Not sure what you are trying to do exactly but you can do the following :

start.zul :

<window apply="com.foo.StartComposer">
   <button id="startButton"/>
</window>

Then in java code you create the StartComposer class which extends the GenericForwardComposer abstract base class :

public class StartComposer extends GenericForwardComposer
{


  // In here you define the following method which will get called every time the user clicks the startButton
  
     public void onClick$startButton(Event event)
     {
                // In here you create whatever objects you want, you can get access to ZK session 
                // with the following code :
                Session zkSession = event.getTarget().getDesktop().getSession();
                // Now you can put anything into or out of the ZK session you like or your java objects you create
                // If you want to then have the user go to a new .zul page, use the following code
               Executions.sendRedirect("/session.zul");
      }

}


For a further explanation of the Composer and how it works etc.. go to : http://www.zkoss.org/smalltalks/mvc3/
Read through the entire thing, but the technique I show above is described in the section titled : 'Get Rid of Those "forward" Attributes'

link publish delete flag offensive edit

answered 2008-10-20 22:23:29 +0800

Col gravatar image Col
135 1 6

Thanks for the reply ansancle. I've been sidetracked onto other projects recently and am finally getting time to get back to this. You're explanation makes sense but the final piece of the puzzle is how to server push information back to session.zul.

To elaborate:
I have RFID readers networked to talk to an RfidListener class on the server. Data is retrieved from a database using the rfid number as the key. This information needs to go back to the appropriate session.zul page. How do I achieve that?

link publish delete flag offensive edit

answered 2008-10-21 06:18:21 +0800

hkn gravatar image hkn
246 3

Hello,

to display data retrieved from a database simply use databinding which now is quite easy to use with the new GenericForwardComposer. Please see http://www.zkoss.org/smalltalks/mvc3/

If you like to update an open browser window showing your session.zul with new data automatic you may should use the ServerPush. There are some good examples here

http://www.zkoss.org/doc/devguide-single/index.html#id455525

/Horst

link publish delete flag offensive edit

answered 2008-10-21 11:32:26 +0800

Col gravatar image Col
135 1 6

Thanks Horst but I think you have misunderstood my problem.

I have one RfidListener on the server listening on a port for tag numbers. However I have many workstations with rfid readers. The only way I know which reader has sent a tag number is via it's ip address. Somehow I need to 'connect' that reader/ip address with the zul page to server push the returned information.

Eg:
server = 1.2.3.1

work station 1 = 1.2.3.2
rfid reader 1 = 1.2.3.3

work station 2 = 1.2.3.4
rfid reader 2 = 1.2.3.5

etc

When I receive an rfid number from reader 1 how do I send the information back to work station 1?

Here's my plan at the moment.

RfidListener.java

public class RfidListener {
    // creates thread to listen to port number 8888
    // when an rfid number is received query the database with rfid number as key
    // update <see Start.java below> with ip address and returned database result
}

start.zul

<window id="startwin" apply="Start">
<button id="startButton" label="Click to start reader"/>
</window>

Start.java

public class Start extends GenericForwardComposer {
	public void onClick$startButton(Event event) {
              // create (new?) window with grid to display database result data
              // how do I create this so that RfidListener knows who to send the database result to?
	}
}

Hopefully this makes sense and maybe I'm approaching the problem from the wrong angle and missing an obvious solution but I'm open to any suggestions. If you need clarification on any of the above just ask. Thanks.

link publish delete flag offensive edit

answered 2008-10-21 13:24:07 +0800

hkn gravatar image hkn
246 3

Hello!

First of all that has nothing to do with ZK, it is more a question of software architecture, but anyhow ;-)

Well "Somehow I need to 'connect' that reader/ip address with the zul page to server push the returned information." means address the rfid message to the correct (tomcat/zk) session. So your RfidListener has to run independent and writes the data to a database or to an application bean (not a session bean!) maybe add a timestamp or whatever.
(About session or application bean and how to address them in a servlet container see tomcat servlet samples, but storing to a sql database is easier)

Your Start class needs an onCreate$startwin to create a new (independent) thread, which periodically looks for new data in the database (maybe every second or so) and uses server push to update the information in your window. How to do that read http://www.zkoss.org/doc/devguide-single/index.html#id455525

Because this is done for each session you can select the correct data from the database by the clients ip address: Executions.getCurrent().getRemoteAddr()


/Horst

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-09-30 08:33:14 +0800

Seen: 287 times

Last updated: Oct 21 '08

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