Basic problem with a4j:commandButton and jsf 2.0
balteo Mar 13, 2011 6:13 AMHello,
I am having a great deal of trouble with a plain a4j:commandButton and Jsf 2.0/RF4RC1.
My application has a form that I am trying to submit. The action method is not even called...
Here is the bean:
package com.jeanbaptistemartin.view;
import com.jeanbaptistemartin.service.JbmService;
import com.jeanbaptistemartin.domain.Personne;
import com.jeanbaptistemartin.service.Message;
import com.jeanbaptistemartin.util.FacesUtils;
import com.ocpsoft.pretty.faces.annotation.URLAction;
import com.ocpsoft.pretty.faces.annotation.URLMapping;
import java.util.Date;
import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.validator.ValidatorException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
*
* @author julien
*/
@Component("contactView")
@Scope("request")
@URLMapping(id = "contactAction", parentId = "rootAction", pattern = "contact", viewId = "/contact.jsf")
public class ContactView {
private static transient Logger log = Logger.getLogger("com.jeanbaptistemartin.view");
public static final String CAPTCHA_ID = "jbm";
private JbmService service;
@Autowired
private Message message;
private String secureText;
@Autowired
private ContactViewBackingBean bb;
private String[] telephones;
private Personne sculpteur;
public ContactView() {
log.debug("ContactView()");
}
@Autowired
public ContactView(JbmService service) {
log.debug("ContactView(JbmService service)");
this.service = service;
this.telephones = service.recupererTelephonesSculpteur();
this.sculpteur = service.recupererSculpteur();
}
public Personne getSculpteur() {
return sculpteur;
}
public void setSculpteur(Personne sculpteur) {
this.sculpteur = sculpteur;
}
public String[] getTelephones() {
return telephones;
}
public void setTelephones(String[] telephones) {
this.telephones = telephones;
}
@URLAction
public String contact() {
log.debug("contact");
return "/contact.xhtml";
}
public String envoyer() {
log.debug("envoyer");
service.envoyerMessage(this.message);
// FacesUtils fu = new FacesUtils();
// FacesContext fc = FacesContext.getCurrentInstance();
// ResourceBundle rb = ResourceBundle.getBundle("resources", fc.getViewRoot().getLocale());
// FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO, rb.getString("message.envoi.reussi"), rb.getString("message.envoi.reussi"));
// fc.addMessage(fu.getClientId("envoyerMessage"), fm);
this.bb.setLocalValuesSet(false);
this.bb.setSubmittedValues(null);
this.bb.setValues("");
return null;
}
public Message getMessage() {
log.debug("getMessage");
return message;
}
public void setMessage(Message message) {
log.debug("setMessage");
this.message = message;
}
public void valider(ActionEvent evt) {//todo was javax.faces.event.ActionEvent
log.debug("valider");
UIInput comp = (UIInput) evt.getComponent().getParent();
FacesContext fc = FacesContext.getCurrentInstance();
ResourceBundle rb = ResourceBundle.getBundle("resources", fc.getViewRoot().getLocale());
try {
comp.validate(fc);
FacesMessage fm = new FacesMessage();
fm.setSeverity(FacesMessage.SEVERITY_INFO);
fc.addMessage(comp.getClientId(fc), fm);
} catch (ValidatorException ve) {
FacesMessage fm = new FacesMessage();
fm.setSeverity(FacesMessage.SEVERITY_ERROR);
fm.setSummary(rb.getString("message.erreur.validation"));
fm.setDetail(rb.getString("message.erreur.validation"));
fc.addMessage(comp.getClientId(fc), fm);
throw new ValidatorException(fm);
}
}
public String getSecureText() {
log.debug("getSecureText");
return secureText;
}
public void setSecureText(String secureText) {
log.debug("setSecureText");
this.secureText = secureText;
}
public ContactViewBackingBean getBb() {
log.debug("getBb");
return bb;
}
public void setBb(ContactViewBackingBean bb) {
log.debug("setBb");
this.bb = bb;
}
public Date getNow() {
log.debug("getNow");
return new Date();
}
}
Here is my jsf form:
<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">
<a4j:region>
<h:panelGrid id="formulaireContactP" columns="3" columnClasses="libellesColonne,champsColonne,validiteColonne">
<h:outputText value="#{msg['message.from.email']}" />
<a4j:outputPanel id="fromEmail">
<h:inputText id="email"
value="#{contactView.message.email}"
required="true"
requiredMessage="#{msg['message.valeurRequise.email']}"
validatorMessage="#{msg['message.erreur.email']}"
binding="#{contactView.bb.emailI}"
maxlength="50"
size="20"
styleClass="emailI">
<f:validator validatorId="adresseEmailValidator" />
<f:ajax event="click" listener="#{contactView.valider}"/>
</h:inputText>
</a4j:outputPanel>
<a4j:outputPanel id="emailMP" ajaxRendered="true">
<h:message for="email" infoClass="champValide" styleClass="champInvalide"/>
</a4j:outputPanel>
<h:outputText value="#{msg['message.from.nom']}" />
<a4j:outputPanel id="nom">
<h:inputText id="nomI"
value="#{contactView.message.nom}"
required="true"
requiredMessage="#{msg['message.valeurRequise.nom']}"
binding="#{contactView.bb.nomI}"
maxlength="50"
size="20"
styleClass="nomI">
<f:ajax listener="#{contactView.valider}" render="nom nomMP"/>
<f:validateLength minimum="3" />
</h:inputText>
</a4j:outputPanel>
<a4j:outputPanel id="nomMP" ajaxRendered="false">
<h:message for="nomI" infoClass="champValide" styleClass="champInvalide"/>
</a4j:outputPanel>
<h:outputText value="#{msg['message.sujet']}" rendered="false"/>
<a4j:outputPanel id="sujet" rendered="false">
<h:inputText id="sujetI" value="#{contactView.message.sujetMessage}" required="true"
requiredMessage="#{msg['message.valeurRequise.sujet']}" validatorMessage="#{msg['message.erreur.sujet']}" binding="#{contactView.bb.sujetI}" maxlength="50" size="20">
<f:validateLength minimum="2" />
</h:inputText>
</a4j:outputPanel>
<a4j:outputPanel id="sujetMP" ajaxRendered="true" rendered="false">
<h:message for="sujetI" infoClass="champValide" styleClass="champInvalide" rendered="true"/>
</a4j:outputPanel>
<h:outputText value="#{msg['message.corps']}" />
<a4j:outputPanel id="corps">
<h:inputTextarea id="corpsI"
value="#{contactView.message.corpsMessage}"
cols="25"
rows="5"
required="true"
requiredMessage="#{msg['message.valeurRequise.corps']}"
validatorMessage="#{msg['message.erreur.corps']}"
binding="#{contactView.bb.corpsI}">
<f:validateLength minimum="15" maximum="1000" />
</h:inputTextarea>
</a4j:outputPanel>
<a4j:outputPanel id="corpsMP" ajaxRendered="true" >
<h:message for="corpsI" infoClass="champValide" styleClass="champInvalide" style="vertical-align: top"/>
</a4j:outputPanel>
<a4j:outputPanel rendered="false">
<h:outputText value="#{msg['message.texte.recopier']}" />
</a4j:outputPanel>
<a4j:outputPanel id="captchaImage" ajaxRendered="true" style="min-height:50px;min-width:150px;" rendered="false">
<h:graphicImage value="/CaptchaServlet?param=#{contactView.now}&locale=#{view.locale.language}" height="50" width="150" alt="#{msg['message.texte.recopier']}" title="#{msg['message.texte.recopier']}"/>
</a4j:outputPanel>
<a4j:outputPanel rendered="false"/>
<a4j:outputPanel rendered="false">
<h:outputText value="#{msg['message.recopier.ici']}" />
</a4j:outputPanel>
<a4j:outputPanel id="secureText" rendered="false">
<h:inputText id="secureTextI" value="#{contactView.secureText}" validatorMessage="#{msg['message.captcha.requis']}" requiredMessage="#{msg['message.captcha.requis']}" maxlength="50" size="20" required="true" binding="#{contactView.bb.secureTextI}">
<f:validator validatorId="captchaValidator" />
</h:inputText>
</a4j:outputPanel>
<a4j:outputPanel id="secureTextMP" rendered="false">
<h:message for="secureTextI" styleClass="champInvalide" />
</a4j:outputPanel>
<a4j:outputPanel layout="block" styleClass="formulaireContactLoader">
<ui:include src="status-bar.xhtml"/>
</a4j:outputPanel>
<a4j:outputPanel layout="block" styleClass="formulaireContactFooter">
<a4j:commandButton id="envoyerMessage" action="#{contactView.envoyer}" type="submit" render="formulaireContactP" value="#{msg['message.envoyer']}" styleClass="form-button" >
<!--<f:ajax execute="@form" listener="#{contactView.valider}" event="click" render="formulaireContactP"/>-->
</a4j:commandButton>
</a4j:outputPanel>
</h:panelGrid>
<a4j:outputPanel>
<h:message for="envoyerMessage" infoClass="champValide"/>
</a4j:outputPanel>
</a4j:region>
</ui:composition>
and the jsf page that includes the form:
<h:form id="formulaireContact" prependId="false">
<ui:include src="/WEB-INF/include/formulaire-contact.xhtml"/>
</h:form>
I would be very grateful for some help...
Thanks in advance,
J.