-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3825480
By: nobody
Hi everyboby,
I'm traing to use zk + jsp + servlets.
I would like to learn how can I require some information (ex: a list) to a servlet and render it dynamically to a listbox.
The ideia is do something like AJAX does. Is there a way to do this with ZK (in JSP if possible)???
(Remeber that I'm working with JSP rather than .zul files)
I'have reading a lot but I did not find out anything about this issue.
Thanks a lot,
Carlos Kolb.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3826087
By: henrichen
Can you provide some sample code that you "wish" how to use it? (Concept is enough, I don't mean the working code)
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3826668
By: nobody
Hi Henri,
Let me try explain my doubt: I'm using zk components embedded on jsp files.
In the example below I have two listboxes. The first one shows tree states from Brazil. When I select one item of first listbox the other listbox should show the cities from that state.
The ideia is to get information from a servlet and render on client without do a refresh, like was done in http://zk1.sourceforge.net/smalltalks/ajax-challenges/ajax-challenge1.html.
I`ve thinking and searching a solution to solve this. I thought that using direct AJAX function written in javascript could help, but it has been a litle confused to write javascrit in the same file that I write zkelements.
<html xmlns:x="http://www.potix.com/2005/zul"
xmlns:zk="http://www.potix.com/2005/zk">
<head>
<title>PA!gina de testes de ZK e AJAX...</title> </head> <body> <x:window title="HTML App" border="normal" width="700px" height="500px">
State
<x:listbox id="state" mold="select" rows="1" >
<x:listitem label="ParanA!" />
<x:listitem label="Santa Catarina"/>
<x:listitem label="Rio Grande do Sul"/>
</x:listbox>
State's cities
<x:listbox id="cities" mold="select" rows="1">
<x:listitem label="THIS LIST SHOULD COME FROM A SERVLET!!! "/>
</x:listbox>
</x:window>
</body>
</html>
Thanks a lot for spend your time!!
Regards,
Carlos Kolb.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3826895
By: tomyeh
I don't see you listen to the onSelect event:
<x:listbox id="state" mold="select" rows="1"
onSelect="do_whatever_you_want_in_Java_on_server()">
...
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3827095
By: nobody
Yeah! This is the point!
What am I supposed to do whith do_whatever_you_want_in_Java_on_server()?
Should Do I make a XMLHttpRequest? Is there an easier way to do this? Doesn't exist something that ZK could do to help me?
I say this because if I need to write javascript in the page the code will be "a little bit" confused, and I had thought that ZK had a taglib or something that make the things easier.
Beyond this, I tried to use javascript. But I couldn't make a javascript call because the arguments were not understood by the function.
I tried to use a code like this one below:
<javascript>
function funcao(str){
alert(str);
}
<javascript>
....
<x:listbox id="state" mold="select" rows="1" onSelect="funcao('someString')">
What am I doing wrong?
Best Regards,
Carlos Kolb.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3827652
By: henrichen
Hi Carlos,
ZK run its event handling code(e.g. onSelect) in SERVER. And the handling code is JAVA code (not javascript) in SERVER.
In your example,
1. When the State is selected by an end user, the onSelect event of the "state"
listbox would be triggered.
2. The JAVA code defined by you in the onSelect would be called by the ZK engine in SERVER. Say,
<x:listbox id="state" mold="select" rows="1" onSelect="Utils.getCities(self)"> ...
3. You should have defined a public class Utils with the public static method getCities(Listbox stateListbox) in your Web Application.
4. In the getCities(Listbox stateListbox), you call
//get the selected state and get city list Listitem li = stateListbox.getSelectedItem(); String state = li.getLabel(); List cities = getCityList(state); //get cities based on state
//populate the city Listbox
Listbox cityListbox = (Listbox) stateListbox.getFellow("cities");
cityListbox.getItems().clear(); //clear city listbox
for(Iterator it = cities.iterator(); it.hasNext();) {
ListItem li = new ListItem((String) it.next());
li.setParent(cityListbox);
}
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3828372
By: nobody
Hi Henri!! This is preatty good!!
It runs on server!! Very good! I'haven't get rigth concept!!
Thanks a lot!
Best Regards,
Carlos Kolb
Asked: 2006-07-17 20:34:06 +0800
Seen: 469 times
Last updated: Jul 19 '06