Rev 1576 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1576 | jmachado | 1 | <%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %> |
2 | <%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %> |
||
3 | <%@ taglib uri="/WEB-INF/tlds/jomm.tld" prefix="jomm" %> |
||
4 | <%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %> |
||
5 | <%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested" %> |
||
6 | <%@ taglib uri="/WEB-INF/tlds/baco.tld" prefix="baco" %> |
||
7 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||
1577 | jmachado | 8 | <div class="container-fluid"> |
1576 | jmachado | 9 | |
10 | <h1>Teste aos Controladores de Widgets de Exemplo</h1> |
||
11 | |||
12 | <h2>Ficheiros biblioteca, não são para alterar</h2> |
||
13 | <ul> |
||
14 | <li>conf/WEB-INF/struts/tiles-jsonwidget.xml (Layouts de Respostas JSON)</li> |
||
15 | <li>conf/WEB-INF/struts/struts-jsonwidget.xml (Global Forwards de Respostas JSON)</li> |
||
16 | <li>classe para extender controladores pt.estgp.estgweb.web.controllers.utils.AbstractWidgetAjaxController</li> |
||
17 | </ul> |
||
18 | |||
19 | <h2>Ficheiro de Configuração de exemplo para novos Controladores de Widgets</h2> |
||
20 | <ul> |
||
21 | <li>conf/WEB-INF/struts/examples/struts-example/jsonwidget.xml</li> |
||
22 | </ul> |
||
23 | |||
24 | <h2>Controladores e form de Exemplo</h2> |
||
25 | <ul> |
||
26 | <li>classe de Exemplo pt.estgp.estgweb.web.controllers.examples.jsonwidget.JsonWidgetExampleForm</li> |
||
27 | <li>classe de Exemplo pt.estgp.estgweb.web.controllers.examples.jsonwidget.WidgetExampleController</li> |
||
28 | </ul> |
||
29 | |||
30 | <h2>Chamadas de Exemplo do Serviço AJAX/JSON</h2> |
||
31 | <p>Os exemplos de chamada das bibliotecas JavaScript são um nível de abstração acima destes exemplos</p> |
||
32 | <ul> |
||
33 | <li> |
||
34 | <a href="<%=request.getContextPath()%>/widgetWithValidationExample.do?dispatch=executeService&serviceJson=serviceClean&nome=teste"> |
||
35 | Teste de um servico sem erros e com validacao |
||
36 | </a> |
||
37 | </li> |
||
38 | <li> |
||
39 | <a href="<%=request.getContextPath()%>/widgetWithValidationExample.do?dispatch=executeService&serviceJson=serviceClean"> |
||
40 | Teste de um servico com erros e com validacao onde foi omitido o campo nome que é obrigatório |
||
41 | </a> |
||
42 | </li> |
||
43 | <li> |
||
44 | <a href="<%=request.getContextPath()%>/widgetExample.do?dispatch=executeService&serviceJson=serviceException"> |
||
45 | Teste de um servico com uma excepção |
||
46 | </a> |
||
47 | </li> |
||
48 | <li> |
||
49 | <a href="<%=request.getContextPath()%>/widgetExample.do?dispatch=executeSimpleServiceOkFail&serviceJson=serviceSimpleOkExample"> |
||
50 | Teste de um servico Tipo Ok ou Fail Simples |
||
51 | </a> |
||
52 | </li> |
||
53 | <li> |
||
54 | <a href="<%=request.getContextPath()%>/widgetExample.do?dispatch=executeSimpleServiceOkFail&serviceJson=serviceSimpleFailExample"> |
||
55 | Teste de um servico Tipo Ok ou Fail Simples com FALHA |
||
56 | </a> |
||
57 | </li> |
||
58 | </ul> |
||
59 | |||
60 | |||
61 | <h2>Como usar as bilbiotecas de chamada AJAX</h2> |
||
62 | <p> |
||
63 | Bibliotecas de alto nível. Libertam o developer para a colocação de mensagens e para a interpretação do estado de resposta a um pedido, |
||
64 | bastando haver um div com a class web-messages dentro do Form. O developer apenas tem de programar os handlers de sucesso e de falha.</p> |
||
65 | <p>Existem dois tipos de chamadas possiveis, as que devolvem um objecto json e as simples que apenas devolvem ok ou fail através da invocação do handler respectivo</p> |
||
66 | |||
67 | <div class="web-messages"><div class="alert alert-info">Exemplo Div para mensagens WEB mas nao é afectado pelo form</div> </div> |
||
68 | <p>Form de Struts com Auto preenchimento de Campos mas invoca um Widget Controller</p> |
||
69 | <html:form styleClass="form-horizontal" action="/widgetWithValidationExample" onsubmit="return false;"> |
||
70 | <div class="web-messages">Aqui vão aparecer as mensagens de Erro ou de Feedback do Widget</div> |
||
71 | <div class="form-group"> |
||
1577 | jmachado | 72 | <label class="col-md-2">Nome</label> |
73 | <div class="col-md-8"> |
||
74 | <html:text styleClass="form-control" property="nome"/> |
||
75 | </div> |
||
1576 | jmachado | 76 | </div> |
77 | |||
78 | <div> |
||
79 | <script> |
||
80 | function widgetCallClean(form) |
||
81 | { |
||
82 | widgetCall('serviceClean',form, |
||
83 | function(response) |
||
84 | { |
||
85 | alert("Accao de resposta terminada: " + response.dataExample); |
||
86 | }); |
||
87 | } |
||
88 | function widgetCallWithErrors(form) |
||
89 | { |
||
90 | widgetCall('serviceWithErrors',form, |
||
91 | function(response) |
||
92 | { |
||
93 | alert("Accao de resposta terminada: " + response.dataExample); |
||
94 | }, |
||
95 | function(response) |
||
96 | { |
||
97 | alert("Accao Falhou mas as resposta foi esta: " + response.dataExample); |
||
98 | }); |
||
99 | } |
||
100 | function widgetCallExceptionTest(form) |
||
101 | { |
||
102 | widgetCall('serviceException',form, |
||
103 | function(response) |
||
104 | { |
||
105 | alert("Accao de resposta terminada: " + response.dataExample); |
||
106 | }); |
||
107 | } |
||
108 | |||
109 | function widgetChamadaSimples(form) |
||
110 | { |
||
111 | widgetSimpleCall('serviceSimpleOkExample',form, |
||
112 | function() |
||
113 | { |
||
114 | alert("OK"); |
||
115 | }, |
||
116 | function() |
||
117 | { |
||
118 | alert("Fail"); |
||
119 | }); |
||
120 | } |
||
121 | function widgetChamadaFalha(form) |
||
122 | { |
||
123 | widgetSimpleCall('serviceSimpleFailExample',form, |
||
124 | function() |
||
125 | { |
||
126 | alert("OK"); |
||
127 | }, |
||
128 | function() |
||
129 | { |
||
130 | alert("Fail"); |
||
131 | }); |
||
132 | } |
||
133 | |||
134 | |||
135 | </script> |
||
136 | <p>(Pode usar ou nao o campo "nome" para ver o resultado da validação do Form. Quando a validacao do form nao passa apenas vem uma falha e uma lista de erros, quando a falha é propositada dentro do controller com a adicao de erros é possivel enviar o objecto json como resposta)</p> |
||
137 | <button class="btn btn-success" type="button" onclick="widgetCallClean(this.form)">Submeter Simulacao Servico OK</button> |
||
138 | <button class="btn btn-warning" type="button" onclick="widgetCallWithErrors(this.form)">Submeter Simulacao Servico Com Erros</button> |
||
139 | <button class="btn btn-danger" type="button" onclick="widgetCallExceptionTest(this.form)">Submeter Simulacao Servico Com Excepção</button> |
||
140 | <button class="btn btn-success" type="button" onclick="widgetChamadaSimples(this.form)">Submeter Simulacao Servico SIMPLES OK/FAIL TUDO OK</button> |
||
141 | <button class="btn btn-warning" type="button" onclick="widgetChamadaFalha(this.form)">Submeter Simulacao Servico SIMPLES OK/FAIL FALHA</button> |
||
142 | </div> |
||
143 | </html:form> |
||
144 | |||
145 | |||
1577 | jmachado | 146 | </div> |