67. public class Vaadin6App extends Application {
public void init() {
setMainWindow(createWindow());
}
public Window getWindow(String name) {
Window window = super.getWindow(name);
if (window == null) {
window = createWindow();
window.setName(name);
addWindow(window);
}
return window;
}
private Window createWindow() {
Window window = new Window("Vaadin 6 Application");
window.addComponent(new TextField("What is your name"));
window.addComponent(new Button("Do not push me"));
return window;
}
}
68. @Title("Vaadin 7 Application")
public class Vaadin7uiUI extends UI {
@Override
public void init(VaadinRequest request) {
addComponent(new TextField("What is your name"));
addComponent(new Button("Do not push me"));
}
}
75. public class Employee {
String firstName;
String lastName;
double salary;
6
Date birthDate;
// Getters, setters, …
}
Form form = new Form();
form.setItemDataSource(
new BeanItem<Employee>(employee));
76.
77.
78. form.setFormFieldFactory(new FormFieldFactory() {
public Field createField(Item item, Object propertyId,
Component uiContext) {
if ("birthDate".equals(propertyId)) {
6
DateField df = new DateField();
df.setResolution(DateField.RESOLUTION_DAY);
return df;
}
// ..
return DefaultFieldFactory.createFieldByPropertyType(item
.getItemProperty(propertyId).getType());
}
});
79. 7
GridLayout form = new GridLayout(2,2) {
TextField firstName = new TextField("First name");
TextField lastName = new TextField("Last name");
TextField salary = new TextField("Salary");
DateField birthDate = new DateField("Birth date");
{
birthDate.setResolution(Resolution.DAY);
setSpacing(true);
addComponent(firstName);
addComponent(lastName);
addComponent(birthDate);
addComponent(salary);
}
};
BeanFieldGroup<Employee> fieldGroup = new BeanFieldGroup<Employee>(Employee.class);
fieldGroup.bindMemberFields(form);
fieldGroup.setItemDataSource(new BeanItem<Employee>(employee));
80. public class Person {
@Size(min = 5, max = 50)
private String name;
@Min(0)
@Max(100)
private int age;
// + constructor + setters + getters
}
82. final TextField textField = new TextField("Name");
textField.setConverter(new StringToNameConverter());
// ....
Name name = (Name) textField.getConvertedValue();
83. public class StringToNameConverter implements Converter<String, Name> {
public Name convertToModel(String text, Locale locale)
throws ConversionException {
// do the conversion
}
public String convertToPresentation(Name name, Locale locale)
throws ConversionException {
// do the conversion
}
public Class<Name> getModelType() {
return Name.class;
}
public Class<String> getPresentationType() {
return String.class;
}
}
89. Publish API from Java
getPage().getJavaScript().addCallback("myCallback",
new JavaScriptCallback() {
public void call(JSONArray arguments) throws JSONException {
// Do something with the arguments
}
});
Use from JavaScript
window.myCallback('foo', 100);
90. Widget implementation in JavaScript
window.com_example_MyWidget = function() {
var element = $(this.getWidgetElement());
// Draw a plot for any server-side (plot data) state change
this.onStateChange = function() {
$.plot(element, this.getState().series, {grid: {clickable: true}});
}
// Communicate local events back to server-side component
element.bind('plotclick', function(event, point, item) {
if (item) {
var onPlotClick = this.getCallback("plotClick");
onPlotClick(item.seriesIndex, item.dataIndex);
}
});
}
91. Server-side Java API for Widget
public class MyWidget extends AbstractJavaScriptComponent {
public MyWidget() {
registerCallback("plotClick", new JavaScriptCallback() {
public void call(JSONArray arguments) throws JSONException {
// Do something with the event
}
});
}
public static class MyWidgetState extends ComponentState {
public List<List<List<Double>>> plotSeriesData =
new ArrayList<List<List<Double>>>();
// getters & setters
}
}
97. aadin
with V nroo
s
ted o Grö
#85
gStar By Mark
ttin
DE:
Ge
LU rnal
INC Exte urces
NTS o
CO NTE Res
adin tion
m
ut Va p plica
Abo An A
o
ting
C re a
rd z . c
s
nent nts
Co mpo m pone Web ser File urces
t Co Brow -Side Res
o
ayou ...
L m o re t
Clien e ntai
ner
a
es nd Co
Them inding a Engi
n sts rvlet
fc
eque Se
B AX R
AJ
Data
i t re
ent
opm efau
lt
d evel us t like n Java t Data g D
me
IN ation ations j The
in
Vis
.A Bind
ervle
AAD pplic pplic ing
or Sw ined
S
UT V eb a
n
a UI nt atio
O xw eb WT pone Inhe
rits
pplic ces
AB e Aja o build w uch as A onta n Com A
our
z!
atio
ve r-sid u t s, s ne nts c A pplic es pp licat
ion Res
a ser
ang
s yo work e compo
d
s Ch A
Clas mes
in is allow p frame ts The
fcar
c Even ata
Vaad ork that eskto terfa n D
del
me w al d us er in s. ru ns o Inhe
rits
E vent r Mo
fra i t i o n u i l t f ro m nent code d by a Liste
ne
trad mpo tion
Re
b l e ser
with ut co plica r n
on is hand nt-serve
U io
licat base
pl icati lly in layo , th e ap tio n is lie s
App Data
ap ica odel terac er. The
c
ch a
e
r a rc h en m l user in s s, su he s
ject
r
hie riv w ie ation
er-d tua e bro chnolog per. As t s no pplic on ob on with
t Mo
e se
rv c
the a ning in
th te lo ei aadi
nA licati
In th hile n ient-
side deve ser, ther for V
to the app e applicati
er, w ngine ru the he itect
ure
serv n y c l i s i b l e t o t h e b ro w h e A p a c Arch ence ched to th
a
side
e
and
a
nv t re 2: refer
get a onent atta
Ge
in nder
cl i e n t - i c a t i o n s i p t , a re i ript u Figu
an
n r vaSc sed You c y comp
co m m u d J a v a S c u n s a s J a n i s re l e a Web face
L an
HTM ide eng ug-ins. V
in er a adi Ser vice Ho t from an user
inter le
with hand
t-s
clien o install
pl You r
EJB Tip tion u ca
n
ava n terac which yo
need
t in J
licat
io er in ts,
2.0. Vaad App ers
en n mode side even l, us ith
L icen
s e
va UI ents B t List rive er - t ton w
pon
Even event-d gers serv
Ja D
a bu
Web r Com s for
Web ser
Serv
e
In th
e trig vent
w
Bro -Side ents s . le c lick e
pon ener hand
lient com t list e
C
ne can even w, w
Engi
ugh , you with belo
WT) ple
t eno olkit (G exam s class:
m
ure
hitec
t is no To the u