Wednesday, 22 May 2013
GWT Request factory Vs RPC
What if your Server is not Java?
Server Side Code must be java. To communicate with different server, you have to use
RequestBuilder class, JSNI methods or a third party library. You will have to communicate using json/xml respone.
If your GWT application needs to communicate with a server, but you can't use Java servlets on the backend — or if you simply prefer not to use RPC — you can still perform HTTP requests manually. GWT contains a number of HTTP client classes that simplify making custom HTTP requests to your server and optionally processing a JSON- or XML-formatted response.
RPC
This feature did not work out as planned, and the GWT team strongly discourages its use.
Service Oriented.
Use it only for simple method call. Dont use it for heavy POJO transfer.
Manual Serailization of POJO need.
RPC does not keeps track of objects that have been modified and sends only changes to the server, which results in very heavy weight network payloads.
Do not use it to Transfer POJO.
Request Factory
Recommended by GWT.
Efficient.
RequestFactory and its related interfaces (RequestContext and EntityProxy) make it easy to build data-oriented (CRUD) apps with an ORM-like interface on the client. It is designed to be used with an ORM layer like JDO or JPA on the server, although this is not required.
RequestFactory keeps track of objects that have been modified and sends only changes to the server, which results in very lightweight network payloads. In addition, RequestFactory provides a solid foundation for automatic batching and caching of requests in the future.
Request Factory with Spring roo
Spring Roo auto generates this request factory related stuffs from domain . Means updating a domain, Spring roo auto updates request factory related stuff.
Tuesday, 21 May 2013
UI Binder GWT
Steps
1. Create ui.xml file.
2. bind it to widget.
Advantages
- Helps productivity and maintainability — it's easy to create UI from scratch or copy/paste across templates;
- makes it easier to collaborate with UI designers who are more comfortable with XML, HTML and CSS than Java source code;
- provides a gradual transition during development from HTML mocks to real, interactive UI;
- encourages a clean separation of the aesthetics of your UI (a declarative XML template) from its programmatic behavior (a Java class);
- performs thorough compile-time checking of cross-references from Java source to XML and vice-versa;
- offers direct support for internationalization that works well with GWT's i18n facility; and
- encourages more efficient use of browser resources by making
it convenient to use lightweight HTML elements rather than
heavier-weight widgets and panels.
UI Elements in fileName.ui.xml
Create Widget and get reference of UI Elements of fileName.ui.xml
Event Of UI Element of fileName.ui.xml
Friday, 17 May 2013
Change Default Author Name for JavaDocs in Eclipse
Change Default Author Name for JavaDocs in Eclipse
posted 29 Dec 2010 03:46 by Sanjeev Kumar [ updated 11 Nov 2011 06:17 ]
/**
* Test default author in JavaDocs
* @author SK0012345
*/
public class TestClass {
}
Here
is a quick way to change the default author name in your Eclipse
projects. Simply edit your eclipse.ini file found in the root directory
where you placed Eclipse. I have Eclipse at
C:\devtools\development\eclipse, so my path would be
C:\devtools\development\eclipse\eclipse.ini. Once editing this file add
the following line and save.
-Duser.name=Sanjeev Kumar
After
saving restart Eclipse and when you do a JavaDoc comment and use the
author attribute by typing @author and pressing enter on the
autocomplete you will see something like this:
/**
* Test default author in JavaDocs
* @author Sanjeev Kumar
*/
public class TestClass {
}
Reference
http://www.javagyan.com/useful-tips/changedefaultauthornameforjavadocsineclipse
Beware of floating point numbers
Beware of floating point numbers
posted 29 Dec 2010 10:23 by Sanjeev Kumar [ updated 11 Nov 2011 06:05 ]
Outside
of a scientific or engineering context, the use of float and double
(and the corresponding wrapper classes Float and Double ) should likely
be avoided. The fundamental problem is that rounding errors will always
occur when using these data types - they are unavoidable.
In
a typical business application, using float and double to represent
money values is dangerous, because of these rounding issues. Instead,
BigDecimal should usually be used to represent money. It is also a
common practice to have utility classes like "MonetaryAmount.java" that
are wrappers over "BigDecimal" class of the JDK and that
provides helper methods and functionality as needed by the business
application.
From an IBM article on this topic :
"...binary
floating-point arithmetic should not be used for financial, commercial,
and user-centric applications or web services because the decimal data
used in these applications cannot be represented exactly using binary
floating-point."
From an article by Brian Goetz :
"...it
is a bad idea to use floating point to try to represent exact
quantities like monetary amounts. Using floating point for
dollars-and-cents calculations is a recipe for disaster. Floating point
numbers are best reserved for values such as measurements, whose values
are fundamentally inexact to begin with."
Article From taken from
http://www.javagyan.com/useful-tips/bewareoffloatingpointnumbers
Thursday, 16 May 2013
Must for GWT Developers-- All That GWT Developer must know to develop large GWT Web Application
Must for GWT Developers
Use Java for
creating Ajax applications
No
need to worry about browser dependencies, it works in all the
browsers.
debugging
UI is easy
Important modules in GWT?
GWT
Compiler
JRE
Emulation library
Hosted
Mode ( Run as java)
Web
Mode ( Run as JavaScript)
What is GWT Compiler?
GWT Compiler used to convert the client side Java code to Javascript at the time of building the source files.
GWT Compiler used to convert the client side Java code to Javascript at the time of building the source files.
GWT - Java
Emulation library?
Google Web Toolkit
includes a library that emulates a subset of the Java run-time
library. The list below shows the set of JRE packages, types and
methods that GWT can translate automatically. Note that in some
cases, only a subset of methods is supported for a given type.
java.lang
java.lang.annotation
java.math
java.io
java.sql
java.util
java.util.logging
java.lang
java.lang.annotation
java.math
java.io
java.sql
java.util
java.util.logging
Bootstrap process:
HTML
|
nocache.js ( Bootstrap javascript file )
|
|->( Loads the browser specific files)
|
module.xml ( *.gwt.xml )
|
|->( which loads the entry point class )
|
onModuleLoad() method
|
|
|
Loads the application
HTML
|
nocache.js ( Bootstrap javascript file )
|
|->( Loads the browser specific files)
|
module.xml ( *.gwt.xml )
|
|->( which loads the entry point class )
|
onModuleLoad() method
|
|
|
Loads the application
HTML
-- > .nocache.js (bootstrap JavaScript
file)
-- > Which loads the browser specific files (Permutation javascript file)
-- > Which loads the browser specific files (Permutation javascript file)
Module.xml
-- > Basic inherits (required modules)
-- >Entry point class (onModuleLoad () method)
-- > cross site linker (useful for code splitting)
-- >Entry point class (onModuleLoad () method)
-- > cross site linker (useful for code splitting)
Organize Gwt Projects
GWT Linkers:
The primary linker (there also are secondary linkers, but they're not involved here) is responsible for creating the *.js or *.html files that host the compiled JS code, and of course how to bootstrap/load them into the browser.
IFrameLinker – Default
XSLinker – For cross site support
SingleScriptLinker
<add-linker name=”XS”>
XSLinker – For cross site support
SingleScriptLinker
<add-linker name=”XS”>
UIBinder
- useful for designing the GUI using XML format ( you can mix HTML
and GWT Widgets)
How
to create custom widgets in GWT?
Create a class that should extends Composite class of GWT.
Inside the constructor you can write you logic to create a widget and call the initWidget method().
Then you can use this class in anywhere in the application and add this widget in any panels.
Create a class that should extends Composite class of GWT.
Inside the constructor you can write you logic to create a widget and call the initWidget method().
Then you can use this class in anywhere in the application and add this widget in any panels.
What
is AsyncDataProvider in GWT cell widgets?
When you want to display dynamic data or a range of data, not just a static list, then we should use AsyncDataProvider.
Example : http://www.mytechtip.com/2010/11/gwt-celltable-example-using_8168.html
What is the use of ValueUpdater vs FieldUpdater in Cell Widgets?
When you want to display dynamic data or a range of data, not just a static list, then we should use AsyncDataProvider.
Example : http://www.mytechtip.com/2010/11/gwt-celltable-example-using_8168.html
What is the use of ValueUpdater vs FieldUpdater in Cell Widgets?
GWT
ClientBundle:
In GWT we can use ClientBundle to load all the images and CSS files in one single file and use it anywhere in the application. It provides flexible way to get the resources.
1. It creates a single image from the collection of images at compile time to reduce the image size.
2. Enable more aggressive caching headers for program resources. It will go to server for every-time to get the images.
3.Eliminate mismatches between physical file names and constants in Java code by performing consistency checks during the compile
In GWT we can use ClientBundle to load all the images and CSS files in one single file and use it anywhere in the application. It provides flexible way to get the resources.
1. It creates a single image from the collection of images at compile time to reduce the image size.
2. Enable more aggressive caching headers for program resources. It will go to server for every-time to get the images.
3.Eliminate mismatches between physical file names and constants in Java code by performing consistency checks during the compile
Server
side communication:
-- > Using GWT RPC
-- > Using RequestBuilder
To use RequestBuilder we need to inherit HTTP Module in module.xml file
<inherits name="com.google.gwt.http.HTTP"/>
--> Using Command Pattern (GWTP Dispatcher)
-- > Using GWT RPC
-- > Using RequestBuilder
To use RequestBuilder we need to inherit HTTP Module in module.xml file
<inherits name="com.google.gwt.http.HTTP"/>
--> Using Command Pattern (GWTP Dispatcher)
→ Request
Factory : recommended
GWT
Serialization:
-- >Using GWT IsSerializable OR Java Serializable
-- >Using GWT IsSerializable OR Java Serializable
What is Entry-point class in GWT and how to configure this?
History
Management- BookMarking URL.How
GWT Navigation works?
In GWT we can handle page navigation using couple of
ways.
1. Using History tokens
2. Clearing the content panel and load the new page in
the content panel.
3.
Using Activities, Activity Manager, and Places concepts (Recommended)
4. GWT P Provides annotation for history mangement
4. GWT P Provides annotation for history mangement
https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces
GWT RPC vs GWT RequestBuilder ( for server side communication )
1. When we use GWT RPC we dont need to handle Serialization / Deserialization of the request.
2. When we use RequestBuilder we need to handle
Serialization / Deserialization of the request/response.
http://milansoftwareengg.blogspot.in/2013/05/gwt-request-factory-vs-rpc.html
http://milansoftwareengg.blogspot.in/2013/05/gwt-request-factory-vs-rpc.html
What is the use of UIBInder in GWT and why we should use UIBinder?
http://milansoftwareengg.blogspot.in/2013/05/ui-binder-gwt.html
How can you test a GWT application?
What is deferred binding in GWT?
Describe what a GWT generator does
Refer the following URL
http://stackoverflow.com/questions/3298317/what-is-the-use-gwt-generator
What are some benefits of using CssResource, ImageResource, TextResource, etc
How does GWT app work? (compiling to JavaScript, cross-browser support, bootstrapping script, etc.)
When would you NOT use GWT? (rather general and open-ended question, but it demonstrates if developer is really into this technology)
Follow-up question: What GWT alternatives would you consider?
Describe server-side development with GWT.
Serialization and Un-serialization. What is required of a user defined class for it to be serializable?
All we need to do is create a class which implements GWT IsSerializable or Java Serializable interface.
IsSerializable
Vs Serializable:
Both are acceptable in GWT to make a class serializable.
When you use Normal java Serializable you need to take care all the serialized classes are available in the Serialization policy file or not.
But when you use GWT IsSerializable, you don't need to worry about Serialization policy file.
So, if your class is only used by GWT application, better we can go for GWT IsSerializable.
If your model class is used by more than one Application then better use Java Serializable.
Event handling. Describe how an event bus is used and implemented.(Recommended)
Create a Classs that extends GWTEvent
Define a new handler and marker interface for the event class.
Register the event using EventBus where you implement interface( the one written inside the event class)
implement the interface method and call the event fire method
Architecture
1. Using
GWTP (Recommended)
http://code.google.com/p/gwt-platform/
2. MVP
Architecture(Recommended)
3. Using
GIN Dependency injector in GWT
What
are some advantages for the Model-View-Presenter pattern?
What
3d party libraries have used with GWT? Which libraries would you
recommend? Why?
GUICE - for Server side dependency injection
GIN - for client side dependency injection
GWTP - Model - View - Presenter framework
What does make MVP better fit for GWT than general MVC?
There are various design patterns to choose from; Presentation-abstraction-control, Model-view-controller, Model-view-presenter, etc... And while each pattern has its benefits, we have found that a Model-view-presenter (MVP) architecture works best when developing GWT apps for two main reasons. First the MVP model, much like other design patterns, decouples development in a way that allows multiple developers to work simultaneously. Secondly, this model allows us to minimize our use of GWTTestCase, which relies on the presence of a browser, and, for the bulk of our code, write lightweight (and fast) JRE tests (which don't require a browser).
GIN - for client side dependency injection
GWTP - Model - View - Presenter framework
What does make MVP better fit for GWT than general MVC?
There are various design patterns to choose from; Presentation-abstraction-control, Model-view-controller, Model-view-presenter, etc... And while each pattern has its benefits, we have found that a Model-view-presenter (MVP) architecture works best when developing GWT apps for two main reasons. First the MVP model, much like other design patterns, decouples development in a way that allows multiple developers to work simultaneously. Secondly, this model allows us to minimize our use of GWTTestCase, which relies on the presence of a browser, and, for the bulk of our code, write lightweight (and fast) JRE tests (which don't require a browser).
Performance(Recommended)
Code Splitting is easy
Fragment Merging
Using Spring Roo with GWT
(Recommended)
Spring roo auto generates
1. Server Component : Server Entity, Hibernate Configuration
2. Client Component : Injecting dependency using gin, RequestFactory, Client Proxy, UI, Activities, Place
Create your own entry point class and Reuse Code Related to Gin Injector, History Management, basic architecture.
Spring roo auto creates and updates domain model and request factory code.
For more information about how to quick set up project architecture using gwt and spring roo, you can freely contact me.
(To be Updated)
Subscribe to:
Posts (Atom)