Frage

I'm newbie with zk6 framework. I created a view model class where i'm trying to navigate from one zul and load some data in another one:

public class SearchVM {
@Command
@NotifyChange({ "searchBean","slides" })
public void doSearch() {
        //load data (slides) from data base
        //navigate to another zul where i display my data
    }

}

The data is displayed if i stay in the same zul but i get nothing if i navigate to another one. i tried to use Executions.sendRedirect("/result.zul") with no sucess.

War es hilfreich?

Lösung

Don't do a browser redirect. Show the results using AJAX.

So in the following a single zul file has two zones, once is hidden by default. When you click the button it hides the first zone and shows the second.

<zk>
<zscript>
boolean showFirstZone = true; 
</zscript>
<window visible="${showFirstZone}" id="firstZoneWindow">
    This is first zone. 

    <include src="/WEB-INF/search/search-input.zul"/>

    <button label="Switch To Results" onClick="secondZoneWindow.visible=true;firstZoneWindow.visible=false;" />

</window>

<window visible="${!showFirstZone}" id="secondZoneWindow" >
   This is second zone. 

   <include src="/WEB-INF/search/search-result.zul"/>

</window>
</zk>

Notice that I put the included zul files under /WEB-INF so that they are not accessible from the browser which is a good idea. That way only the entry pages which define the desktops of the system are in the main folder of the site (e.g. one for customers, one for staff, one for admins) each of which can reuse the including fragments hidden under /WEB-INF.

The Theory:

With php/jsp you have the browser request new pages and you draw them so that they see related dated via the session. ZK is a desktop oriented framework where you tend to build "single page applications" which means applications updated by AJAX. Doing a browser redirect is not doing an AJAX update. Your forcing a refetch of all the JS and CSS and re-evaluation of the zul file which is a lot less efficient than doing a dynamic update over AJAX.

If you read http://books.zkoss.org/wiki/ZK%20Developer%27s%20Reference/UI%20Composing/Component-based%20UI it indicates that when you open a new URL you are creating a new desktop. ZK actually puts in a body onunload javascript handler onto the html page it renders telling the browser to send a final AJAX event to destroy the existing desktop when the user navigates to a new url. So your actually destroying your ViewModel when you have your user navigate away from your first zul page. That's why you don't see any data at the new url the browser goes to; it is an entirely new desktop which would get an entirely new ViewModel which has nothing to do with the one the user went away from.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top