Question

I am trying to pass an object from one zul page to another. where :

  1. Both zul pages have own composers.
  2. I want to set value of object in 1st zul's composer.
  3. And Want to get it in 2nd zul's composer.

I have tried executions.sendredirect(), but it clears the value of object, forward() thrwos an exception saying that "use sendRedirect instead to process user request".

Was it helpful?

Solution

Your problem is scope.

In ZK, like other web application frameworks, you have access to a number of different scopes: webapp, desktop, page, session, request, etc. If you have two different pages served from two different URLs, those will have distinct request scopes.

When moving from one request to another, you can pass information on the request URL:

Executions.sendRedirect("page2.zul?myId=1234")

Then, in the composer on page2, you can retrieve this value from the Execution:

Execution execution = Executions.getCurrent();
execution.getParameter("myId");

This is standard HTTP query string business so you're limited to text and numbers here. For passing things like database ids though, this can be quite convenient.

A more robust solution might be to leverage some of ZK's other scopes. For example, you could put your object in the user's Session scope. Refer to my answer to ZK session variable with a menu for implementation details. Note that when using the Session, you are no longer limited to text but can store an actual Object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top