SlideShare a Scribd company logo
1 of 56
Il framework Wicket Andrea Del Bene Jug Marche [email_address]
Quali sono i “guai” della programmazione web? ,[object Object],[object Object],[object Object]
L'HTTP è  stateless  e dobbiamo fare i salti mortali per associare uno stato alla navigazione di un utente sul nostro sito (di solito si ricorre all'oggetto Session)
Wicket: pagine come oggetto ,[object Object],[object Object],[object Object],[object Object]
Wicket VS Swing ,[object Object]
Dov'è finito l'HTML? ,[object Object],[object Object],[object Object]
Il file web.xml ,[object Object],[object Object],<? xml   version = &quot;1.0&quot;   encoding = &quot;UTF-8&quot; ?> <! DOCTYPE   web-app PUBLIC   &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot; &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot; > < web-app > < display-name > Wicket  HelloWorld </ display-name > < filter > < filter-name > WizardApplication </ filter-name > < filter-class > org.apache.wicket.protocol.http.WicketFilter </ filter-class > < init-param > < param-name > applicationClassName </ param-name > < param-value > helloWorld.WicketApplication </ param-value > </ init-param > </ filter > < filter-mapping > < filter-name > WizardApplication </ filter-name > < url-pattern > /* </ url-pattern > </ filter-mapping > </ web-app >
La classe WicketApplication package  helloWorld; import  org.apache.wicket.Page; import  org.apache.wicket.protocol.http.WebApplication; public   class  WicketApplication  extends  WebApplication { @Override public  Class<?  extends  Page> getHomePage() { return  HomePage. class ; } } ,[object Object],[object Object]
Pagina HelloWorld  ,[object Object],< html > < head > < meta   http-equiv = &quot;Content-Type&quot;   content = &quot;text/html; charset=UTF-8&quot; > < title > Insert title here </ title > </ head > < body > < h1   wicket:id = &quot;label&quot; ></ h1 > </ body > </ html > ,[object Object],package  helloWorld; import  org.apache.wicket.markup.html.WebPage; import  org.apache.wicket.markup.html.basic.Label; public   class  HomePage  extends  WebPage { public  HomePage(){ super (); add( new  Label( &quot;label&quot; ,  &quot;Hello World&quot; )); } } HelloWorld.html HelloWorld.java
WicketHelloWorld ,[object Object],... < body > < h1   wicket:id = &quot;label&quot; ></ h1 > </ body > ... ... public  HomePage(){ super (); add( new  Label( &quot;label&quot; ,  &quot;Hello World&quot; )); } ...
Wicket come template per layout ,[object Object],[object Object],[object Object]
Il framework Wicket ,[object Object]
Layout di una pagina web ,[object Object],Header Menù Contenuto Footer
L'approccio “classico” ,[object Object],<%@include file=&quot;../common/Jug4TendaHeader.jsp&quot;%> <%@include file= &quot;gestioneOspiteMenu.htm &quot;%> <div id=&quot;Content&quot;> <%@include file=&quot;../common/Jug4TendaFooter.jsp&quot;%>
Layout in Wicket ,[object Object],<div wicket:id=”headerPanel”></div> <div wicket:id=”menuPanel”> </div> <div wicket:id=”contentPanel”></div> <div wicket:id=”footerPanel”></div>
I pannelli di Wicket ,[object Object],[object Object]
Possono a loro volta contenere altri componenti ,[object Object],[object Object]
Il pannello header < html > < head > < meta   http-equiv = &quot;Content-Type&quot;   content = &quot;text/html; charset=UTF-8&quot; > < title > Insert title here </ title > </ head > < body > <wicket:panel> < table   width = &quot;100%&quot;   style = &quot;border: 0px none;&quot; > < tbody >< tr > < td >< img   alt = &quot;Jug4Tenda&quot;   src = &quot;wicketLayout_files/logo_jug4tenda.gif&quot; ></ td > < td >< h1 > Gestione   Anagrafica   Accoglienze </ h1 ></ td > < td >< img   alt = &quot;Associazione di volontariato La Tenda d'Abramo&quot;   src = &quot;wicketLayout_files/logo_latendadabramo.gif&quot; ></ td > </ tr > </ tbody > </ table > </wicket:panel> </ body > </ html >  HeaderPanel.html ,[object Object]
La classe del pannello header package  helloWorld.layoutTenda; import  org.apache.wicket.markup.html.panel.Panel; public   class   HeaderPanel   extends  Panel { public  HeaderPanel(String id) { super (id); } }  HeaderPanel.java ,[object Object],[object Object]
Il pannello footer … < wicket:panel > < span   class = &quot;piccolo&quot; > Powered by  </ span > < a   target = &quot;_blank&quot;   title = &quot;vai al sito dello JUG Ancona,..”   href = &quot;http://www.jugancona.it/&quot; > < img   title = &quot;vai al sito dello JUG Ancona, ...&quot;   alt = &quot;JUG Ancona, Java User    Group di Ancona&quot;   src = &quot;wicketLayout_files/logo_jugancona.gif&quot; ></ a > < img   title = &quot;JUG, Java User Group&quot;   alt = &quot;JUG, Java User Group&quot;     src = &quot;wicketLayout_files/logo_jug.gif&quot; > < a   title = &quot;vai al sito del framework Spring &quot;   href = &quot;http://www.springframework.org/&quot; > < img   title = &quot;vai al sito del framework Spring&quot;   alt = &quot;Spring&quot;   src = &quot;wicketLayout_files/logo_spring.gif&quot; ></ a > < a   title = &quot;vai al sito di Mozilla Firefox...&quot; href = &quot;http://www.mozilla.com/&quot; > < img   title = &quot;vai al sito di Mozilla Firefox...&quot;   alt = &quot;Firefox&quot;  src = &quot;wicketLayout_files/logo_firefox.gif&quot; ></ a > </ wicket:panel > …  FooterPanel.html package  helloWorld.layoutTenda; import  org.apache.wicket.markup.html.panel.Panel; public   class   FooterPanel   extends  Panel { public  FooterPanel(String id) { super (id); } }  HeaderPanel.java
Il pannello menu … <div class=&quot;menuTitle&quot;>Menu principale</div> <ul class=&quot;menuItems&quot;> <li> <img src=&quot;wicketLayout_files/home.gif&quot;> <a class=&quot;Offmouse&quot; href=&quot;http://localhost:8080/jug4tenda/index.jsp&quot;  id=&quot;newOspite&quot; onmouseout=&quot;this.className='Offmouse'&quot;  onmouseover=&quot;this.className='Onmouse'&quot;>Home</a></li> </ul> …  MenuPanel.html package  helloWorld.layoutTenda; import  org.apache.wicket.markup.html.panel.Panel; public   class  Menu Panel   extends  Panel { public  Menu Panel (String id) { super (id); } }  MenuPanel.java
La pagina template Jug4Wicket  package  helloWorld.layoutTenda; import  org.apache.wicket.markup.html.WebPage; public   class   JugTemplate   extends  WebPage { public  JugTemplate(){ add( new   HeaderPanel( &quot;headerPanel&quot; ) ); add( new   MenuPanel( &quot;menuPanel&quot; ) ); add( new   FooterPanel( &quot;footerPanel&quot; ) ); add( new   Label( &quot;contentComponent&quot;, &quot;content&quot; ) ); } } < html > < head > < meta   http-equiv = &quot;Content-Type&quot;   content = &quot;text/html; charset=UTF-8&quot; > < title > Jug4Tenda - Home page </ title > ...   </ head > < body > < div   id = &quot;intestazione&quot;   wicket:id = &quot;headerPanel&quot; > intestazione </ div > < div   id = &quot;pagina&quot; > < div   id = &quot;Menu&quot;   wicket:id = &quot;menuPanel&quot; > Menu </ div > < div   id = &quot;Content&quot;  wicket:id = &quot;content&quot; > Content </ div > </ div > < div   id = &quot;piedipagina&quot;   wicket:id = &quot;footerPanel&quot; > piedipagina </ div > </ body > </ html >
Demo
JavaScript e CSS in Wicket ,[object Object],< html > < head > < meta   http-equiv = &quot;Content-Type&quot;   content = &quot;text/html; charset=UTF-8&quot; > < title > Insert title here </ title > <wicket:head> <script>...</script> <wicket:head> ... </ head > < body > ... < wicket:panel > … </ wicket:panel > ...
Il framework Wicket ,[object Object]
L'ereditarietà delle pagine Wicket ,[object Object],[object Object],[object Object],package  helloWorld.layoutTenda; import  org.apache.wicket.markup.html.basic.Label; public   class  ChildPage  extends  JugTemplate { public  ChildPage(){ super (); addOrReplace( new  Label( &quot;contentComponent&quot; ,  &quot;L'ereditariatà  delle pagine Wicket e sia a livello di codice che di  html&quot; )); } }
Pagina “figlia” del template ,[object Object],addOrReplace( new  Label( &quot;contentComponent&quot; ,  &quot;L'ereditariatà  delle pagine Wicket e sia a livello di codice che di html&quot; ));
Il framework Wicket ,[object Object]
I Wicket link ,[object Object],[object Object],[object Object],add( new   Link( &quot;link&quot; ) { @Override public   void  onClick() { } });
I Wicket link 2 ,[object Object],[object Object],add( new   Link( &quot;link&quot; ) { @Override public   void  onClick() { setResponsePage(JugTemplate.class); } });
Il metodo onBeforeRender ,[object Object],[object Object],[object Object],Dopo il click il costruttore della pagina non verrà invocato mai il metodo onBeforeRender si!
Pagina di esempio sui Link ,[object Object],[object Object]
Codice della pagina di esempio public   class  HomePage  extends  WebPage { public   HomePage (){ super (); add( new  Label( &quot;label&quot; ,  &quot;Hello World&quot; )); add( new  Label( &quot;timeStamp&quot; ,  &quot;&quot;  +  new  Date())); add( new   Link( &quot;link&quot; ) { @Override public   void  onClick() { } }); add( new  Link( &quot;spanLink&quot; ){ @Override public   void  onClick() { } } ); .... @Override protected   void   onBeforeRender () { super .onBeforeRender(); addOrReplace( new  Label( &quot;timeStampFresh&quot; ,  &quot;&quot;  +  new  Date())); } }
Il framework Wicket ,[object Object]
Il ruolo del “model” in wicket 1 ,[object Object],[object Object],[object Object],public interface IModel { public Object getObject(); public void setObject(final Object object); }
Il ruolo del “model” in wicket 2 ,[object Object],[object Object],[object Object]
new  Model<Persona>( new   Persona( “Mario” ,  “Rossi” )); …
I Form di Wicket ,[object Object],[object Object],[object Object]
Il componente TextField ,[object Object],[object Object],[object Object],[object Object]
Classe Java
new  TextField<String>( “username” , new   Model<String>( “Inserisci  il tuo username” )); Codice HTML Username:  < input   type = &quot;text&quot;   wicket:id = &quot;username&quot; />
Prototipo maschera di login
Il pannello di login (HTML) < html > … < wicket:panel > < div   style = &quot;margin: auto; width: 40%&quot;   class = &quot;crop_content_contenuti&quot; > < form   id = &quot;ricerca&quot;   method = &quot;get&quot;   wicket:id = &quot;form&quot; > < fieldset   id = &quot;ricerca1&quot;   class = &quot;center&quot; > < legend   wicket:id = &quot;message&quot; > Ricerca </ legend > < p   wicket:id = &quot;loginStatus&quot;   style = &quot;font-weight: bold;color: red;text-align: left&quot; ></ p > < span > Username:  </ span > < input   wicket:id = &quot;username&quot;   type = &quot;text&quot;   id = &quot;username&quot;   />< br /> < span   > Password:  </ span > < input   wicket:id = &quot;password&quot;   type = &quot;password&quot;   id = &quot;password&quot;   /> < p > < input   type = &quot;submit&quot;   name = &quot;login&quot;   value = &quot;login&quot; /> </ p > </ fieldset > </ form > </ div > </ wicket:panel > … </ html > ,[object Object]
Il pannello e la form di login (Java) 1 public   class  LoginPanel  extends  Panel { public  LoginPanel(String id) { super (id); init(); } private   void  init(){ Form loginForm =  new  LoginForm( &quot;form&quot; ); add(loginForm); } } ,[object Object]
Il pannello e la form di login (Java) 2 public   class  LoginForm  extends  Form { private  TextField  usernameField  =  null ; private  PasswordTextField  passwordField  =  null ; private  Label  loginStatus  =  null ; public  LoginForm( final  String componentName) { super (componentName); usernameField  =  new  TextField( &quot;username&quot; ,  new  Model<String>( &quot;&quot; )); passwordField  =  new  PasswordTextField( &quot;password&quot; ,  new   Model<String>( &quot;&quot; )); loginStatus  =  new  Label( &quot;loginStatus&quot; ); add( usernameField ); add( passwordField ); add( new  Label( &quot;message&quot; ,  &quot;Login&quot; )); add( loginStatus ); } public   final   void  onSubmit() { String username =  usernameField .getValue(); String password =  passwordField .getValue(); if ((username.equals( &quot;Mario&quot; ) && password.equals( &quot;Rossi&quot; ))) loginStatus .setDefaultModel( new  Model<String>( &quot;Complimenti!&quot; )); else loginStatus .setDefaultModel( new  Model<String>( &quot;Username o    password errate!&quot; )); } Wicket dispone di un componente apposito per i campi password. L'evento onSubmit della form scatta prima di inviare i parametri della form al server.
Il pannello di login (Java) public   class  LoginPanel  extends  Panel { public  LoginPanel(String id) { super (id); init(); } private   void  init(){ Form loginForm =  new  LoginForm( &quot;form&quot; ); add(loginForm); } public   final   class  LoginForm  extends  Form { private  TextField  usernameField  =  null ; private  PasswordTextField  passwordField  =  null ; private  Label  loginStatus  =  null ; public  LoginForm( final  String componentName) { super (componentName); usernameField  =  new  TextField( &quot;username&quot; ,  new  Model<String>( &quot;&quot; )); passwordField  =  new  PasswordTextField( &quot;password&quot; ,  new  Model<String>( &quot;&quot; )); loginStatus  =  new  Label( &quot;loginStatus&quot; ); add( usernameField ); add( passwordField ); add( new  Label( &quot;message&quot; ,  &quot;Login&quot; )); add( loginStatus ); } public   final   void  onSubmit() { String username =  usernameField .getValue(); String password =  passwordField .getValue(); if ((username.equals( &quot;Mario&quot; ) && password.equals( &quot;Rossi&quot; ))) loginStatus .setDefaultModel( new  Model<String>( &quot;Complimenti!&quot; )); else loginStatus .setDefaultModel( new  Model<String>( &quot;Username o password errate!&quot; )); ... Wicket dispone di un componente apposito per i campi password. L'evento onSubmit della form scatta prima di inviare i parametri della form al server.
La pagina di login ,[object Object],package  helloWorld.layoutTenda; import  helloWorld.LoginPanel; import  org.apache.wicket.markup.html.basic.Label; public   class  LoginPage  extends  JugTemplate { public  LoginPage(){ super (); addOrReplace( new  LoginPanel( &quot;contentComponent&quot; )); } }
Demo
Il framework Wicket ,[object Object]
I repeat viewer
I bean come model Wicket ,[object Object],[object Object],[object Object],Esempio:  Vogliamo realizzare un pannello e con una form con dei semplici dati anagrafici (nome, cognome, indirizzo, email). Premendo submit la form: ,[object Object]
la aggiunge alla lista di istanze precedentemente create
visualizza le istanze della lista.
Il JavaBean Person package  helloWorld; import  java.io.Serializable; public   class   Person   implements  Serializable { private  String  name ; private  String  sureName ; private  String  address ; private  String  email ; public  String getAddress() { return   address ; } public   void  setAddress(String address) { this . address  = address; } public  String getEmail() { return   email ; } public   void  setEmail(String email) { this . email  = email; } public  String getName() { return   name ; } public   void  setName(String name) { this . name  = name; } public  String getSureName() { return   sureName ; } public   void  setSureName(String sureName) { this . sureName  = sureName; } }
La form class   CreatePerson   extends   Form { private  Person  person  =  new  Person(); public  Person getPerson() { return   person ; } public  CreatePerson(String id) { super (id); setDefaultModel( new  CompoundPropertyModel<Person>( this )); add( new  TextField<String>( &quot;person.name&quot; )); add( new  TextField<String>( &quot;person.sureName&quot; )); add( new  TextField<String>( &quot;person.address&quot; )); add( new  TextField<String>( &quot;person.email&quot; )); } @Override protected   void  onSubmit() { super .onSubmit(); personsArray .add( person ); person  =  new  Person(); } }
La form class   CreatePerson   extends   Form { private  Person  person  =  new  Person(); public  Person getPerson() { return   person ; } public  CreatePerson(String id) { super (id); setDefaultModel( new  CompoundPropertyModel<Person>( this )); add( new  TextField<String>( &quot;person.name&quot; )); add( new  TextField<String>( &quot;person.sureName&quot; )); add( new  TextField<String>( &quot;person.address&quot; )); add( new  TextField<String>( &quot;person.email&quot; )); } @Override protected   void  onSubmit() { super .onSubmit(); personsArray .add( person ); person  =  new  Person(); } } Si traduce in  getPerson().getPerson().set/getName , quindi il TextFiled legge/scrive direttamente sui campi dell'istanza di Person Uso la stessa form come modello per i miei dati ed avrò accesso ai sui campi La form sarà una inner class del pannello è vedrà la sua variabile  personsArray

More Related Content

Viewers also liked

Library essentials for year 1 Biochemical Engineers
Library essentials for year 1 Biochemical EngineersLibrary essentials for year 1 Biochemical Engineers
Library essentials for year 1 Biochemical EngineersLynne Meehan
 
Blogging
BloggingBlogging
Blogginggarylee
 
Inbound Marketing Agency Presentation
Inbound Marketing Agency PresentationInbound Marketing Agency Presentation
Inbound Marketing Agency Presentationmgower
 
Blogging
BloggingBlogging
Blogginggarylee
 
Inside Academy - Social Media &amp; Blogging
Inside Academy - Social Media &amp; BloggingInside Academy - Social Media &amp; Blogging
Inside Academy - Social Media &amp; Bloggingmgower
 
Lead Management and You
Lead Management and YouLead Management and You
Lead Management and Youkhagood
 

Viewers also liked (6)

Library essentials for year 1 Biochemical Engineers
Library essentials for year 1 Biochemical EngineersLibrary essentials for year 1 Biochemical Engineers
Library essentials for year 1 Biochemical Engineers
 
Blogging
BloggingBlogging
Blogging
 
Inbound Marketing Agency Presentation
Inbound Marketing Agency PresentationInbound Marketing Agency Presentation
Inbound Marketing Agency Presentation
 
Blogging
BloggingBlogging
Blogging
 
Inside Academy - Social Media &amp; Blogging
Inside Academy - Social Media &amp; BloggingInside Academy - Social Media &amp; Blogging
Inside Academy - Social Media &amp; Blogging
 
Lead Management and You
Lead Management and YouLead Management and You
Lead Management and You
 

Similar to Presentazione wicket

Similar to Presentazione wicket (20)

Lab Web Prof.Di Blasi 2008
Lab Web Prof.Di Blasi 2008Lab Web Prof.Di Blasi 2008
Lab Web Prof.Di Blasi 2008
 
Rich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in JqueryRich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in Jquery
 
react-it.pdf
react-it.pdfreact-it.pdf
react-it.pdf
 
Web writing 2
Web writing 2Web writing 2
Web writing 2
 
Presentazione Corso - Parte 1
Presentazione Corso - Parte 1Presentazione Corso - Parte 1
Presentazione Corso - Parte 1
 
Introduzione ad angular 7/8
Introduzione ad angular 7/8Introduzione ad angular 7/8
Introduzione ad angular 7/8
 
HTML5
HTML5HTML5
HTML5
 
Training Signal Webtrends
Training Signal WebtrendsTraining Signal Webtrends
Training Signal Webtrends
 
Many Designs Elements
Many Designs ElementsMany Designs Elements
Many Designs Elements
 
JSP Tag Library
JSP Tag LibraryJSP Tag Library
JSP Tag Library
 
JSP Tag Library
JSP Tag LibraryJSP Tag Library
JSP Tag Library
 
JSP Tag Library
JSP Tag LibraryJSP Tag Library
JSP Tag Library
 
Asp.Net MVC 3 - Il Model View Controller secondo Microsoft
Asp.Net MVC 3 - Il Model View Controller secondo MicrosoftAsp.Net MVC 3 - Il Model View Controller secondo Microsoft
Asp.Net MVC 3 - Il Model View Controller secondo Microsoft
 
Dal Click Al Web Server
Dal Click Al Web ServerDal Click Al Web Server
Dal Click Al Web Server
 
Fogli di stile CSS
Fogli di stile CSSFogli di stile CSS
Fogli di stile CSS
 
Ajax
AjaxAjax
Ajax
 
I Linguaggi Del Web (1° Giornata)
I Linguaggi Del Web (1° Giornata)I Linguaggi Del Web (1° Giornata)
I Linguaggi Del Web (1° Giornata)
 
Yagwto
YagwtoYagwto
Yagwto
 
HTML e CSS
HTML e CSSHTML e CSS
HTML e CSS
 
Asp.net 4 Community Tour VS2010
Asp.net 4 Community Tour VS2010Asp.net 4 Community Tour VS2010
Asp.net 4 Community Tour VS2010
 

Presentazione wicket

  • 1. Il framework Wicket Andrea Del Bene Jug Marche [email_address]
  • 2.
  • 3. L'HTTP è stateless e dobbiamo fare i salti mortali per associare uno stato alla navigazione di un utente sul nostro sito (di solito si ricorre all'oggetto Session)
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20. Il pannello footer … < wicket:panel > < span class = &quot;piccolo&quot; > Powered by </ span > < a target = &quot;_blank&quot; title = &quot;vai al sito dello JUG Ancona,..” href = &quot;http://www.jugancona.it/&quot; > < img title = &quot;vai al sito dello JUG Ancona, ...&quot; alt = &quot;JUG Ancona, Java User Group di Ancona&quot; src = &quot;wicketLayout_files/logo_jugancona.gif&quot; ></ a > < img title = &quot;JUG, Java User Group&quot; alt = &quot;JUG, Java User Group&quot; src = &quot;wicketLayout_files/logo_jug.gif&quot; > < a title = &quot;vai al sito del framework Spring &quot; href = &quot;http://www.springframework.org/&quot; > < img title = &quot;vai al sito del framework Spring&quot; alt = &quot;Spring&quot; src = &quot;wicketLayout_files/logo_spring.gif&quot; ></ a > < a title = &quot;vai al sito di Mozilla Firefox...&quot; href = &quot;http://www.mozilla.com/&quot; > < img title = &quot;vai al sito di Mozilla Firefox...&quot; alt = &quot;Firefox&quot; src = &quot;wicketLayout_files/logo_firefox.gif&quot; ></ a > </ wicket:panel > … FooterPanel.html package helloWorld.layoutTenda; import org.apache.wicket.markup.html.panel.Panel; public class FooterPanel extends Panel { public FooterPanel(String id) { super (id); } } HeaderPanel.java
  • 21. Il pannello menu … <div class=&quot;menuTitle&quot;>Menu principale</div> <ul class=&quot;menuItems&quot;> <li> <img src=&quot;wicketLayout_files/home.gif&quot;> <a class=&quot;Offmouse&quot; href=&quot;http://localhost:8080/jug4tenda/index.jsp&quot; id=&quot;newOspite&quot; onmouseout=&quot;this.className='Offmouse'&quot; onmouseover=&quot;this.className='Onmouse'&quot;>Home</a></li> </ul> … MenuPanel.html package helloWorld.layoutTenda; import org.apache.wicket.markup.html.panel.Panel; public class Menu Panel extends Panel { public Menu Panel (String id) { super (id); } } MenuPanel.java
  • 22. La pagina template Jug4Wicket package helloWorld.layoutTenda; import org.apache.wicket.markup.html.WebPage; public class JugTemplate extends WebPage { public JugTemplate(){ add( new HeaderPanel( &quot;headerPanel&quot; ) ); add( new MenuPanel( &quot;menuPanel&quot; ) ); add( new FooterPanel( &quot;footerPanel&quot; ) ); add( new Label( &quot;contentComponent&quot;, &quot;content&quot; ) ); } } < html > < head > < meta http-equiv = &quot;Content-Type&quot; content = &quot;text/html; charset=UTF-8&quot; > < title > Jug4Tenda - Home page </ title > ... </ head > < body > < div id = &quot;intestazione&quot; wicket:id = &quot;headerPanel&quot; > intestazione </ div > < div id = &quot;pagina&quot; > < div id = &quot;Menu&quot; wicket:id = &quot;menuPanel&quot; > Menu </ div > < div id = &quot;Content&quot; wicket:id = &quot;content&quot; > Content </ div > </ div > < div id = &quot;piedipagina&quot; wicket:id = &quot;footerPanel&quot; > piedipagina </ div > </ body > </ html >
  • 23. Demo
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33. Codice della pagina di esempio public class HomePage extends WebPage { public HomePage (){ super (); add( new Label( &quot;label&quot; , &quot;Hello World&quot; )); add( new Label( &quot;timeStamp&quot; , &quot;&quot; + new Date())); add( new Link( &quot;link&quot; ) { @Override public void onClick() { } }); add( new Link( &quot;spanLink&quot; ){ @Override public void onClick() { } } ); .... @Override protected void onBeforeRender () { super .onBeforeRender(); addOrReplace( new Label( &quot;timeStampFresh&quot; , &quot;&quot; + new Date())); } }
  • 34.
  • 35.
  • 36.
  • 37. new Model<Persona>( new Persona( “Mario” , “Rossi” )); …
  • 38.
  • 39.
  • 41. new TextField<String>( “username” , new Model<String>( “Inserisci il tuo username” )); Codice HTML Username: < input type = &quot;text&quot; wicket:id = &quot;username&quot; />
  • 43.
  • 44.
  • 45. Il pannello e la form di login (Java) 2 public class LoginForm extends Form { private TextField usernameField = null ; private PasswordTextField passwordField = null ; private Label loginStatus = null ; public LoginForm( final String componentName) { super (componentName); usernameField = new TextField( &quot;username&quot; , new Model<String>( &quot;&quot; )); passwordField = new PasswordTextField( &quot;password&quot; , new Model<String>( &quot;&quot; )); loginStatus = new Label( &quot;loginStatus&quot; ); add( usernameField ); add( passwordField ); add( new Label( &quot;message&quot; , &quot;Login&quot; )); add( loginStatus ); } public final void onSubmit() { String username = usernameField .getValue(); String password = passwordField .getValue(); if ((username.equals( &quot;Mario&quot; ) && password.equals( &quot;Rossi&quot; ))) loginStatus .setDefaultModel( new Model<String>( &quot;Complimenti!&quot; )); else loginStatus .setDefaultModel( new Model<String>( &quot;Username o password errate!&quot; )); } Wicket dispone di un componente apposito per i campi password. L'evento onSubmit della form scatta prima di inviare i parametri della form al server.
  • 46. Il pannello di login (Java) public class LoginPanel extends Panel { public LoginPanel(String id) { super (id); init(); } private void init(){ Form loginForm = new LoginForm( &quot;form&quot; ); add(loginForm); } public final class LoginForm extends Form { private TextField usernameField = null ; private PasswordTextField passwordField = null ; private Label loginStatus = null ; public LoginForm( final String componentName) { super (componentName); usernameField = new TextField( &quot;username&quot; , new Model<String>( &quot;&quot; )); passwordField = new PasswordTextField( &quot;password&quot; , new Model<String>( &quot;&quot; )); loginStatus = new Label( &quot;loginStatus&quot; ); add( usernameField ); add( passwordField ); add( new Label( &quot;message&quot; , &quot;Login&quot; )); add( loginStatus ); } public final void onSubmit() { String username = usernameField .getValue(); String password = passwordField .getValue(); if ((username.equals( &quot;Mario&quot; ) && password.equals( &quot;Rossi&quot; ))) loginStatus .setDefaultModel( new Model<String>( &quot;Complimenti!&quot; )); else loginStatus .setDefaultModel( new Model<String>( &quot;Username o password errate!&quot; )); ... Wicket dispone di un componente apposito per i campi password. L'evento onSubmit della form scatta prima di inviare i parametri della form al server.
  • 47.
  • 48. Demo
  • 49.
  • 51.
  • 52. la aggiunge alla lista di istanze precedentemente create
  • 53. visualizza le istanze della lista.
  • 54. Il JavaBean Person package helloWorld; import java.io.Serializable; public class Person implements Serializable { private String name ; private String sureName ; private String address ; private String email ; public String getAddress() { return address ; } public void setAddress(String address) { this . address = address; } public String getEmail() { return email ; } public void setEmail(String email) { this . email = email; } public String getName() { return name ; } public void setName(String name) { this . name = name; } public String getSureName() { return sureName ; } public void setSureName(String sureName) { this . sureName = sureName; } }
  • 55. La form class CreatePerson extends Form { private Person person = new Person(); public Person getPerson() { return person ; } public CreatePerson(String id) { super (id); setDefaultModel( new CompoundPropertyModel<Person>( this )); add( new TextField<String>( &quot;person.name&quot; )); add( new TextField<String>( &quot;person.sureName&quot; )); add( new TextField<String>( &quot;person.address&quot; )); add( new TextField<String>( &quot;person.email&quot; )); } @Override protected void onSubmit() { super .onSubmit(); personsArray .add( person ); person = new Person(); } }
  • 56. La form class CreatePerson extends Form { private Person person = new Person(); public Person getPerson() { return person ; } public CreatePerson(String id) { super (id); setDefaultModel( new CompoundPropertyModel<Person>( this )); add( new TextField<String>( &quot;person.name&quot; )); add( new TextField<String>( &quot;person.sureName&quot; )); add( new TextField<String>( &quot;person.address&quot; )); add( new TextField<String>( &quot;person.email&quot; )); } @Override protected void onSubmit() { super .onSubmit(); personsArray .add( person ); person = new Person(); } } Si traduce in getPerson().getPerson().set/getName , quindi il TextFiled legge/scrive direttamente sui campi dell'istanza di Person Uso la stessa form come modello per i miei dati ed avrò accesso ai sui campi La form sarà una inner class del pannello è vedrà la sua variabile personsArray
  • 57.
  • 58. Il pannello public class PersonsManager extends Panel { private List<Person> personsArray = new ArrayList<Person>(); public PersonsManager(String id, List<Person> personsArray) { super (id); add( new CreatePerson( &quot;form&quot; )); PageableListView<Person> persons = new PageableListView<Person>( &quot;persons&quot; , personsArray,30) { @Override protected void populateItem(ListItem<Person> personHtml) { personHtml.add( new Label( &quot;personName&quot; , personHtml.getModel().getObject().getName())); personHtml.add( new Label( &quot;personSurename&quot; , personHtml.getModel().getObject().getSureName())); personHtml.add( new Label( &quot;address&quot; , personHtml.getModel().getObject().getAddress())); personHtml.add( new Label( &quot;email&quot; , personHtml.getModel().getObject().getEmail())); } }; add(persons); this . personsArray = personsArray; } Il codice nell'ellisse è il repeat viewer che visualizza la lista di persone create
  • 59. Demo
  • 60.
  • 61. Rende le applicazioni web testabili molto più facilmente.
  • 62. Gestione dello stato trasparente.
  • 63. Grande varietà di componenti pronti all'uso.
  • 64.
  • 65. Documentazione utente e tutorial frammentari e scarni.
  • 66. ...
  • 67.
  • 69.
  • 70.
  • 71. Grazie ! Andrea Del Bene JUG Marche - www.jugancona.it