-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi ZK developers!
I'm starting programming a web application using the ZK technologies. I read some smalltalk about the MVC patterns that can be used with ZK. But I have some problems developing my own application. I have the View (mvc.zul), the Control (Control.java) but I want add the business, the Model (xxx.java). When I try to call from the Control.java to a method of the Model, I receive a java null pointer exception. How can I proceed? what am I doing wrong? (I'm trying to follow the Zlora example)
Thanks in advance
And here is the code:
mvc.zul
<zk> <window title="composer1 example" border="normal" width="300px" use="org.atos.inicio.controller.Control"> <grid> <rows> <row>First Name: <textbox id="firstName" forward="onChange=onFirstName"/></row> <row>Last Name: <textbox id="lastName" forward="onChange=onLastName"/></row> <row>Full Name: <label id="fullName"/></row> <row><button label="OK" forward="onLogin" /><button label="Cancel" /></row> </rows> </grid> </window> </zk>
Control.java
public class Control extends Window implements AfterCompose{ private Textbox firstName; private Textbox lastName; private Label fullName; protected PruebaModelBusiness pmb; //-- AfterCompose --// public void afterCompose() { //wire variables Components.wireVariables(this, this); //NO need to register onXxx event listeners //auto forward Components.addForwards(this, this); } public void onChange$firstName(Event event) { fullName.setValue(firstName.getValue()+" "+lastName.getValue()); } public void onChange$lastName(Event event) { fullName.setValue(firstName.getValue()+" "+lastName.getValue()); } public void onLogin() { System.out.println("hemos llegado aqui"); pmb.escribeLogin("aa", "bb"); try { System.out.println("user + pswd: "+firstName.getValue()+" "+lastName.getValue()); Executions.getCurrent().sendRedirect("prueba.zul"); //win.doModal(); } catch (Exception e) { System.out.println("hemos llegado error"); } // refresh UI } }
The Model (is an interface called PruebaModelBusiness and the respective Impl: PruebaModelBusinessImpl)
package org.atos.inicio.model; public class PruebaModelBusinessImpl implements PruebaModelBusiness { protected PruebaModelBusiness _pmb; public PruebaModelBusinessImpl(){ _pmb=this; } @Override public void escribeLogin(String Name, String Password) { System.out.println("El nombre y password"+ Name+" "+Password); } }
1.) First, you do not need forward="onChange=onFirstName" ÁND autoforward.
Autofoward + the correct name is enough.
2.) You do not create an instance of your mode!
Something like _pmb = new PruebaModelBusiness();
/Robert
Hi,
I didn't try your code, just ask a question from your words,
"When I try to call from the Control.java to a method of the Model, I receive a java null pointer exception."
So I searched your Control.java and found that you declare
protected PruebaModelBusiness pmb;
pmb.escribeLogin("aa", "bb");
If this is where the exception happened,
please try revising your declaration,
such as
protected PruebaModelBusiness pmb = new PruebaModelBusiness();
BTW, providing error message would be appreciated.
Thanks.
(oh, I didn't cheat, I swear I didn't refer to Robert's solution before my post)
Hi robertpic71,
Thank you about the suggesions!!
but I have a comment:
About the 2nd suggestion, PruebaModelBusiness is an interface for PruebaModelBusinessImpl class, so, if it is needed a constructor, it should be the class, isn't it?
And the instance, it should be instantiated on the afterCompose method of the controller class?
Thanks!
It is no clear the usage of the PruebaModelBusiness...
Chen you reach the onLogin event the "pbm" var is null because it was not created as instance..
Asked: 2009-03-31 15:33:29 +0800
Seen: 245 times
Last updated: Apr 01 '09