-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Good afternoon.
I'm creating for my project a forum using ZK. I created a login page where the user can type his username and password and then if he's already registered he can log himself in the forum.
I'm also creating a "Registration section" for new users. If a new user wants to register in the forum, he has to fill 3 text boxes: one for his username, another one for his password and another one for his email. In this same page I created a button that when it's pressed it should insert all the user's data in a precise table of my DataBase.
So in order to do that I created a class named "RegistrationDAO" that allows me to execute the INSERT query (insert username, password and email of a new user into the DB); this class works fine. Then I created another class named "Registration" that should be my "controller class". In this class I declared the name of my window (created in the .zul file), the name of the 3 text boxes but I'm having problems with the auto wiring process. When the user fills all the empty fields in the "Registration section" then he clicks the button and my problem is that I don't know how to take all the values written in text boxes by the user (I mean his username, password and email) and send the into my DB.
I'm posting here my:
1) .zul file named "forumRegistrazione"
2) Registration.java class which is my controller
1) forum.Registrazione.zul
<zk xmlns:c="client"> <style> .meter { font-size: 1px; height: 3px; } .meter-inner { width: 0px; height: 3px; } .meter-red .meter-inner{ background: red; } .meter-orange .meter-inner{ background: orange; } .meter-green .meter-inner{ background: green; } </style> <script src="/js/pwd_str.js"/> <window id="loginWin" border="normal" width="300px" title="You are using: ${desktop.webApp.version}" apply="com.supinfo.JavaClass.Registration"> <grid style="border:0;" width="530px"> <rows> <row>Username: <textbox id="username" width="150px"/> </row> <row> <label value="Password"/> <textbox id="pwd" width="150px" type="password" c:onChanging="meterUpdate(event)" /> </row> <row> <label value="Password Strength"/> <vlayout> <div id="meter" sclass="meter" width="240px"> <div sclass="meter-inner"></div> </div> <label id="msg" /> </vlayout> </row> <row> E-mail: <textbox width="150px" value="" id="email" constraint="/.+@.+\.+/: Please enter an e-mail address" /> </row> <row> <cell colspan="3" style="text-align:center"> <button label="Submit" id="confirmBtn" width="100px" height="30px" href="/forum/registrationSuccess.zul"/> </cell> </row> </rows> </grid> </window> <script type="text/javascript"><![CDATA[ function typePassword(text) { var pwdWidget = zk.Widget.$("$pwd"); pwdWidget.setValue(text); pwdWidget.fire('onChanging',{ value : text }); } ]]> </script> </zk>
2) Registration.java
package com.supinfo.JavaClass; //Questa classe serve per il RegistrationDAO per verificare se la insert avviene correttamente import com.supinfo.DAO.RegistrationDAO; import java.awt.Window; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Textbox; //nel DB. public class Registration extends GenericForwardComposer{ Window loginWin; private Textbox username; private Textbox pwd; private Textbox email; //Name of my DAO class where I declared the INSERT query to insert data in my DB RegistrationDAO rdao= new RegistrationDAO(); public void onClick$confirmBtn(){ } }
Many many many thx for your help!!!
You are most of the way there if I understand your question correctly - sorry if not. You correctly named your member variables the same as what the id's are in the zul file - that supplies the connection for you. Then all you have to do is the following :
public void onClick$confirmBtn() { // The GenericForwardComposer is what handles making the connection between your zul components and the java classes - as long as your id's match up to the member variable names // this is all you have to do. String user = username.getValue(); String password = pwd.getValue(); String mail = email.getValue(); // NOW SEND TO DB }
Asked: 2011-07-25 10:44:36 +0800
Seen: 133 times
Last updated: Jul 25 '11