Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Articles
CreateActions_it
ValidationAndListSpr...




JSPWiki v2.2.33

[RSS]


Hide Menu

SpringControllers_it


Difference between version 9 and version 1:

At line 3 changed 1 line.
;:''Questo tutorial ha come precedenza __Parte II:__ [Creazione nuovi Manager|CreateManager_it].''
;:''Questo tutorial dipende da __Parte II:__ [Creazione nuovi Manager|CreateManager_it].''
At line 18 changed 1 line.
* [6] Crea i WebTest Canoo per il test delle azioni stile browser
* [6] Crea i WebTest Canoo per il test delle azioni con simulazione del browser
At line 26 changed 1 line.
* Esegui __ant -Dobject.name=Person -Dappgen.type=pojo -Dapp.module=__ per generare un po' di file in extras/appgen/build/gen. Di fatto, saranno generati tutti i file di cui hai bisogno per completare questo tutorial. In ogni caso prendi solo quelli necessari.
* Esegui __ant -Dobject.name=Person -Dappgen.type=pojo -Dapp.module=""__ per generare un po' di file in extras/appgen/build/gen. Di fatto, saranno generati tutti i file di cui hai bisogno per completare questo tutorial. In ogni caso prendi solo quelli necessari.
At line 53 changed 1 line.
;: ''The files in the "pages" directory will end up in "WEB-INF/pages" at deployment time. The container provides security for all files below WEB-INF. This applies to client requests, but not to forwards from the DispatchServlet. Placing all JSPs below WEB-INF ensures they are only accessed through Controllers, and not directly by the client or each other. This allows security to be moved up into the Controller, where it can be handled more efficiently, and out of the base presentation layer.''
;: ''I files nella directory "pages" finiranno in "WEB-INF/pages" a deployment time. Il container fornisce protezione per tutti i file sotto WEB-INF. Ciò si applica a tutte le richieste da client, ma non ai forward da DispatchServlet. Mettere tutte le JSP sotto WEB-INF assicura che vengano accedute solo tramite Controller, e non direttamente dal client o l'una con l'altra. Ciò permette di spostare la security in alto sul Controller, dove può essere gestita in modo più efficiente, e fuori dallo strato di presentazione di base.''
At line 55 changed 1 line.
The web application security for AppFuse specifies that all *.html url-patterns should be protected (except for /signup.html and /passwordHint.html). This guarantees that clients must go through an Action to get to a JSP (or at least the ones in ''pages'').
La security della web application per AppFuse specifica che tutti gli url-pattern *.html debbano essere protetti (eccetto /signup.html e /passwordHint.html). Ciò garantisce che i client passino da una Action per arrivare ad una JSP (o almeno a quelle sotto ''pages'').
At line 57 changed 1 line.
%%note __NOTE:__ If you want to customize the CSS for a particular page, you can add <body id="pageName"/> to the top of the file. This will be slurped up by SiteMesh and put into the final page. You can then customize your CSS on a page-by-page basis using something like the following:
%%note __NOTA:__ Se vuoi personalizzare i CSS per una data pagina, puoi aggiungere <body id="pageName"/> in cima al file. Questo verrà assimilato da SiteMesh e messo nella pagina finale. Puoi poi personalizzare il tuo CSS pagina per pagina usando qualcosa del tipo:
At line 60 changed 2 lines.
* Add keys in ApplicationResources.properties the titles and headings in the JSPs
In the generated JSPs, there are two keys for the title (top of the browser window) and the header (heading in the page). We now need to add these two keys (personDetail.title and personDetail.heading) to ApplicationResources.properties.
* Aggiungi chiavi in ApplicationResources.properties per titoli ed intestazioni nelle JSP
Nelle JSP generate ci sono due chiavi per il titolo (sulla finestra del browser in alto) e l'header (intestazione nella pagina). Ora dobbiamo aggiungere queste due chiavi (personDetail.title and personDetail.heading) ad ApplicationResources.properties.
At line 75 changed 1 line.
To create a JUnit Test for the PersonFormController, start by creating a PersonFormControllerTest.java file in the test/web/**/action directory.
Per creare un test JUnit per il PersonFormController, inizia a creare un file PersonFormControllerTest.java nella directory test/web/**/action.
At line 131 changed 1 line.
assertNotNull(request.getSession().getAttribute("messages"));
assertNotNull(request.getSession().getAttribute("successMessages"));
At line 139 changed 1 line.
assertNotNull(request.getSession().getAttribute("messages"));
assertNotNull(request.getSession().getAttribute("successMessages"));
At line 144 changed 1 line.
Nothing will compile at this point (ant compile) because you need to create the PersonFormController that you're referring to in this test.
A questo punto non compila nulla (con ant compile) perché devi creare il PersonFormController cui questo test si riferisce.
At line 149 changed 1 line.
In src/web/**/action, create a PersonFormController.java file with the following contents:
In src/web/**/action, crea un file PersonFormController.java file con il seguente contenuto:
At line 234 changed 1 line.
In the class above, there are a few methods you might not be familiar with. The {{formBackingObject()}} method is used to supply the object this Controller operates on. The {{processFormSubmission()}} method is used to detect the cancel button, and {{onSubmit()}} is called on POST requests and handles delete/add/update of a user.
Nella classe sopra ci sono alcuni metodi con i quali potresti non essere familiare. Il metodo {{formBackingObject()}} viene usato per fronire l'oggetto sul quale opera questo Controller. Il metodo {{processFormSubmission()}} viene usato per rilevare il bottone cancel, ed {{onSubmit()}} viene chiamate sulle richieste POST e gestisce il delete/add/update di un utente.
At line 236 changed 1 line.
There are a few keys you (might) need to add to ApplicationResources.properties to display the success messages. This file is located in ''web/WEB-INF/classes'' - open it and add the following:
Ci sono alcune chiavi che dovresti (eventualmente) aggiungere ad ApplicationResources.properties per visualizzare i messaggi di successo. Questo file si trova in ''web/WEB-INF/classes'' - aprilo ed aggiungi quanto segue:
At line 238 changed 1 line.
;:''I usually add these under the {{# -- success messages --}} comment.''
;:''Di solito li aggiungo sotto il commento {{# -- success messages --}}.''
At line 245 changed 1 line.
You could use generic ''added'', ''deleted'' and ''updated'' messages, whatever works for you. It's nice to have separate messages in case these need to change on a per-entity basis.
Potresti usare anche dei messaggi generici di ''added'', ''deleted'' ed ''updated'', qualsiasi cosa funzioni per te. Va bene avere messaggi separati nel caso sia necessario modificarli per entità.
At line 247 changed 1 line.
You might notice that the code we're using to call the PersonManager is the same as the code we used in our PersonManagerTest. Both PersonFormController and PersonManagerTest are ''clients'' of PersonManagerImpl, so this makes perfect sense.
Come puoi notare il codice per chiamare il PersonManager è lo stesso utilizzato nel PersonManagerTest. Sia PersonFormController che PersonManagerTest sono ''client'' di PersonManagerImpl, pertanto ciò ha perfettamente senso.
At line 249 changed 1 line.
Now you need to add a url-mapping for this controller in the web/WEB-INF/action-servlet.xml file. In the block below, the new line is at the bottom, with __<prop key="/editPerson.html">__:
Ora devi aggiungere una url-mapping per questo controller nel file web/WEB-INF/action-servlet.xml. Nel blocco sotto la nuova riga è alla fine, con __<prop key="/editPerson.html">__:
At line 270 changed 1 line.
You also need to add the <bean> definition for personFormController in this same file:
Devi anche aggiungere la definizione <bean> per il personFormController nello stesso file:
At line 284 changed 1 line.
;:''The "validator" property is commented out in the above XML block because we haven't defined any validation rules for the Person object. We'll uncomment this value when we add validation.''
;:''La proprietà "validator" è commentate nel blocco XML sopra in quanto non abbiamo ancora definito alcuna regola di validazione per l'oggetto Person. Decommenteremo questo valora quando aggiungiamo la validazione.''
At line 286 changed 2 lines.
!!Run the PersonFormControllerTest [#4]
If you look at our PersonFormControllerTest, all the tests depend on having a record with id=1 in the database (and testRemove depends on id=2), so let's add those records to our sample data file (metadata/sql/sample-data.xml). I'd just add it at the bottom - order is not important since it (currently) does not relate to any other tables.
!!Esegui il PersonFormControllerTest [#4]
Se osservi il PersonFormControllerTest, tutti i test dipendono dall'avere un record con id=1 nel database (e testRemove depende da uno con id=2), pertanto aggiungiamo tali record al nostro file di dati di esempio (metadata/sql/sample-data.xml). Lo aggiungerei giusto alla fine - l'ordine non è importante in quanto (al momento) non ci sono relazioni con altre tabelle.
At line 307 changed 1 line.
DBUnit loads this file before we running any of the tests, so this record will be available to your Controller test.
DBUnit carica questo file prima di eseguire un qualsiasi test, pertanto questo record sarà disponibile per il test del tuo Controller.
At line 309 changed 1 line.
Make sure are in the base directory of your project. If you run __ant test-web -Dtestcase=PersonFormController__ - everything should work as planned.
Controlla di essere nella directory base del progetto. Se esegui __ant test-web -Dtestcase=PersonFormController__ - tutto dovrebbe funzionare come previsto.
At line 315 changed 1 line.
!!Clean up the JSP to make it presentable [#5]
!!Ripulisci la JSP per renderla presentabile [#5]
At line 317 changed 1 line.
If you want to add a usability enhancement to your form, you can set the cursor to focus on the first field when the page loads. Simply add the following JavaScript at the bottom of your form:
Se vuoi aggiungere un miglioramento in usabilità del tuo form, puoi impostare il cursore in modo da avere il focus sul primo campo al caricamento della pagina. Basta che aggiungi il JavaScript seguente in fondo al tuo form:
At line 320 changed 1 line.
document.forms["person"].elements["firstName"].focus();
Form.focusFirstElement($('personForm'));
At line 323 changed 1 line.
Now if you execute __ant db-load deploy__, start Tomcat and point your browser to [http://localhost:8080/appfuse/editPerson.html?id=1], you should see something like this:
Ora se esegui __ant db-load deploy__, avvii Tomcat e punti il browser su [http://localhost:8080/appfuse/editPerson.html?id=1], dovresti vedere qualcosa del genere:
At line 329 changed 1 line.
Finally, to make this page more user friendly, you may want to add a message for your users at the top of the form, but this can easily be done by adding text (using <fmt:message>) at the top of the personForm.jsp page.
Infine, per rendere questa pagina più user friendly, puoi aggiungere un messaggio per i tuoi utenti ad inizion form, ciò può essere fatto facilmente aggiungendo del testo (usando <fmt:message>) all'inizio della pagina personForm.jsp.
At line 331 changed 2 lines.
!![[Optional] Create a Canoo WebTest to test browser-like actions [#6]
The final (optional) step in this tutorial is to create a [Canoo WebTest|http://webtest.canoo.com] to test the JSPs.
!![[Opzionale] Crea i WebTest Canoo per il test delle azioni con simulazione del browser [#6]
Il passo finale (opzionale) in questo tutorial è la creazione di un [WebTest Canoo|http://webtest.canoo.com] per il test delle JSP.
At line 334 changed 1 line.
;:''I say this step is optional, because you can run the same tests through your browser.''
;:''Dico che questo passo è opzionale, in quanto puoi eseguire gli stessi test navigando direttamente dal tuo browser.''
At line 336 changed 1 line.
You can use the following URLs to test the different actions for adding, editing and saving a user.
Puoi usare le seguenti URL per il test delle varie azioni di aggiunta, modifica e registrazione utente.
At line 338 changed 4 lines.
* Add - [http://localhost:8080/appfuse/editPerson.html].
* Edit - [http://localhost:8080/appfuse/editPerson.html?id=1] (make sure and run __ant db-load__ first).
* Delete - [http://localhost:8080/appfuse/editPerson.html?method=Delete&id=1] (or edit and click on the Delete button).
* Save - Click [edit|http://localhost:8080/appfuse/editPerson.html?id=1] and then click the Save button.
* Aggiungi - [http://localhost:8080/appfuse/editPerson.html].
* Modifica - [http://localhost:8080/appfuse/editPerson.html?id=1] (assicurati di eseguire prima __ant db-load__).
* Elimina - [http://localhost:8080/appfuse/editPerson.html?method=Delete&id=1] (o modifica e fai clic sul pulsante Elimina).
* Registra - Fai clic su [modifica|http://localhost:8080/appfuse/editPerson.html?id=1] e poi fai clic sul pulsante Registra.
At line 343 changed 1 line.
Canoo tests are pretty slick in that they're simply configured in an XML file. To add tests for add, edit, save and delete, open test/web/web-tests.xml and add the following XML. You'll notice that this fragment has a target named ''PersonTests'' that runs all the related tests.
I test Canoo sono molto comodi perché si configurano semplicemente in un file XML. Per aggiungere test per le operazioni di aggiungi, modifica, registra ed elimina, apri test/web/web-tests.xml ed aggiungi il seguente XML. Noterai che questo frammento ha un target denominato ''PersonTests'' che esegue tutti i test correlati.
At line 345 changed 1 line.
;:''I use CamelCase target names (vs. the traditional lowercase, dash-separated) because when you're typing ''-Dtestcase=Name'', I've found that I'm used to doing CamelCase for my JUnit Tests.''
;:''Uso nomi di target in CamelCase (al posto del tradizionale lowercase, separato da trattini) perché quanto digiti ''-Dtestcase=Nome'', ho scoperto che sono abituato ad usare il CamelCase come per i miei test JUnit.''
At line 349 changed 1 line.
<!-- runs person-related tests -->
<!-- esegui i test relativi a person -->
At line 356 changed 1 line.
<!-- Verify the edit person screen displays without errors -->
<!-- Verifica che la schermata di modifica persona sia visualizzata senza errori -->
At line 370 changed 1 line.
<!-- Edit a person and then save -->
<!-- Modifica una persona e poi registra -->
At line 381 changed 1 line.
<clickbutton label="Save" description="Click Save"/>
<clickbutton label="${button.save}" description="Click Save"/>
At line 389 changed 1 line.
<!-- Add a new Person -->
<!-- Aggiungi un nuovo oggetto Person -->
At line 409 changed 1 line.
<!-- Delete existing person -->
<!-- Elimina persona esistente -->
At line 427 changed 1 line.
After adding this, you should be able to run __ant test-canoo -Dtestcase=PersonTests__ with Tomcat running or __ant test-jsp -Dtestcase=PersonTests__ if you want Ant to start/stop Tomcat for you. To include the PersonTests when all Canoo tests are run, add it as a dependency to the "run-all-tests" target.
Dopo aver aggiunto quanto sopra, dovresti poter eseguire __ant test-canoo -Dtestcase=PersonTests__ con Tomcat attivo o __ant test-jsp -Dtestcase=PersonTests__ se vuoi che Ant avvii e fermi Tomcat per te. Per includere PersonTests quando vengono eseguiti tutti i test Canoo, aggiungilo come dipendenza al target "run-all-tests".
At line 429 changed 1 line.
You'll notice that there's no logging in the client-side window by Canoo. If you'd like to see what it's doing, you can add the following between &lt;/webtest&gt; and &lt;/target&gt; at the end of each target.
;:''I test Canoo funzionano solo se è configurato almeno un tag XDoclet per la validazione dell'input, come spiegato nel prossimo tutorial [Aggiungere Validazione e Schermata Elenco|ValidationAndListSpring_it]. In alternativa eliminare in personForm.jsp la chiamata alla funzione JavaScript validatePerson sull'evento onsubmit del form.''
At line 431 added 2 lines.
Noterai che non c'è alcun log nella finestra lato client generato da Canoo. Se vuoi vedere cosa sta facendo, puoi aggiungere le righe seguenti fra &lt;/webtest&gt; e &lt;/target&gt; alla fine di ogni target.
At line 441 changed 1 line.
''Next Up:'' __Part IV:__ [Adding Validation and List Screen|ValidationAndListSpring] - Adding validation logic to the personForm so that firstName and lastName are required fields and adding a list screen to display all person records in the database.
''Prossimo:'' __Parte IV:__ [Aggiungere Validazione e Schermata Elenco|ValidationAndListSpring_it] - Aggiungere logica di convalida al personForm in modo che firstName e lastName siano campi obbligatori ed aggiungere una schermata elenco per visualizzare tutti i record nel database.

Back to SpringControllers_it, or to the Page History.