0

Simple question (BUT URGENT!!) about ZSCRIPT

asked 2008-11-05 08:28:01 +0800

ziccardi gravatar image ziccardi
321 7

updated 2008-11-05 08:32:03 +0800

Hi all.

Why, when I try to access the arg variable, I get the following error?

attempt to resolve method: get() on undefined variable or class name: arg

My zul file is as follows:

<window title="Apertura Pratica">
<zscript>
<![CDATA[
Long lProcessID = (Long) arg.get("ID");
]]>
</zscript>
</window>


Thanks!

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2008-11-05 09:12:16 +0800

ziccardi gravatar image ziccardi
321 7

Hi all.
Even if I try to access the window this way, I get the same error:

<window title="title" id="wid">
<button label="Click Here" onClick="wid.detach()"/>
</window>

It says wid is not defined...

link publish delete flag offensive edit

answered 2008-11-05 10:06:24 +0800

ziccardi gravatar image ziccardi
321 7

Noone has been able to give an hint....
I solved it with a workaround: I access the components using Path.getComponent("path/to/the/component"), and I access
the args through the Executions object.

Regards.

link publish delete flag offensive edit

answered 2008-11-06 14:08:56 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

That is weird. Can you give complete sample codes?

link publish delete flag offensive edit

answered 2008-11-06 16:16:27 +0800

ziccardi gravatar image ziccardi
321 7

I tried to replicate the problem in another simple app, but it seems it works in other scenarious.

One of the ZUL pages that do not works is the following:

<?page id="testZul" title=" New ZUL Title" cacheable="false" 
	language="xul/html" zscriptLanguage="Java" contentType="text/html;charset=UTF-8"?>

<?link rel="stylesheet"  type="text/css" href="..."?>

<zk xmlns="http://www.zkoss.org/2005/zul"
	xmlns:h="http://www.w3.org/1999/xhtml" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">

<window title="Apertura Pratica" id="wid" width="300px">

<zscript>

	import org.jbpm.JbpmConfiguration;
	import org.jbpm.JbpmContext;
	import org.jbpm.context.exe.ContextInstance;
	import org.jbpm.db.GraphSession;
	import org.jbpm.graph.def.Node;
	import org.jbpm.graph.exe.ProcessInstance;
	import org.jbpm.graph.exe.Token;
	import org.zkoss.zul.Label;
	import org.zkoss.zul.Row;
	import org.zkoss.zul.RowRenderer;
	import org.jbpm.taskmgmt.exe.TaskInstance;
	
	//Long lTaskID = Executions.getCurrent().getArg().get("ID");
	Long lTaskID = arg.get("ID");
	Long lProcessID = null;
	JbpmContext jbpmContext = null;

	List vFiles = new ArrayList();
	String sSocieta = "";
	
	
	try
	{
		jbpmContext =  JbpmConfiguration.getInstance().createJbpmContext();
		//Prelevo il process id
		TaskInstance ti = jbpmContext.getTaskInstance(lTaskID.longValue());
		ProcessInstance pi = ti.getProcessInstance();
		lProcessID = new Long(pi.getId());
		//////////////////////////////
				
		List v = (List) pi.getContextInstance().getVariable("AP_FILES");
		sSocieta = (String) pi.getContextInstance().getVariable("SOCIETA");
		if (v != null)
			vFiles = v;
		if (sSocieta == null)
			sSocieta = "";
		
		//alert(pi);
	}
	finally
	{
		if (jbpmContext != null)
			jbpmContext.close();
	}
</zscript>

	<vbox>
		<grid>
		   <rows>
		   		<row>
					Nome Societa' :
					<textbox id="societa" text="${sSocieta}"/>
				</row>
			</rows>
		</grid>
		Lista Documenti allegati: 
		<grid id="fileList">
			<columns>
				<column label="Nome File"/>
			</columns>
		</grid>

		<zscript>
			Grid g = Path.getComponent("/wid/fileList");
			g.setModel(new SimpleListModel(vFiles));
		
			void onSave()
			{
				Window w = (Window) Path.getComponent("/wid");
				Textbox txtSocieta = (Textbox) Path.getComponent("/wid/societa");
				
				JbpmContext jbpmContext = null;

				try
				{	
					jbpmContext =  JbpmConfiguration.getInstance().createJbpmContext();
					//GraphSession graphSession = jbpmContext.getGraphSession();
					ProcessInstance pi = jbpmContext.getProcessInstance(lProcessID.longValue());
					//List v = (List) pi.getContextInstance().getVariable("AP_FILES");
					//if (v != null)
					//	vFiles = v;
					
					pi.getContextInstance().setVariable("AP_FILES", vFiles);
					pi.getContextInstance().setVariable("SOCIETA", txtSocieta.getText());
					
					jbpmContext.save(pi);
					
				}
				finally
				{
					if (jbpmContext != null)
						jbpmContext.close();
				}

				w.detach();
			}

			void onValidate()
			{
				Window w = (Window) Path.getComponent("/wid");
				Textbox txtSocieta = (Textbox) Path.getComponent("/wid/societa");
				
				JbpmContext jbpmContext = null;

				try
				{	
					jbpmContext =  JbpmConfiguration.getInstance().createJbpmContext();
					//GraphSession graphSession = jbpmContext.getGraphSession();
					ProcessInstance pi = jbpmContext.getProcessInstance(lProcessID.longValue());
					//List v = (List) pi.getContextInstance().getVariable("AP_FILES");
					//if (v != null)
					//	vFiles = v;
					
					pi.getContextInstance().setVariable("AP_FILES", vFiles);
					pi.getContextInstance().setVariable("SOCIETA", txtSocieta.getText());
					
					
					TaskInstance ti = jbpmContext.getTaskInstance(lTaskID.longValue());
					ti.end("validazione");
					
					jbpmContext.save(pi);
					
				}
				finally
				{
					if (jbpmContext != null)
						jbpmContext.close();
				}

				w.detach();
			}
			
		</zscript>
		
		<button label="Allega Nuovo File">
			<attribute name="onClick">
			{
				Object media = Fileupload.get();
				if (media != null)
				{	
					String s = media.getName();
					vFiles.add(s);
					Grid g = Path.getComponent("/wid/fileList");
					g.setModel(new SimpleListModel(vFiles));
				}
			}
			</attribute>
		</button>
		
		<hbox>
			<button label="Salva Modifiche" onClick="onSave()"/>
			<button label="Invia in approvazione" onClick="onValidate()"/>
		</hbox>


	</vbox>
	
	
</window>
</zk>

My application works like this:
I have a workflow, managed through JBPM.
I want all the pages to be embedded inside the workflow, so that I can change the workflow, without the need to change the WEB application.

I solved it this way: inside the workflow package (the .par archive), I put all the pages needed to handle the workflow step.

Than, as on enter event of each step, I create a variable that holds the content of the zul page.

In my web application, I simply ask the flow item to give me the source of the zul page needed to handle itself. Then I create the page with Executions.createComponentDirectly.

The code that creates the page, is:

        private Window createPage(Long lProcessID)
	{
		JbpmContext jbpmContext = null;
		
		try
		{
			jbpmContext =  JbpmConfiguration.getInstance().createJbpmContext();
			//GraphSession graphSession = jbpmContext.getGraphSession();
			TaskInstance ti = jbpmContext.getTaskInstance(lProcessID.longValue());
			
			ProcessInstance pi = ti.getProcessInstance();
			//ProcessInstance pi = jbpmContext.getProcessInstance();
			//ProcessInstance pi = (ProcessInstance) graphSession.findProcessInstances().get(0);
			String sPage = (String) pi.getContextInstance().getVariable("PAGE");
			
			Map args = new HashMap();
			args.put("ID", lProcessID);
			
			return (Window) Executions.createComponentsDirectly(sPage, "zul", null, args);
			
		}
		finally
		{
			if (jbpmContext != null)
				jbpmContext.close();
		}
	}

Thank you.

link publish delete flag offensive edit

answered 2008-11-10 06:35:16 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

We need an example that is simple and can be run; otherwise it is very difficult to replicate your issue.

link publish delete flag offensive edit

answered 2008-11-10 07:40:44 +0800

ziccardi gravatar image ziccardi
321 7

I though so.

As I told you, with simpler examples, it works.
If I should ever be able to produce an example, I'll post it again here.

However, in the meanwhile, I'll keep on using the Path object to access the components..

Thanks for your support.

link publish delete flag offensive edit

answered 2008-11-10 09:19:29 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

It looks like a wrong bsh.jar problem, do you use the bsh.jar form official download of zk package or a older one.

link publish delete flag offensive edit

answered 2008-11-10 10:38:57 +0800

ziccardi gravatar image ziccardi
321 7

I use the official one

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-11-05 08:28:01 +0800

Seen: 522 times

Last updated: Nov 10 '08

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