0

Zk with servlet and jsp

asked 2009-10-26 05:52:23 +0800

victorhugomunizm gravatar image victorhugomunizm
33

I have my application in production and want change the view layer to put ZK there...
I take all attributes in my jsp with request.getAttribute("xpto").. I want one way to get my attributes in my Zks components from the request.. I don't want use .zul and don't want create one more class to my jsp
How is it possible? Expression lenguage maybe? How I can populate a <z:listbox> with my attribute from the request?
Do you have an example for this? A tutorial? Any helps is well come!!

Thaks a lot

delete flag offensive retag edit

12 Replies

Sort by ยป oldest newest

answered 2009-10-26 12:19:34 +0800

n4rk0 gravatar image n4rk0
120 3

This is the way to transfer information between java code in Jsp and ZK


<%
	String myStr1 = "scriptlet String";
	request.setAttribute("myStr1",myStr1);
%>

<zk:page>
	
	<zk:label value="${myStr1}"/>
</zk:page>

link publish delete flag offensive edit

answered 2009-10-26 12:24:34 +0800

victorhugomunizm gravatar image victorhugomunizm
33

n4rk0

I do this and works fine

but my problem is with a list.. How is it possible? Expression lenguage maybe? How I can populate a <z:listbox> with my attribute from the request?


see this
http://www.zkoss.org/forum/listComment/10019

link publish delete flag offensive edit

answered 2009-10-26 22:09:10 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi,victorhugomunizm

you can refer to http://www.zkoss.org/smalltalks/zuljspII/

but zkjsp spec is changed

you must to set Variable like: page.setVariable("list", list);

this is my demo

<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ taglib uri="http://www.zkoss.org/jsp/zul" prefix="z"%>
<z:init use="org.zkoss.zkplus.databind.AnnotateDataBinderInit"/>
<%
	request.setAttribute("my_text", "Texto ZK");// use Request to store and pass data.

	LinkedList<Properties> list = new LinkedList<Properties>();
	Properties p1 = new Properties();
	p1.setProperty("nome", "ABCD");
	p1.setProperty("email", "[email protected]");

	Properties p2 = new Properties();
	p2.setProperty("nome", "EFGH");
	p2.setProperty("email", "[email protected]");

	list.add(p1);
	list.add(p2);

	request.setAttribute("list", list);

	LinkedList<String> list2 = new LinkedList<String>();
	list2.add("ABCD");
	list2.add("EFGH");

	request.setAttribute("list2", list2);
%>


<z:page>
	<z:zscript>
		list = requestScope.get("list");	
		page.setVariable("list", list);	
	</z:zscript>
	<z:window title="Hello World!!" border="normal" width="100%">
		<z:groupbox id="gb" mold="3d" width="100%">
			<z:label value="${my_text}" />
		</z:groupbox>
		<z:groupbox>
			<z:listbox id="feedListBox" model="@{list}">
				<z:listhead sizable="true">
					<z:listheader label="Name" width="100px" />
					<z:listheader label="Email" width="250px" />
				</z:listhead>
				 <z:listitem self="@{each='my'}">
					<z:listcell label="@{my.nome}"/>
					<z:listcell label="@{my.email}"/>
   				 </z:listitem>
			</z:listbox>			
		</z:groupbox>
	</z:window>
</z:page>

link publish delete flag offensive edit

answered 2009-10-27 06:13:05 +0800

victorhugomunizm gravatar image victorhugomunizm
33

My friend

why we have do this
<z:zscript>
list = requestScope.get("list");
page.setVariable("list", list);
</z:zscript>

No have possible don't do this and use EL like ${list}
???

link publish delete flag offensive edit

answered 2009-10-27 06:46:15 +0800

victorhugomunizm gravatar image victorhugomunizm
33

another question...

why my header don't show me the label???

this...
<z:listheader label="Name" width="100px" />

don't appear the label 'Name' ...why??

link publish delete flag offensive edit

answered 2009-10-27 20:48:48 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

because @{list} is handle by <z:init use="org.zkoss.zkplus.databind.AnnotateDataBinderInit"/>
so it only can get Variable in zk
it can't get request scope Variable in @{list}
so we need to transfer data between JSP and ZK.
because zk AnnotateDataBinder not support to get request scope Variable

I try my sample code
the header is show well
did you test my sample code ?

link publish delete flag offensive edit

answered 2009-10-28 06:07:46 +0800

victorhugomunizm gravatar image victorhugomunizm
33

thanks for de explanition

yes I try, but don't appear... I creat another jsp, I test in another browser...

where is possible I post a print screen to you see what I am talking

what happened... my label don't works fine

what I can do??

link publish delete flag offensive edit

answered 2009-10-28 13:41:17 +0800

victorhugomunizm gravatar image victorhugomunizm
33

I created another project to but the labels don't appear

one thing so easy can be so complicated... how is it possible?

link publish delete flag offensive edit

answered 2009-10-28 19:45:20 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

you can update your zuljsp.jar to 1.4

link publish delete flag offensive edit

answered 2009-10-29 11:00:05 +0800

victorhugomunizm gravatar image victorhugomunizm
33

I try with zk 3.6.2 and zk 5

I update my zuljsp.jar to 1.4

I prepared a .zul file and works fine but in my jsp the problem continues

what else I can do to solve this problem??

thanks a lot

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: 2009-10-26 05:52:23 +0800

Seen: 992 times

Last updated: Oct 30 '09

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