-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I'm trying to get back some return values from a modal windows opened
inside a main windows.
When, in the main windows, you press a button a new modal windows
is shown and you can choose some values
How can I get back these values to the main window then the modal
is closed ?
That is the suggested way to handle this situation ?
Thank you
Giuseppe
`<disable-event-thread>false</disable-event-thread>`
should suspend execution on calling doModal().
Hi Giuseppe. For such a case we have written our InputConfirmBox
You can adapt it to your need. I.e. set the returnValue to object and Cast on the caller Side to your needed Type
call:
String str = InputConfirmBox.show(parentComponent, "This is a question that shows in the InputConfirmBox"));
InputConfirmBox.java
/** * This class creates a modal window as a dialog in which the user <br> * can input something. By onClosing this InputConfirmBox can return a value. <br> * In this useCase the returnValue is the same as the inputValue.<br> * * @author bbruhns * @author sgerth */ public class InputConfirmBox extends Window { private static final long serialVersionUID = 8109634704496621100L; private static final Logger logger = Logger.getLogger(InputConfirmBox.class); private final String question; private final Textbox textbox; /** * The Call method. * * @param parent * The parent component * @param anQuestion * The question that's to be confirmed. * @return String from the input textbox. */ public static String show(Component parent, String anQuestion) { return new InputConfirmBox(parent, anQuestion).textbox.getText(); } /** * private constructor. So it can only be created with the static show() * method * * @param parent * @param anQuestion */ private InputConfirmBox(Component parent, String anQuestion) { super(); question = anQuestion; textbox = new Textbox(); setParent(parent); createBox(); } private void createBox() { setWidth("350px"); setHeight("110px"); setTitle(Labels.getLabel("message_Information")); setId("confBox"); setVisible(true); setClosable(true); addEventListener("onOK", new OnCloseListener()); Vbox vbox = new Vbox(); vbox.setParent(this); Label label = new Label(); label.setValue(question); label.setParent(vbox); Separator sp = new Separator(); sp.setBar(true); sp.setParent(vbox); Hbox hbox = new Hbox(); hbox.setParent(vbox); Separator sep = new Separator(); sep.setParent(hbox); textbox.setType("password"); textbox.setWidth("100px"); textbox.setParent(hbox); try { doModal(); } catch (SuspendNotAllowedException e) { logger.fatal("", e); } catch (InterruptedException e) { logger.fatal("", e); } } final class OnCloseListener implements EventListener { @Override public void onEvent(Event event) throws Exception { onClose(); } } }
best
Stephan
PS: all codes from the open Zksample2 project
Hi,
I have a question. The above code of the class InputConfirmBox works under the libraries zk ver. 5.02?
I tried this code with the class InputConfirmBox with libraries zk 5.02 and I can not get it to work, but with the libraries of zk ver. 3.6 works well
do I have to add any aditional code, to make this class work with zk 5.05 libraries or I need to do anything else?
I hope you can help.
Thanks in advance.
Att. Julio Cesar Vivas Camargo
Hi Julio,
add these lines to your zk.xml. because the default value have changed between 3.6.x and 5.x
zk.xml
<system-config> <disable-event-thread>false</disable-event-thread> </system-config>
best
Stephan
Thanks Stephan!!!!!
I tried the previous setting in an example and it works, but not in my project code. I'm using class ThreadLocalListener in my zk.xml file, could this interfere?.
I read the class documentation org.zkoss.zkplus.util.ThreadLocalListener and I do not know if I should do some extra configuration.
The version of the libraries is zk 5.02. I'm using de tag <aop:scoped-proxy /> to access spring beans.
is there any way to use modal windows in this context?
My zk.xml file is:
<zk> <system-config> <ui-factory-class>org.zkoss.zk.ui.http.SerializableUiFactory</ui-factory-class> <disable-event-thread>false</disable-event-thread> </system-config> <listener> <description>ThreadLocal Synchronization Listener</description> <listener-class>org.zkoss.zkplus.util.ThreadLocalListener</listener-class> </listener> <preference> <name>ThreadLocal</name> <value> org.springframework.web.context.request.RequestContextHolder=requestAttributesHolder,inheritableRequestAttributesHolder; </value> </preference>
</zk>
My aplicationContext.xml file is:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <bean name="aqAlmacen" class="gnp.ae.presentacion.ventanaMarco.impl.AqAlmacenImpl" init-method="init"> <property name="smInfo2000" ref="smInfo2000"></property> </bean> <bean name="aqSistema" class="gnp.ae.presentacion.ventanaMarco.impl.AqSistemaImpl" init-method="init" scope="session"> <aop:scoped-proxy /> <property name="aqAlmacen" ref="aqAlmacen" /> </bean> </beans>
I hope you can help.
Thanks in advance.
Att. Julio Cesar Vivas Camargo
Hmmm, i tested it yet with 5.0.2 without problems.
What is the false behaviour you mean?
We do it without the <aop:scoped-proxy /> since we let call the controllers with apply="${customerDialogCtrl}"
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> . . . <bean id="articleDialogCtrl" class="de.forsthaus.webui.article.ArticleDialogCtrl" parent="basisCtrl" scope="prototype"> <property name="articleService" ref="articleService" /> </bean> . . .
Thanks for your reply Stephan!!!!!
The <disable-event-thread>false</disable-event-thread> behavior is that the modal window doesn't suspend execution and return inmediately on calling the doModal() method.
I apologize for any inconvenience caused.
Thanks in advance.
Att. Julio Cesar Vivas Camargo
Asked: 2010-05-03 03:59:17 +0800
Seen: 1,328 times
Last updated: Feb 04 '13