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




JSPWiki v2.2.33

[RSS]


Hide Menu

ValidationAndList_it


Difference between version 7 and version 4:

At line 1 changed 1 line.
__Parte IV:__ [Aggiungere Validazione e Schermata Elenco|ValidationAndList_it] - Aggiungere un logica di validazione al PersonForm in modo che firstName e lastName siano campi obbligatori ed aggiungere una schermata di elenco per visualizzare tutti i record di tipo person nel database.
__Parte IV:__ [Aggiungere la Validazione ed una Schermata Elenco|ValidationAndList_it] - Aggiungere una logica di validazione al PersonForm in modo che firstName e lastName siano campi obbligatori ed aggiungere una schermata di elenco per visualizzare tutti i record di tipo person nel database.
At line 22 changed 1 line.
Per usare il Validator di Struts, normalmente devi scrivere un file validation.xml a mano. Se non stai usando AppFuse, devi anche configurare il Plugin Validator e le chiavi degli errori nel tuo ApplicationResources.properties. Per ulteriori informazioni sull'argomento, vedi il [Tutorial Validation Made Easy|http://www.reumann.net/struts/lesson3/step8.do] (c'è anche un [ricco insieme di tutorial|http://www.reumann.net/struts/main.do] per Struts da solo).
Per usare il Validator di Struts, normalmente devi scrivere un file validation.xml a mano. Se non stai usando AppFuse, devi anche configurare il Plugin Validator e le chiavi degli errori nel tuo ApplicationResources.properties. Per ulteriori informazioni sull'argomento, vedi il [Tutorial Validation Made Easy|http://www.learntechnology.net/struts-lesson-3.do] (c'è anche un [ricco insieme di tutorial|http://www.learntechnology.net/struts-lesson-1.do] sul solo Struts).
At line 45 changed 1 line.
Puoi anche aggiungere un attributo ''msgkey'' a questo tag per fare l'override della chiave di default relativa al messaggio associato a questo errore.
Puoi anche aggiungere un attributo ''msgkey'' a questo tag per fornire una tua chiave in alternativa a quella di default per il messaggio associato a questo errore.
At line 54 changed 1 line.
Ora se registru Person.java ed esegui __ant clean webdoclet__, verrà generato un file validation.xml in build/appfuse/WEB-INF/. Il suo contenuto dovrebbe includere una voce per "personForm".
Ora se registri Person.java ed esegui __ant clean webdoclet__, verrà generato un file validation.xml in build/appfuse/WEB-INF/. Il suo contenuto dovrebbe includere una voce per "personForm".
At line 167 changed 1 line.
Now add the same method signature to src/service/**/service/__PersonManager.java__. Save all your files and adjust the imports in your tests. Next you need to implement the getPeople() method in your implementation classes. Open src/dao/**/dao/hibernate/PersonDaoHibernate.java and add the following method:
Ora aggiungi la medesima firma di metodo a src/service/**/service/__PersonManager.java__. Registra tutti i tuoi file e correggi gli import nei tuoi test. Come passo successivo devi implementare il metodo getPeople() nelle tue classi di implementazione. Apri src/dao/**/dao/hibernate/PersonDaoHibernate.java ed aggiungi il metodo seguente:
At line 177 changed 1 line.
You'll notice here that nothing is being done with the ''person'' parameter. This is just a placeholder for now - in the future you may want to filter on it's properties using [Hibernate's Query Language|http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html] (HQL) or using [Criteria Queries|http://www.hibernate.org/hib_docs/reference/en/html/querycriteria.html].
Noterai qui che che nulla è stato fatto con il parametro ''person''. Per il momento è solo un segnaposto - nel futuro potresti voler filtrare in base alle sue proprità usando il [Linguaggio di Query di Hibernate|http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html] (HQL) o le [Query per Criteri|http://www.hibernate.org/hib_docs/reference/en/html/querycriteria.html].
At line 179 changed 1 line.
''An example using a Criteria Query:''
''Un esempio che usa le Query per Criteri:''
At line 195 changed 1 line.
Now implement the ''getPeople()'' method in src/service/**/impl/PersonManagerImpl.java:
Ora implementa il metodo ''getPeople()'' in src/service/**/impl/PersonManagerImpl.java:
At line 204 changed 1 line.
After saving all your changes, you should be able to run both tests by executing the following:
Dopo aver registrato tutte le tue modifiche, dovresti essere in grado di eseguire entrambi i test eseguendo i seguenti comandi:
At line 209 changed 1 line.
If everything works - ''nice job!'' Now you need to add this ''retrieve all'' functionality to the web tier.
Se funziona tutto - ''ottimo lavoro!'' Ore devi aggiungere questa funzionalità di ''recupera tutto'' allo strato web.
At line 212 changed 1 line.
Open test/web/**/action/PersonActionTest.java and add the following method:
Apri test/web/**/action/PersonActionTest.java ed aggiungi il metodo seguente:
At line 228 changed 1 line.
This class will not compile until you add the PERSON_LIST variable to the src/dao/**/Constants.java file.
Questa classe non compilerà finché non aggiungi la variabile PERSON_LIST al file src/dao/**/Constants.java.
At line 230 changed 1 line.
;:%%(color: blue)''I usually copy a similar variable that already exists in this file - i.e. USER_LIST.''
;:%%(color: blue)''Di solito io copio una variabile analoga già esistente in questo file - i.e. USER_LIST.''
At line 240 changed 1 line.
Now save all your changes. You won't be able to run __ant test-web -Dtestcase=PersonAction__ yet since ''PersonAction.search()'' does not exist (yet).
Ora registra tutte le tue modifiche. Non puoi ancora eseguire __ant test-web -Dtestcase=PersonAction__ in quanto ''PersonAction.search()'' non esiste (per il momento).
At line 243 changed 1 line.
Open src/web/**/action/PersonAction.java and add the following XDoclet tag at the top - to forward to our list screen.
Apri src/web/**/action/PersonAction.java ed aggiungi il seguente tag XDoclet in cima - per impostare il forward alla nostra schermata di elenco.
At line 250 changed 1 line.
Now add the search method to the body of the PersonAction class.
Ora aggiungi il metodo search all'interno dell classe PersonAction.
At line 252 changed 1 line.
;:%%(color: blue)''I used UserAction.search() as a template for this method.''
;:%%(color: blue)''Ho utilizzato UserAction.search() come modello per questo metodo.''
At line 273 changed 1 line.
Run __ant test-web -Dtestcase=PersonAction__.
Esegui __ant test-web -Dtestcase=PersonAction__.
At line 275 changed 1 line.
__Nice!__
__Bene!__
At line 280 changed 1 line.
Open the personList.jsp file in ''web/pages''. You'll probably want to change the code to show the plural form of the items you're listing. The generated name in this example is "persons" and it should probably be people. At or near line 31, you should have the following line:
Apri il file personList.jsp in ''web/pages''. Molto probabilmente vorrai modificare il codice in modo da visualizzare la forma plurale degli elementi che stai elencando. Il nome generato in questo esempio è "persons" e probabilmente sarebbe meglio fosse people. Alla riga 31 o vicino ad essa, dovresti avere la seguente:
At line 284 changed 1 line.
Change it to:
Modificala in:
At line 288 changed 1 line.
Finally, add the title and heading keys (personList.title and personList.heading) to web/WEB-INF/classes/ApplicationResources.properties. Open this file and add the following:
Infine, aggiungi le chiavi per titolo ed intestazione (personList.title e personList.heading) a web/WEB-INF/classes/ApplicationResources.properties. Apri questo file ed aggiungi quanto segue:
At line 296 changed 2 lines.
As a reminder, the {{personList.title}} is what ends up in the brower's title bar (the <title> tag) and
{{personList.heading}} will be put into an &lth1> tag before any page content.
Come promemoria, il {{personList.title}} è ciò che finisce nella barra del titolo del tuo browser (il tah <title>) e
{{personList.heading}} verrà messo in un tag &lth1> prima di qualsiasi contenuto della pagina.
At line 299 changed 1 line.
At this point, you should be able to run __ant clean deploy__, start Tomcat and view this page in your browser at [http://localhost:8080/appfuse/editPerson.html?method=Search].
A questo punto, dovresti essere in grado di eseguire __ant clean deploy__, avvia Tomcat e vedi la pagina nel tuo browser su [http://localhost:8080/appfuse/editPerson.html?method=Search].
At line 301 changed 1 line.
Now that we have a List Screen, let's change the pages that are displayed after adding and deleting a new Person. In src/web/**/action/PersonAction.java, change the ''mapping.findForward("mainMenu")'' in the ''save'', ''delete'' and ''cancel'' methods to be:
Ora che abbiamo un Schermata Elenco, modifichiamo le pagine che sono visualizzate all'aggiunta di una nuova Person e alla sua eliminazione. In src/web/**/action/PersonAction.java, modifica il ''mapping.findForward("mainMenu")'' nei metodi ''save'', ''delete'' e ''cancel'' in modo che diventi:
At line 308 changed 1 line.
You will also need to change ''verifyForward("mainMenu")'' to be ''verifyForward("viewPeople")'' in the testRemove method of test/web/**/action/PersonActionTest.java. Lastly, the Canoo tests "AddPerson" and "DeletePerson" need to be updated. Open test/web/web-tests.xml and change the following line in the "AddPerson" target:
Devi anche modificare ''verifyForward("mainMenu")'' in ''verifyForward("viewPeople")'' nel metodo testRemove di test/web/**/action/PersonActionTest.java. Per ultimo, i test Canoo "AddPerson" e "DeletePerson" devono essere aggiornati. Apri test/web/web-tests.xml e modifica la seguente riga nel target "AddPerson":
At line 313 changed 1 line.
to:
in:
At line 318 changed 1 line.
Then in the "DeletePerson" target, change the following line:
Poi nel target "DeletePerson", modifca la seguente riga:
At line 324 changed 1 line.
to:
in:
At line 328 changed 1 line.
Finally, declare the viewPeople forward in metadata/web/global-forwards.xml after viewUsers as below:
Infine, dichiara il forward viewPeople in metadata/web/global-forwards.xml dopo viewUsers come qui sotto:
At line 332 changed 1 line.
The name "viewPeople" is used instead of "list" so that the search method will be executed, rather than simply forwarding to the personForm.jsp (which the "list" forward points to).
Il nome "viewPeople" viene usato al posto di "list" in modo che venga eseguito il metodo search, invece di effettuare un semplice forward alla personForm.jsp (cui punta il forward "list").
At line 334 changed 1 line.
To test that displaying this page works, create a new JSP test in test/web/web-tests.xml:
Per verificare che la visualizzazione di questa pagina funzioni, crea un nuovo test JSP in test/web/web-tests.xml:
At line 355 changed 1 line.
You'll also want to add the "SearchPeople" target to the "PersonTests" target so it will be executed along with all the other person-related tests.
Vorrai anche aggiungere il target "SearchPeople" al target "PersonTests" in modo che venga eseguito insieme agli altri test relativi a person.
At line 367 changed 1 line.
Now you can run __ant test-canoo -Dtestcase=SearchPeople__ (or ''ant test-jsp'' if Tomcat isn't running) and hopefully it will result in "BUILD SUCCESSFUL". If so - ''nice work!''
Ora puoi eseguire __ant test-canoo -Dtestcase=SearchPeople__ (o ''ant test-jsp'' se Tomcat non è in esecuzione) e sperabilmente otterrai come risultato un "BUILD SUCCESSFUL". Se è così - ''ottimo lavoro!''
At line 370 changed 1 line.
The last step is to make the list, add, edit and delete functions visible to the user. The simplest way is to add a new link to the list of links in web/pages/mainMenu.jsp:
L'ultimo passo è rendere visibili all'utente le funzioni di elenco, aggiunta, modifica ed eliminazione. Il modo più semplice è aggiungere un nuovo collegamento all'elenco di collegamenti in web/pages/mainMenu.jsp:
At line 373 changed 1 line.
%%note __NOTE:__ The other links in mainMenu.jsp don't use <html:link> so this JSP can be shared among the various web framework implementations in AppFuse (i.e. Spring MVC and WebWork).%%
%%note __NOTA:__ Gli altri collegamenti in mainMenu.jsp non usano <html:link> in modo che questa JSP possa essere condivisa fra le varie implementazioni di framework web usate in AppFuse (i.e. Spring MVC e WebWork).%%
At line 385 changed 1 line.
Where ''menu.viewPeople'' is an entry in web/WEB-INF/classes/ApplicationResources.properties.
Dove ''menu.viewPeople'' è una voce nel file web/WEB-INF/classes/ApplicationResources.properties.
At line 390 changed 1 line.
The other (more likely) alternative is that you'll want to add it to the menu. To do this, add the following to web/WEB-INF/menu-config.xml:
Un'alternativa (più probabile) è che tu voglia aggiungere questa voce al menu. Per far questo, aggiungi quanto segue a web/WEB-INF/menu-config.xml:
At line 397 changed 1 line.
Make sure the above XML is inside the &lt;Menus&gt; tag, but not within another &lt;Menu&gt;. Then add this new menu to web/common/menu.jsp - which should now look as follows:
Controlla che l'XML su indicato si trovi all'interno del tag &lt;Menus&gt;, ma non dentro un altro tag &lt;Menu&gt;. Poi aggiungi questo nuovo menu a to web/common/menu.jsp - che ora dovrebbe presentarsi in questo modo:
At line 415 changed 1 line.
Now if you run __ant clean deploy__ start Tomcat and go to [http://localhost:8080/appfuse/mainMenu.html], you should see something like the screenshot below.
Ora se esegui __ant clean deploy__, avvi Tomcat e vai a [http://localhost:8080/appfuse/mainMenu.html], dovresti vedere qualcosa di simile alla schermata qui sotto.
At line 421 changed 1 line.
Notice that there is a new link on the left side (from mainMenu.jsp) and on the right in our menu (from menu.jsp).
Nota che c'è un nuovo collegamento sul lato sinistro (da mainMenu.jsp) e sulla destra nel nostro menu (da menu.jsp).
At line 423 changed 2 lines.
!!That's it!
You've completed the full lifecycle of developing a set of master-detail pages with AppFuse and Struts - __Congratulations__! Now the real test is if you can run all the tests in your app without failure. To test, stop tomcat and run __ant clean test-all__. This will run all the unit tests within your project. As a reminder, it should be easy to setup and test AppFuse from scratch using __ant setup-db setup-tomcat test-all__. Also, if you're looking for more robust examples - checkout [Struts Resume|StrutsResume].
!!È tutto!
Hai completato il ciclo di sviluppo completo di un insieme di pagine master-detail con AppFuse e Struts - __Congratulazioni__! Ora il vero test è se sei in grado di eseguire tutti i test nella tua applicazione senza errori. Per verificare, ferma tomcat ed esegui __ant clean test-all__. Questo target esegure tutti gli unit test nel tuo progetto. Come promemoria, dovrebbe essere semplice impostare e fare un test di AppFuse da zero usando __ant setup-db setup-tomcat test-all__. Inoltre, se stai cercando degli esempi più corposi - prova a vedere [Struts Resume|StrutsResume].
At line 426 changed 1 line.
''__Happy Day!__''
''__Buona Giornata!__''

Back to ValidationAndList_it, or to the Page History.