I am using Struts 2 in my java project. I just learned how to send a parameter by AJAX and now a need to update the html with the data returned from my Action Java class.
I just can update the html with the data returned from my Action Java class without AJAX.
Example:
<s:url action="painel.visualizarErro.action" namespace="/errosView.jsp" var="id" /> window.location = '<s:property value="id" />?jobId=' + jobId;
But I need to do by AJAX and i DON'T WANNA use JSON.
Here is my action in struts.xml:
<action name="painel.visualizarErro" class="com.fiveware.agendador.web.action.PainelAction"
method="visualizarErroProcessamento">
<result name="success">/errosView.jsp</result>
</action>
Here is my AJAX:
$.ajax({
type : "GET",
url : "<s:url action='painel.visualizarErro'/>",
beforeSend: function (xhr) {
xhr.setRequestHeader('ajax', 'true');
},
dataType : 'text/javascript',
data:{ 'actionToPerform': 'visualizarErroProcessamento',
'jobId': jobId,
},
processData: jobId,
success : exibirMensagemErro(),
});
Here is my Java Class (jus the metthod):
public String visualizarErroProcessamento() {
System.out.println("ID do JOB " + getJobId());
String erroProcessamento = new ItemJobBO(null).obtemErroProcessamento(String.valueOf(getJobId()));
setErroProcessamento(erroProcessamento);
Map<String, Object> sessionMap = ActionContext.getContext().getSession();
setCliente((ClienteVO) sessionMap.get(SessaoInterceptor.SESSAO_ID));
sessionMap.put("erros", erroProcessamento);
return SUCCESS;
}
Here is the HTML page, that I wanna update:
<%@ taglib prefix="s" uri="/struts-tags"%>
<div>ERRO NO PROCESSAMENTO</div>
<s:iterator value="#session.erros">
<label><s:property value="erroProcessamento" /></label>
<label><s:property value="jobId" /></label>
</s:iterator>
<script>
</script>