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
Articles_pt
CreateActions_pt




JSPWiki v2.2.33

[RSS]


Hide Menu

ValidationAndList_pt


Difference between version 4 and version 3:

At line 86 changed 1 line.
Now that you have Validation configured for this form, whenever this form is used in an action-mapping with validate="true", these rules will be applied. In the [last tutorial|CreateActions], we added the "savePerson" action-mapping for PersonAction. The XDoclet tags for this action-mapping were:
Agora que possuímos a validação configurada para este formulário, estas regras serão aplicadas toda vez que este formulário for utilizado em um action-mapping com validate="true". No [tutorial anterior|CreateActions_pt], adicionamos o action-mapping "savePerson" para a classe PersonAction. As tags XDoclet para este action-mapping eram:
At line 94 changed 1 line.
So now, as long as your web/pages/personForm.jsp has <html:form action="savePerson">, validation should kick in when we try to save this form. Run __ant db-load deploy__, start Tomcat and go to [http://localhost:8080/appfuse/editPerson.html?id=1].
Então agora, contanto que nosso web/pages/personForm.jsp possua um <html:form action="savePerson">, a validação deve ser realizada quando tentarmos salvar este formulário. Rodaremos __ant db-load deploy__, inicie o Tomcat (ou __ant db-load deploy start.tomcat__ para simplificar) e vá para [http://localhost:8080/appfuse/editPerson.html?id=1].
At line 96 changed 1 line.
If you erase the values in the firstName and lastName fields and click the save button, you should get the following JavaScript alert.
Se apagarmos os valores nos campos firstName e lastName, e clicarmos o botão Salvar, devemos receber o seguinte alerta Javascript:
At line 102 changed 1 line.
To make sure things are ''really'' working as expected, you can turn off JavaScript and ensure the server-side validation is working. This is easy in [Mozilla Firebird|http://www.mozilla.org/products/firebird/] (my favorite browser), just go to Tools → Options → Web Features and uncheck "Enable JavaScript". Now if you clear the fields and save the form, you should see the following:
Para nos certificarmos que tudo está ''realmente'' executando como esperamos, podemos desligar Javascript para provar que a validação do lado do servidor está funcionando. Isto é relativamente simples no [Mozilla Firebird|http://www.mozilla.org/products/firebird/] (meu browser favorito), apenas vá em Ferramentas(Tools) → Opções (Options) → Facilidades (Web Features) and uncheck "Permitir Javascript" ("Enable JavaScript"). Agora se limparmos os campos e salvarmos formulário, devemos ver o seguinte:
At line 108 changed 1 line.
If you don't see these validation errors, there are a couple possibilities:
Se não forem mostrados os erros de validação, podem haver algumas possibilidades:
At line 110 changed 4 lines.
* The form saves with a success message, but the firstName and lastName fields are now blank.
;:''This is because the <html:form> in web/pages/personForm.jsp has action="editPerson" - make sure it has __action="savePerson"__.''
* You click save, but a blank page appears.
;:''The blank page indicates that the "input" attribute of you "savePerson" forward is incorrectly configured. Make sure it relates to a local or global action-forward. In this example, it should be __input="edit"__, which points to the .personDetail tile's definition. From my experience, the input's value must be a forward, not a path to an action.''
* O formulário salva com a mensagem de sucesso, mas os campos firstName e lastName estão em branco.
;:''Isto é porque o <html:form> na página web/pages/personForm.jsp possui action="editPerson" - certifique-se que ele contenha __action="savePerson"__.''
* Clicamos em "Salvar", mas uma página em branco apareceu.
;:''A página em branco indica que o atributo de "entrada" de nosso envio "savePerson" está configurada erroneamente. Devemos nos certificar que ele esteja relacionado com um action-forward local ou global. Neste exemplo, ele deve ser __input="edit"__, que aponta para a definição de .personDetail. Por experiência própria, um valor de entrada deve ser um envio, não um caminho para uma action.''
At line 115 changed 1 line.
If you only want server-side validation (no JavaScript), you can remove the ''onsubmit'' attribute of <html:form> (in web/pages/personForm.jsp) as well as the Validator JavaScript tags at the bottom of the page.
Se desejarmos apenas validação do lado servidor (sem Javascript), podemos remover o atributo ''onsubmit'' do <html:form> (em web/pages/personForm.jsp) assim como as tags de validação Javascript no final da página.
At line 126 changed 1 line.
To create a List screen (also called a master screen), we need to create methods that will return all the rows from our ''person'' table. Let's start by adding tests for these methods to our PersonDaoTest and PersonManagerTest classes. I usually name this method ''getEntities'' (i.e. getUsers), but you could also use ''getAll'' or ''search'' - it's really just a matter of personal preference.
Para criarmos uma tela de listagem (também chamada uma tela mestre), devemos criar métodos que retornarão todas as tuplas de nossa tabela ''person''. Vamos começar adicionando os métodos de teste às nossas classes PersonDaoTest e PersonManagerTest. Geralmente nomeio este método ''getEntidades'' (i.e. getUsers), mas podemos também utilizar ''getAll'' ou ''search'' - isto é realmente uma questão de preferência pessoal.
At line 128 changed 1 line.
Open test/dao/**/dao/PersonDaoTest.java and add a ''testGetPeople'' method:
Abra o arquivo test/dao/**/dao/PersonDaoTest.java e adicione o método ''testGetPeople'':
At line 139 changed 1 line.
The reason I'm passing in a person object to the ''getPeople'' method is to allow for filtering (based on values in person) in the future. Adding this parameter in your getPeople() method signature is optional, but the rest of this tutorial assumes you have done this.
A razão pela qual passamos um objeto person ao método ''getPeople'' é para permitir filtragem (baseado nos atributos do person) no futuro. Adicionando este parâmetro na assinatura de nosso método getPeople() é opcional, mas o resto do tutorial assume que fizemos isto.
At line 141 changed 1 line.
Now open test/service/**/service/PersonManagerTest.java and add a ''testGetPeople'' method:
Agora abra o arquivo test/service/**/service/PersonManagerTest.java e adicione um método ''testGetPeople'':
At line 150 changed 1 line.
// set expected behavior on dao
// seta o comportamento esperado do DAO
At line 160 changed 1 line.
In order for these tests to compile, you need to add the ''getPeople()'' method to the PersonDao and PersonManager interfaces, and their implementations.
Para estes testes compilarem, devemos adicionar o método ''getPeople()'' às interfaces PersonDao e PersonManager, assim como a suas implementações.
At line 163 changed 1 line.
Open src/dao/**/dao/PersonDao.java and add the getPeople() method signature:
Abra o arquivo src/dao/**/dao/PersonDao.java e adicione a assinatura do método getPeople():

Back to ValidationAndList_pt, or to the Page History.