CPR GWT (gwt-ext Netbeans) Hi
< hash.length;i++){
entry is required for this pre-configured with a gwt project in Netbeans and configured in plugin gwt-ext (jar).
< 16) cad+="0";
First I would like to talk about the advantages of GWT and then talk about the disadvantages.
- Everything Back End
programs
, which means you do not necessarily have to learn html, css, javascript, java just have to know the
Front End Back End programs as it sounds so strange is, the gwt compiler is responsible for generating an optimal code in js for your application.
- The way to make asynchronous requests are made quickly through RCP.
- The learning curve is quick.
- The applications run in most browsers (IE, Firefox).
Well after this brief introduction we will create an application that give users a CRUD
.
For our example we must create our model and view package level: org.aplication.client where is all in code that turns into Front End. After
create a class User call within the package org.aplication.client.modelo Create a class named User.
org.aplication.client.modelo package;
import
com.google.gwt.user.client.rpc.IsSerializable;
/ ** * * @ author Isaac
* / public class User implements
IsSerializable {
cve private int;
getApellido
public String () {return name
;
} public void
setApellido (String name) {
this.apellido = surname; } public int
getCve ()
cve {return;}
setCve public void (int cve) {
this.cve = cve;
} public int
getEdad () {return
age
} public void
SETEDER (int age) {
this.edad = age;
} public String getName () {return name
;
} public void
setNombre (String name) {this.name = name
;
}}
This gwt class implements IsSerializable of that is the charge to serialize our class and allows communication between a client and server.
Step 2. Create a package named view (org.aplication.client.view) and a class called GuiUsuario, Uml class diagram for this class will be more or less like this but then we will be adding more methods or classes.
Well first we create our form and then our rcp.
org.aplication.client.view package;
import
com.gwtext.client.core.EventObject;
com.gwtext.client.core.Position import, import
com.gwtext.client.widgets.Button;
com.gwtext.client.widgets.MessageBox import, import
com.gwtext.client.widgets.Window;
com.gwtext.client.widgets.event.ButtonListenerAdapter import, import
com.gwtext.client.widgets.form.FormPanel ;
com.gwtext.client.widgets.form.TextField import; Import
org.aplication.client.modelo.Usuario;
/ **
* * @ author Isaac
* / public class
GuiUsuario {private User user; private Window window;
FormPanel formPanel private, private
TextField name;
private TextField name;
private TextField age
public
FormPanel getFormPanel () {
FormPanel formPanel = new ();
formPanel.setFrame (true);
formPanel.setTitle ( User ");
name = new TextField (" Name "," name ", 230);
name = new TextField (" Name " "Name", 230);
age = new TextField ("age" and "age", 230);
formPanel.add (name);
formPanel.add (last)
formPanel . add (age);
formPanel
return;} public
getUsuario User () {return
user;
} public Window GetWindow () { window = new Window () ;
window.setTitle ("Layout Window");
window.setClosable (true);
window.setWidth (600);
window.setHeight (350);
window.setPlain (true);
window.setCloseAction (Window.HIDE) window.add (getFormPanel ());
buttonNewUser = Button new Button ("New User");
buttonNewUser.addListener (new ButtonListenerAdapter () { @ Override public void onClick (Button button, EventObject e) { MessageBox.alert ("test event ");
}}
) window.setButtonAlign (Position.CENTER)
window.addButton (buttonNewUser)
return window; } public void setUsuario (User user) {
this.usuario = user;
}}
The method GetWindow
() is responsible for creating the window and also to create the
FormPanel through getFormPanel
method (), then just need to call our Gui since it will be the class EntryPoint MainEntryPoint that is in the package org.aplication. client. org.aplication.client package; com.google.gwt.core.client.EntryPoint
import, import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.ClickListener;
import com.gwtext.client.widgets.Window;
import org.aplication.client.view.GuiUsuario;
/**
* Main entry point.
*
* @author isaac
*/ public class MainEntryPoint implements EntryPoint { /** * Creates a new instance of MainEntryPoint
*/
public MainEntryPoint() {
}
/** * The entry point method, called automatically by loading a module
* that declares an implementing class as an entry-point
*/
public void onModuleLoad () {final
Button button = new Button ("Click me!");
button.addClickListener (new clickListener () {public void
onClick (Widget w) {
GuiUsuario GuiUsuario guiUsuario = new ();
winUsu = guiUsuario.getWindow Window ();
winUsu.show ();
}});
RootPanel.get (). add (button);
}}
winUsu.show ();
This method makes the Window class window is displayed on the client browser.
Depues we run a project and we should have something like this.
Step 3. We create the CPR right-click on new / other depues gwt option appears and a list where this gwtrcp we click and then we ask in the name of the service package where we will put it.
Serbian creation: We'll call and you should be GWTServiceUser org.aplication.client.servicio
package
Then we have a structure like the following: A gwt needs rcp 3 main classes and mapping in the web.xml you already do by default netbeans assistant.
within the package
org.aplication.client.servicio
- interface GWTServiceUserAsync
GWTServiceUser -interface and server side in the package this class org.aplication.server.servicio:
-class
GWTServiceUserImpl
The class diagram for the creation of users from client to server is:
The code for each class is: package
org.aplication.client.servicio;
com.google.gwt.user.client.rpc.RemoteService import, import
com.google.gwt.user. client.rpc.RemoteServiceRelativePath;
org.aplication.client.modelo.Usuario import;
/ ** * * @ author Isaac
* /
@ RemoteServiceRelativePath ("service / gwtserviceuser)
public interface extends GWTServiceUser
RemoteService {public String newuser (User user);}
---------------
org.aplication.client.servicio package;
import com. google.gwt.user.client.rpc.AsyncCallback;
org.aplication.client.modelo.Usuario import; / **
* * @ author Isaac
* / public interface
GWTServiceUserAsync {public void newuser (User user, AsyncCallback callback);}
-------------------------------------- org.aplication.server.servicio package;
com.google.gwt.user.server.rpc.RemoteServiceServlet
import, import
java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
org.aplication.client.modelo.Usuario import, import
org.aplication.client.servicio.GWTServiceUser;
/ ** * @
*
author isaac
* /
public class GWTServiceUserImpl extends RemoteServiceServlet implements GWTServiceUser {
private static List
users = null;
private static int contCve = 0;
public String newuser (User user) {
contCve + +;
user. setCve (contCve)
if (users == null) {
users = new ArrayList ();
usuarios.add (user)
usuarios.add} else (user);
for (User u: users) {
System.out.println ("user" + u.getNombre ());}
return "has been created user "}
} ------------------------------------- ------------------------
org.aplication.client.view package;
import com.google.gwt.core.client.GWT ;
com.google.gwt.user.client.rpc.AsyncCallback import, import
com.google.gwt.user.client.rpc.ServiceDefTarget;
com.gwtext.client.core.EventObject import, import
com.gwtext . client.core.Position;
import com.gwtext.client.widgets.Button;
com.gwtext.client.widgets.MessageBox import, import
com.gwtext.client.widgets.Window;
com.gwtext.client.widgets.event.ButtonListenerAdapter import, import
com.gwtext.client.widgets.form.FormPanel;
com.gwtext.client.widgets.form.TextField import, import
org.aplication.client.modelo.Usuario;
org.aplication.client.servicio.GWTServiceUser import; import
org.aplication.client.servicio.GWTServiceUserAsync;
/ **
* * @ author Isaac
* / public class
GuiUsuario {private User user;
private Window window;
FormPanel formPanel private, private
TextField name;
private TextField name;
private TextField age
GWTServiceUserAsync private static service;
public
FormPanel getFormPanel () {
FormPanel formPanel = new ();
formPanel.setFrame (true);
formPanel.setTitle (User) ;
name = new TextField ("Name", "name", 230);
name = new TextField ("Name", "name", 230);
age = new TextField ("age" and "age", 230 )
formPanel.add (name);
formPanel.add (last)
formPanel.add (age);
formPanel
return;}
User public
getUsuario () {return
user;
} public Window
GetWindow () {
window = new Window ();
window.setTitle ("Layout Window");
window.setClosable (true);
window.setWidth (600);
window.setHeight (350);
window.setPlain (true);
window.setCloseAction (Window.HIDE)
window.add (getFormPanel ());
buttonNewUser = new Button Button ("New User");
buttonNewUser.addListener (new ButtonListenerAdapter () {
@ Override public void onClick (Button button, EventObject e) {
User u = new User ();
u.setEdad (Integer.parseInt (edad.getText ()));
u.setNombre (nombre.getText ());
u.setApellido (last . getText ());
insertaUsuario (u);
}}
)
window.setButtonAlign (Position.CENTER)
window.addButton (buttonNewUser)
return window;
} public void
setUsuario (User user) {
this.usuario = user;
} public void insertaUsuario (User user) {
/ / Create an asynchronous callback to handle the result.
final AsyncCallback callback = new AsyncCallback () {public void
onSuccess (Object result) {
String response = (String) result;
MessageBox.alert (response);
} public void
onFailure (Throwable caught) {
MessageBox.alert ("Error" + caught);
}};
getService (). newuser (username, callback);
} public static
GWTServiceUserAsync getService () {
service = (GWTServiceUserAsync) GWT.create (GWTServiceUser.class) ServiceDefTarget
endpoint = (ServiceDefTarget) service;
moduleRelativeURL = GWT.getModuleBaseURL String () + "service / gwtserviceuser"
endpoint.setServiceEntryPoint (moduleRelativeURL )
return service;}
}
----------------------------------- -----
- The important part that we understand the gwt rcp is that we can send beans from customers to our server clearly without needing to take
request.
The menera that this is done is right through the following method GuiUsuario
class.
GWTServiceUserAsync public static getService () {
service = (GWTServiceUserAsync) GWT.create (GWTServiceUser.class)
ServiceDefTarget endpoint = (ServiceDefTarget) service;
moduleRelativeURL = GWT.getModuleBaseURL String () + "service / gwtserviceuser"
endpoint.setServiceEntryPoint (moduleRelativeURL)
return service;}
and occupy the following method call within the same class: public void
insertaUsuario (User user ) { / / Create an asynchronous callback to handle the result.
final AsyncCallback callback = new AsyncCallback () {public void onSuccess (Object result) {
String response = (String) result;
MessageBox.alert (response);
} public void onFailure (Throwable caught) {
MessageBox.alert ("Error" + caught); }};
getService (). newuser (username, callback);}
When you execute this method directly call method getService () which has a method called newuser which we send as a parameter the user and his task callback will be receiving the response from the server rcp here GWTServiceUserImpl class to override the newuser that is where we create the list and insert elements it and it responds with the message return "Created user" which is received by the callback in:
public void onSuccess (Object result) {
String response = (String) result;
MessageBox.alert (response )
.
.
.
Finally we need the event the GuiUsuario button to create the user and call the
insertaUsuario ButtonNewUser Button = new Button ("New User");
buttonNewUser.addListener (new ButtonListenerAdapter () {
@ Override public void onClick (Button button, EventObject e) {
User u = new User ();
u. SETEDER (Integer.parseInt (edad.getText ()));
u.setNombre (nombre.getText ());
u.setApellido (apellido.getText ());
insertaUsuario (u);}
});
After we run the project and our application is ready to create users I put a static list of users but it can be inserted into a database with jdbc or hibernate.
Well that's it then create a grid ....
Dedicated to my little princess.
Part