-
1. Action is not triggered after a submit
boy18nj Feb 9, 2011 12:07 PM (in response to dpnascimento)Please show your code.
-
2. Action is not triggered after a submit
dpnascimento Feb 9, 2011 12:14 PM (in response to boy18nj)Ok.
Let's go...
this is my template code
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:t="http://myfaces.apache.org/tomahawk">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>
<ui:insert name="title">
Ares Performance Suite - Beta Version
</ui:insert>
</title>
<ui:insert name="head">
</ui:insert>
<script type="text/javascript">
var infoWindowAMShown = false;
var infoWindowAMTimer;
function showModalInfoWindow()
{
infoWindowAMTimer = setTimeout("if(!infoWindowAMShown){Richfaces.showModalPanel('ajaxLoadingModalBox');infoWindowAMShown=true;}", 500);
}
function hideModalInfoWindow()
{
if (infoWindowAMShown) {
Richfaces.hideModalPanel('ajaxLoadingModalBox');
infoWindowAMShown=false;
} else {
if(infoWindowAMTimer)
clearTimeout(infoWindowAMTimer);
}
}
</script>
</head>
<body>
<!-- ajax loading -->
<a4j:status onstart="showModalInfoWindow();" onstop="hideModalInfoWindow()"/>
<rich:modalPanel id="ajaxLoadingModalBox" autosized="true">
<f:facet name="header">
<h:outputText value="Em processamento"/>
</f:facet>
<h:outputText value="Por favor aguarde... Sua solicitação está sendo processada pelo sistema!"/>
</rich:modalPanel>
<!-- bloco principal -->
<a4j:outputPanel ajaxRendered="true" id="mainOutputPanel" style="width: 600px">
<a4j:form>
<!-- bloco de pesquisa -->
<rich:panel id="searchlistBlock"
rendered="#{defaultBean.pesquisarEstado}">
<f:facet name="header">
Pesquisar
</f:facet>
<h:messages errorStyle="color: red" infoStyle="color: blue" layout="table" showSummary="true" showDetail="false" globalOnly="true"/>
<ui:insert name="searchlistBlock">
</ui:insert>
</rich:panel>
<!-- bloco de edicao -->
<rich:panel id="addUpdateBlock"
rendered="#{defaultBean.adicionarEstado or defaultBean.editarEstado}">
<f:facet name="header">
Dados do Bean
</f:facet>
<h:messages errorStyle="color: red" infoStyle="color: blue" layout="table" showSummary="true" showDetail="false" globalOnly="true"/>
<ui:insert name="addUpdateBlock">
</ui:insert>
</rich:panel>
</a4j:form>
</a4j:outputPanel>
</body>
</html>
this is my page code
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:c="http://java.sun.com/jstl/core"
template="/templates/crudTemplate.xhtml">
<!-- passa parametro para o template -->
<ui:param name="defaultBean" value="#{holdingBean}" />
<ui:define name="title">
Cadastro de Holdings
<t:saveState id="_bean" value="#{holdingBean}" />
</ui:define>
<ui:define name="head">
<style type="text/css">
.odd-row {
background-color: #ECF3FE;
}
.even-row {
background-color: #FCFFFE;
}
</style>
</ui:define>
<!-- define searchlistBlock -->
<ui:define name="searchlistBlock">
<h:panelGrid columns="1">
<h:column>
<a4j:commandButton value="Pesquisar" action="#{holdingBean.pesquisar}"/>
<a4j:commandButton value="Adicionar" action="#{holdingBean.prepararParaAdicionar}" immediate="true"/>
<a4j:commandButton value="Gravar - I" action="#{holdingBean.incluir}" />
</h:column>
</h:panelGrid>
<rich:spacer width="1" height="5" />
<rich:datascroller align="left" for="userList" maxPages="10" />
<rich:spacer height="15" />
<rich:dataTable width="450" id="userList" rows="10"
rowClasses="odd-row,even-row"
columnClasses="col" value="#{holdingBean.holdings}" var="row">
<f:facet name="header">
<rich:columnGroup>
<h:column>
<h:outputText styleClass="headerText" value="ID" />
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="Nome" />
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="CNPJ" />
</h:column>
<h:column>
</h:column>
</rich:columnGroup>
</f:facet>
<h:column>
<h:outputText value="#{row.id}" />
</h:column>
<h:column>
<h:outputText value="#{row.nome}" />
</h:column>
<h:column>
<h:outputText value="#{row.CNPJ}" />
</h:column>
<h:column>
<span>
<a4j:commandLink value="Editar" action="#{holdingBean.prepararParaEditar}" immediate="true">
<f:setPropertyActionListener value="#{row}" target="#{holdingBean.holding}"/>
</a4j:commandLink>
</span>
<span>
<a4j:commandLink value="Excluir" action="#{holdingBean.excluir}" immediate="true">
<f:setPropertyActionListener value="#{row}" target="#{holdingBean.holding}"/>
</a4j:commandLink>
</span>
</h:column>
</rich:dataTable>
</ui:define>
<!-- define addUpdateBlock -->
<ui:define name="addUpdateBlock">
<h:panelGrid columns="2" id="panel2" binding="#{holdingBean.panelForm}" columnClasses="odd-row,even-row">
<h:outputLabel value="Nome: "/>
<h:column>
<h:inputText value="#{holdingBean.holding.nome}" size="30" required="true" id="nome"
requiredMessage="Por favor, informe um nome para a Holding"
readonly="#{holdingBean.editarEstado}"
style="#{holdingBean.editarEstado ? 'color: gray;' : ''}"/>
<br/>
<h:message for="nome" errorStyle="color: darkred;"/>
</h:column>
<h:outputLabel value="CNPJ: "/>
<h:column>
<h:inputText value="#{holdingBean.holding.numeroCNPJ}" size="14" required="false" id="numeroCNPJ"
readonly="#{holdingBean.editarEstado}"
style="#{holdingBean.editarEstado ? 'color: gray;' : ''}"/>
<br/>
</h:column>
</h:panelGrid>
<a4j:commandButton value="Gravar - I" action="#{holdingBean.incluir}" rendered="#{holdingBean.adicionarEstado}"/>
<a4j:commandButton value="Gravar - U" action="#{holdingBean.alterar}" rendered="#{holdingBean.editarEstado}"/>
<a4j:commandButton value="Voltar para pesquisa" action="#{holdingBean.voltar}" immediate="true"/>
</ui:define>
</ui:composition>
And now my Bean Code
package br.com.aresitsolutions.aps.controller;
import java.util.List;
import br.com.aresitsolutions.aps.businessobjects.HoldingBO;
import br.com.aresitsolutions.aps.domain.Holding;
import br.com.aresitsolutions.aps.domain.Usuario;
import br.com.aresitsolutions.aps.exception.BusinessException;
public class HoldingBean extends CrudBean {
private Usuario usuarioLogado;
private HoldingBO holdingBO;
private Holding holding;
private List<Holding> holdings;
public HoldingBean() {
super();
this.usuarioLogado = null;
holdingBO = new HoldingBO(this.usuarioLogado);
}
public List<Holding> getHoldings() {
return this.holdings;
}
public Holding getHolding() {
return holding;
}
public void setHolding(Holding holding) {
this.holding = holding;
}
public void setHoldings(List<Holding> holdings) {
this.holdings = holdings;
}
public void listar() throws BusinessException {
this.holdings = holdingBO.listar();
if (this.holdings == null || this.holdings.size() == 0) {
this.lancarMensagemInformacao("holding.cadastro.vazio");
}
}
public void inserir() throws BusinessException {
holdingBO.incluir(holding);
this.lancarMensagemInformacao("holding.cadastro.sucesso");
}
public void editar() throws BusinessException {
holdingBO.alterar(holding);
this.lancarMensagemInformacao("holding.alterado.sucesso");
}
public void apagar() throws BusinessException {
holdingBO.excluir(holding);
this.lancarMensagemInformacao("holding.excluido.sucesso");
}
public void limparCampos() {
holding = new Holding();
}
}
my super class code 1
package br.com.aresitsolutions.aps.controller;
import javax.faces.component.UIComponent;
import javax.faces.component.UIPanel;
import br.com.aresitsolutions.aps.controller.iface.ICrudBean;
import br.com.aresitsolutions.aps.exception.BusinessException;
public abstract class CrudBean extends GenericBean implements ICrudBean {
public static final String PESQUISAR_ESTADO = "pesquisar";
public static final String ADICIONAR_ESTADO = "adicionar";
public static final String EDITAR_ESTADO = "editar";
private String estadoAtualForm;
private UIPanel panelForm;
public CrudBean () {
super();
}
public String getEstadoAtual() {
return estadoAtualForm;
}
public void setEstadoAtual(String estadoAtualForm) {
this.estadoAtualForm = estadoAtualForm;
}
public void pesquisar() {
try {
this.setEstadoAtual(PESQUISAR_ESTADO);
listar();
} catch (BusinessException be) {
this.lancarMensagemAlerta(be.getMessage());
} catch (Exception e) {
e.printStackTrace();
this.lancarMensagemErro(e.getMessage());
}
}
public void incluir() {
try {
this.setEstadoAtual(PESQUISAR_ESTADO);
inserir();
pesquisar();
} catch (BusinessException be) {
this.lancarMensagemAlerta(be.getMessage());
} catch (Exception e) {
e.printStackTrace();
this.lancarMensagemErro(e.getMessage());
}
}
public void alterar() {
try {
editar();
pesquisar();
} catch (BusinessException be) {
this.lancarMensagemAlerta(be.getMessage());
} catch (Exception e) {
e.printStackTrace();
this.lancarMensagemErro(e.getMessage());
}
}
public void excluir() {
try {
apagar();
pesquisar();
} catch (BusinessException be) {
this.lancarMensagemAlerta(be.getMessage());
} catch (Exception e) {
e.printStackTrace();
this.lancarMensagemErro(e.getMessage());
}
}
public void prepararParaAdicionar() {
this.clear();
this.setEstadoAtual(ADICIONAR_ESTADO);
}
public void prepararParaEditar() {
this.setEstadoAtual(EDITAR_ESTADO);
}
public void voltar() {
limparCampos();
this.clear();
this.pesquisar();
}
/**
* Limpa os componentes filhos para que depois eles possam ser recriados
* @param component
*/
private void cleanSubmittedValues(UIComponent component) {
component.getChildren().clear();
}
/**
* Limpa atributos
*/
protected void clear() {
if (this.panelForm != null) {
cleanSubmittedValues(this.panelForm);
}
}
/*
* Métodos que expõem o estado à página
*/
public boolean isPesquisarEstado() {
String state = this.getEstadoAtual();
return (state == null || PESQUISAR_ESTADO.equals(state));
}
public boolean isAdicionarEstado() {
return ADICIONAR_ESTADO.equals(this.getEstadoAtual());
}
public boolean isEditarEstado() {
return EDITAR_ESTADO.equals(this.getEstadoAtual());
}
public UIPanel getPanelForm() {
return panelForm;
}
public void setPanelForm(UIPanel panelForm) {
this.panelForm = panelForm;
}
}
my super class code 2
package br.com.aresitsolutions.aps.controller;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import br.com.aresitsolutions.aps.util.ResourceBundleUtil;
public abstract class GenericBean {
//instanciando um objeto do tipo HttpServlet
protected HttpServletRequest requestScope;
//instanciando um objeto do tipo HttpSession
protected HttpSession sessionScope;
protected FacesContext context;
public GenericBean() {
FacesContext facesContext = FacesContext.getCurrentInstance();
this.requestScope = (HttpServletRequest) facesContext.getExternalContext().getRequest();
this.sessionScope = requestScope.getSession();
this.context = FacesContext.getCurrentInstance();
}
protected String getSessionIP() {
return requestScope.getRemoteAddr();
}
protected String getSessionId() {
return sessionScope.getId();
}
protected void lancarMensagemErro(String nomeMensagem) {
if (nomeMensagem == null) {
nomeMensagem = "nullPointerExcepetion";
}
String mensagem = ResourceBundleUtil.getApplicationMessagesString(nomeMensagem, null);
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, mensagem, mensagem);
this.context.addMessage(null, message);
}
protected void lancarMensagemInformacao(String nomeMensagem) {
if (nomeMensagem == null) {
nomeMensagem = "nullPointerExcepetion";
}
String mensagem = ResourceBundleUtil.getApplicationMessagesString(nomeMensagem, null);
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, mensagem, mensagem);
this.context.addMessage(null, message);
}
protected void lancarMensagemAlerta(String nomeMensagem) {
if (nomeMensagem == null) {
nomeMensagem = "nullPointerExcepetion";
}
String mensagem = ResourceBundleUtil.getApplicationMessagesString(nomeMensagem, null);
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_WARN, mensagem, mensagem);
this.context.addMessage(null, message);
}
}
my web.xml code
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Ares Performance Suite - Beta version</display-name>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING_CLASSES</param-name>
<param-value>enable</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<!--
<context-param>
<param-name>onload-config</param-name>
<param-value>/WEB-INF/onload-config.xml</param-value>
</context-param>
-->
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<listener>
<listener-class>
com.sun.faces.config.ConfigureListener
</listener-class>
</listener>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
My faces-config.xml code
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<!-- Definicao do arquivo de mensagens -->
<application>
<locale-config>
<default-locale>pt_BR</default-locale>
<supported-locale>pt_BR</supported-locale>
<supported-locale>en_US</supported-locale>
</locale-config>
<resource-bundle>
<base-name>br.com.aresitsolutions.aps.resources.jsp.messages</base-name>
<!-- Var define nome do mapa de variaveis que contem as mensagens -->
<var>msgs</var>
</resource-bundle>
</application>
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
<managed-bean>
<managed-bean-name>loginBean</managed-bean-name>
<managed-bean-class>br.com.aresitsolutions.aps.controller.LoginBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>holdingBean</managed-bean-name>
<managed-bean-class>br.com.aresitsolutions.aps.controller.HoldingBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
-
3. Action is not triggered after a submit
godoy Feb 9, 2011 12:53 PM (in response to dpnascimento)Use <h:form />
-
4. Action is not triggered after a submit
godoy Feb 9, 2011 1:00 PM (in response to dpnascimento)jsf in its methods should have the following signature:
for action = "#" should return a string and has no parameters eg
public String excluir(){
return "";
}
or to be void ActionListener and ActionEvent as a parameter eg
public void excluir(ActionEvent evt){
..
}
-
5. Action is not triggered after a submit
dpnascimento Feb 9, 2011 1:01 PM (in response to godoy)Leandro godoy wrote:
Use <h:form />
I got the same problem.
-
6. Action is not triggered after a submit
dpnascimento Feb 9, 2011 1:05 PM (in response to godoy)Leandro godoy wrote:
jsf in its methods should have the following signature:
for action = "#" should return a string and has no parameters eg
public String excluir(){
return "";
}
or to be void ActionListener and ActionEvent as a parameter eg
public void excluir(ActionEvent evt){
..
}
Well I'm using Facelets + JSF
So, why the method "pesquisar()" works fine?
And also, If I move the buttons "Gravar" to the search block, they start to work!
-
7. Action is not triggered after a submit
godoy Feb 9, 2011 1:26 PM (in response to dpnascimento)Isso não sei responder mas a especificação JSF diz que as actions tem que ter tipo de retorno String e as actionListener's tem que ser void com parametro ActionEvent.
Experimente mudar a assinatura dos seus metodos para ver se funciona, lembre- se tambem de sempre envolver seus componentes dentro de um form, pois erros deste tipo quase sempre sao causados pela falta de um form.
-
8. Action is not triggered after a submit
dpnascimento Feb 9, 2011 5:04 PM (in response to dpnascimento)Well... after some tests I continue with problemas.
Anybody else can help me?
-
9. Action is not triggered after a submit
boy18nj Feb 9, 2011 9:14 PM (in response to dpnascimento)I cannot understand your code, it's probably not english language, unable to figure out your saving mechanisim in beans.
-
10. Action is not triggered after a submit
liuliu Feb 10, 2011 3:15 AM (in response to dpnascimento)hi,
if it is one of your commandbuttons with rendered attribute has problem, maybe because your holdingbean is request scope.
-
11. Action is not triggered after a submit
dpnascimento Feb 10, 2011 7:07 AM (in response to boy18nj)Aman S wrote:
I cannot understand your code, it's probably not english language, unable to figure out your saving mechanisim in beans.
Aman, thanks for your reply. You're rigth. My code use portuguese language!
Think about the transformation below to understand the code.
pesquisar, listar = search
inserir, incluir = insert
alterar, editar = update
excluir, apagar = delete
If you have some another consideration, please, let me know.
Thanks,
-
12. Action is not triggered after a submit
dpnascimento Feb 10, 2011 8:02 AM (in response to liuliu)liumin hu wrote:
hi,
if it is one of your commandbuttons with rendered attribute has problem, maybe because your holdingbean is request scope.
Hi liumin hu,
i have change the bean's scope to application, and works.
Do you know why the request scope cause this behavior?
Thanks.
-
13. Action is not triggered after a submit
liuliu Feb 10, 2011 8:24 AM (in response to dpnascimento)Request scope bean is initiated every reques so the rendered attribute is false at begining.
and the JSF ignore the component with "rendered = false" when it restore the view(phase 1). At phase render response(phase 6), the rendered became true, so you can see it. but the component is not in the view, the action is ignored too.
-
14. Action is not triggered after a submit
dpnascimento Feb 10, 2011 2:55 PM (in response to liuliu)Hi again Iimin hu!
Well... I have tested some resources after the update to application scope. But unfortunally I can't use application scope to this case in my application.
So what can I do about it? Session scope is not a good ideia... So I just can use request scope.