0

Passing param to a composer to another

asked 2010-06-23 07:29:34 +0800

SHERKHAN gravatar image SHERKHAN
231 3

updated 2010-06-23 07:31:10 +0800

Hi,

Here is my problem. I have two composers : one for the window of the zul file 1 and the other for the window of the zul file 2. I would like changing page when a specific event occurs from the zul file 1. So when an event occurs from the zul file 1, the zul file 2 is displayed. (sendRedirect?)
And I would like retrieving an object from the first composer, which is initialized when the event occurs, in the composer 2.

Maybe something like that :

Composer 1 :

class Composer1 extends GenericForwardComposer {
     onClick$event {
        Object obj = initializeObject()
        (do something...)
        sendRedirect() or createComponent() or include .... I don't know...
     }
}

zul file 1:

<window id="win1"  width="800px" border="normal" apply="Composer1">
  .....
</window>

Composer 2:

class Composer2 extends GenericForwardComposer {
     Composer2 {
        Object obj = // retrieve the object from the composer 1
     }
}

zul file 2 :

<window id="win2"  width="800px" border="normal" apply="Composer2">
  .....
</window>

Thanks for your help,
Regards,
SHERKHAN

delete flag offensive retag edit

10 Replies

Sort by » oldest newest

answered 2010-06-23 08:37:29 +0800

rafaelmaas gravatar image rafaelmaas
51

updated 2010-06-23 08:39:00 +0800

Hi Dude.

I face the same problem a few days ago and solved as follows:

My first zul page:

<zk>
	<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
	<window id="main" apply="DatabindingComposer" height="400px">

		<div>
			<label id="historico"
				style="position:relative; top:2px;padding-left: 465px; font-size:24px;color:#383838;font-weight:bold;"
				value="Historico Serviço" />
		</div>
		<div align="center">
			<label id="teste" />
			<listbox id="hist_serv_req" model="@{mainCtrl.historico}"
				selectedItem="@{mainCtrl.selected}" rows="20" mold="paging"
				pageSize="20" multiple="true" width="600px">
				<listhead>
					<listheader label="Id" width="10px" />
					<listheader label="Definição do serviço"
						width="17px" />
				</listhead>
				<listitem self="@{each=historico}"
					onClick="detalhes()" tooltip="detalhes">
					<listcell label="@{historico.id}"></listcell>
					<listcell
						label="@{historico.service.description}">
					</listcell>
				</listitem>
			</listbox>
		</div>

		<popup id="detalhes" width="170px">
		
			Clique para detalhes.
		</popup>
		<zscript>
	void detalhes() {
		Sessions.getCurrent().setAttribute("historyServiceRequest", mainCtrl.selected);
		Executions.sendRedirect("detalhes.zul");
	}
	void fechar() {
		mainCtrl.selected = null;
		detalhes.close();
	}
</zscript>
	</window>

</zk>

my second zul page:

<zk>
	<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
	<window id="detalhes" apply="DetalhesComposer">
		<div>
			<label
				style="position:relative; top:2px;padding-left: 470px; font-size:24px;color:#383838;font-weight:bold;"
				value="Detalhes" />
		</div>
		<div align="center">
		<window width="400px" height="380px" contentStyle="overflow:auto">
			<div align="center">
				<grid fixedLayout="true" 
					model="@{detalhesCtrl.historyServiceRequestData}">

					<rows>
						<row self="@{each=historyServiceRequestData}">
							<grid>
								<columns>
									<column align="left" width="25%"
										label="@{historyServiceRequestData.id}" />
								</columns>
								<rows>
									<row>
										<label value="Nome" />
										<textbox id="dataLabel"
											width="98%" value="@{historyServiceRequestData.label.label}" />
									</row>
									<row>
										<label value="Valor" />
										<textbox id="value" width="98%"
											value="@{historyServiceRequestData.value}" />
									</row>
									<row>
										<label value="Tipo do valor" />
										<textbox id="valueType"
											width="98%"
											value="@{historyServiceRequestData.valueType.type}" />
									</row>
									<row>
										<label value="Tipo do dado" />
										<textbox id="dataType"
											width="98%"
											value="@{historyServiceRequestData.dataType.type}" />
									</row>
								</rows>
							</grid>
						</row>

					</rows>
				</grid>
			</div>
		</window>
		</div>
		
		<label value="   "></label>
		<image style="position:relative; top:5px;padding-left: 510px;" src="/img/voltar.PNG" onClick="voltar()"/>
			


	</window>
	<zscript>
	void voltar() {
		Executions.sendRedirect("relatorio_historico_servico.zul");
	}
</zscript>

</zk>

and my DetalhesComposer.java:


public class DetalhesComposer extends GenericForwardComposer{
	private static final long serialVersionUID = -7852265997568232956L;

	HistoryServiceRequest historyServiceRequest;
	List<HistoryServiceRequestData> historyServiceRequestData =new ArrayList<HistoryServiceRequestData>();
	public DetalhesComposer() {

	}

	public void doAfterCompose(Component comp) throws Exception {
		
		//Pegar o id e fazer uma busca no DAO para pegar o resto dos dados
		super.doAfterCompose(comp);
		comp.setVariable(comp.getId() + "Ctrl", this, true);
		HttpSession session = (HttpSession) (Executions.getCurrent())
		.getDesktop().getSession().getNativeSession();
		historyServiceRequest = new VoiceAnywhereBO().historyServiceRequest(((HistoryServiceRequest)session.getAttribute("historyServiceRequest")).getId());
		
		for (HistoryServiceRequestData d : historyServiceRequest.getData()) {
			historyServiceRequestData.add(d);
		}
	}

	public List<HistoryServiceRequestData> getHistoryServiceRequestData() {
		return historyServiceRequestData;
	}

}

.. i just put my object into a session and recover it in the other page.
Well, i hope this helps you.

PS: sorry, my english sux.

link publish delete flag offensive edit

answered 2010-06-23 09:07:28 +0800

SHERKHAN gravatar image SHERKHAN
231 3

Thanks rafaelmaas,

I thought about session, but I thought too an other way exists to do the same things...

I will try your way,

Regards,

SHERKHAN

PS : my english sux too :) Where are you from?

link publish delete flag offensive edit

answered 2010-06-23 09:18:20 +0800

rafaelmaas gravatar image rafaelmaas
51

Try to search about CRUD.
In my case, session was the best (and simple) solution.

PS: im from brasil.

link publish delete flag offensive edit

answered 2010-06-23 09:20:49 +0800

SHERKHAN gravatar image SHERKHAN
231 3

updated 2010-06-23 09:22:55 +0800

Oh and why do you do Executions.getCurrent().getDesktop().getSession().getNativeSession() and not just Sessions.getCurrent() in your DetalhesComposer to retrieve the session? Maybe it's a stupid question but...

link publish delete flag offensive edit

answered 2010-06-23 09:45:10 +0800

rafaelmaas gravatar image rafaelmaas
51

Cause when i try to use Sessions.getCurrent() i got a java.lang.NullPointerException.

Probably i was doing something wrong.... LOL

link publish delete flag offensive edit

answered 2010-06-23 12:07:44 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-06-23 12:09:51 +0800

search for Executions.createComponents("/pages/win1.zul", parent, paramMap) That's the easiest way to overhanded to a second zul-file the controller self in the paramMap. So you have control with the getters/setters

zul1.zul

	
         .  .  .

         /**
	 * When the tab 'tabCustomerList' is selected.<br>
	 * Loads the zul-file into the tab.
	 * 
	 * @param event
	 * @throws IOException
	 */
	public void onSelect$tabCustomerList(Event event) throws IOException {

               .  .  .

		if (tabPanelCustomerList != null) {

			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("mainCustomerController", this);

			tabPanelCustomerList.getChildren().clear();

			Panel panel = new Panel();
			Panelchildren pChildren = new Panelchildren();

			panel.appendChild(pChildren);
			tabPanelCustomerList.appendChild(panel);

			// call the zul-file and put it on the tab.
			Executions.createComponents("/WEB-INF/pages/customer/customerList.zul", pChildren, map);
		}

	}
         .  .  .

zul2.zul

        .  .  .
	// Databinding
	private AnnotateDataBinder binder;
	private CustomerMainCtrl customerMainCtrl;  // + getter/setter

        .  .  .

	/**
	 * Automatically called method from zk.
	 * 
	 * @param event
	 * @throws Exception
	 */
	public void onCreate$windowCustomerList(Event event) throws Exception {

		if (logger.isDebugEnabled()) {
			logger.debug("--> " + event.toString());
		}

		binder = (AnnotateDataBinder) event.getTarget().getAttribute("binder", true);

		// get the params map that are overhanded by creation.
		Map<String, Object> args = getCreationArgsMap(event);

		/*
		 * BINDING STUFF:
		 * 
		 * Get the selectedItem from the Mainmodule.
		 */
		if (args.containsKey("mainCustomerController")) {
			setCustomerMainCtrl((CustomerMainCtrl) args.get("mainCustomerController"));

	

. . .



	/**
	 * Get the params map that are overhanded at creation time. <br>
	 * Reading the params that are binded to the createEvent.<br>
	 * 
	 * @param event
	 * @return params map
	 */
	@SuppressWarnings("unchecked")
	public Map<String, Object> getCreationArgsMap(Event event) {
		CreateEvent ce = (CreateEvent) ((ForwardEvent) event).getOrigin();
		return ce.getArg();
	}

link publish delete flag offensive edit

answered 2010-06-24 03:39:27 +0800

SHERKHAN gravatar image SHERKHAN
231 3

Thanks Terry,

So in my case I will attach my zul2.zul to the zul1.zul window. But I will attach a window to another... It is maybe not good... Or maybe I can change the current window... But I don't know if it is possible... Or I have to have another zulFile which manage the view and decide which zulFile (zul1 or zul2) it will use. But in this case I will have to catch the event from the other zulFile (zul1 or zul2), and I don't know if it is possible too.

Maybe something like that:

Composer1:

class Composer1 extends GenericForwardComposer {
  
  protected Window window1;

  Composer1 {   // or doAfterCompose, I never used it
    Executions.createComponents("zul1.zul", window1, null);
  }
  
  public void onClick$fromTheZulFile2 {
     Map<String, Object> map = // retrieve information from the composer2 and create the map...
     Executions.createComponents("zul2.zul", window1, map); // after detachment of the last
  }
}

But I think it doesn't work...

Thanks for your help,

Best regards,

SHERKHAN

link publish delete flag offensive edit

answered 2010-06-24 04:14:43 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-06-24 04:17:01 +0800

SHERKHAN,

i have problems to understand your intention.

But I will attach a window to another... It is maybe not good...

Why not?

Think about the window component as a container for a nameSpace. (Means it can have no border/title and capsulate only several comps that you can manipulate in the controller)

Have a look on this thread for the codes from Simon

best
Stephan

link publish delete flag offensive edit

answered 2010-06-24 04:57:05 +0800

SHERKHAN gravatar image SHERKHAN
231 3

Thanks Stephan (not terry?),

I'm going to study this way!

Thanks for all,

Regards,

SHERKHAN

link publish delete flag offensive edit

answered 2014-04-10 07:04:47 +0800

PankajSonagara gravatar image PankajSonagara
1

hi ! You can use Executions.sendRedirect("zul_path?param1=value1&param1=value1"); and after than in the composer of zul where you are redirecting you can get this parameters values. like:

String[] param1Array = (String[])param.get(param1); String param1 = param1Array.get(0); String[] param1Array = (String[])param.get(param1); String param2 = param2Array.get(0);

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: 2010-06-23 07:29:34 +0800

Seen: 709 times

Last updated: Apr 10 '14

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