managedBean et <h:message>
Bonjour à tous
j'aurais besoin d'aide sur l'envoi de message d'erreur à une balise <h:message> à partir d'un managedbean
Dans ma page jsp j'ai un champ login qui vérifie dans la BDD si le login est déjà existent ou pas. Pour cela j'utilise un balise <a4j:support action=#{managedBean.doLoginVerif}>
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
public String doLoginVerif(){
System.out.println("cb");
List<Customer> liste = csbl.findCustomers();
for(int i = 0 ; i<liste.size();i++ ){
if ( liste.get(i).getLogin().equals(login)){
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.addMessage("formEnregistrement:error_login2", new FacesMessage(FacesMessage.SEVERITY_ERROR,"le login est déjà présent dans la base",""));
}
et voici une sortie console :
}
return "";
} |
et voici une sortie console :
Code:
1 2 3 4 5
|
sourceId=formEnregistrement:error_login2[severity=(ERROR 2), summary=(le login est déjà présent dans la base), detail=(le login est déjà présent dans la base)];|WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=formEnregistrement:error_login2[severity=(ERROR 2), summary=(le login est déjà présent dans la base), detail=(le login est déjà présent dans la base)] |
ma page jsp :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!-- RichFaces tag declaration-->
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j"%>
<%@taglib prefix="rich" uri="http://richfaces.org/rich"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%--
This file is an entry point for JavaServer Faces application.
--%>
<f:view>
<h:outputText value="Bienvenue sur SAGACITY"/>
<h:panelGrid columns="2" id="panelPrincipal">
<h:form id="formPrincipal">
<h:panelGrid id="panelLogin">
<h:outputText value="Login"/>
<h:inputText id="login" value="#{login.login}" required="true" requiredMessage="Ce champ est obligatoire">
</h:inputText>
<h:message id="error_login"for="login" showDetail="true" style="color: red"/>
<h:outputText value="Password"/>
<h:inputSecret id="pass"value="#{login.password}" required="true" requiredMessage="Ce champs est obligatoire">
</h:inputSecret>
<h:message id="error_pass"for="pass" showDetail="true" style="color: red"/>
<h:commandButton value="Validez" action="#{login.doSignIn}"/>
</h:panelGrid>
</h:form>
<h:form id="formEnregistrement">
<h:outputText value="enregistrez vous"/>
<h:panelGrid columns="1" id="panelEnregistrement">
<h:outputText value="Firstname"/>
<h:inputText id="firstname" value="#{login.firstname}" required="true" requiredMessage="Ce champs est obligatoire"/>
<h:message id="error_firstname"for="firstname" showDetail="true" style="color: red"/>
<h:outputText value="Lastname"/>
<h:inputText id="lastname" value="#{login.lastname}" required="true" requiredMessage="Ce champs est obligatoire"/>
<h:message id="error_lastname"for="lastname" showDetail="true" style="color: red"/>
<a4j:region id="ajax_region_1">
<h:panelGroup>
<h:outputText value="Login"/>
<h:inputText id="login2"value="#{login.login}" required="true" requiredMessage="Ce champs est obligatoire" >
<a4j:support event="onkeyup" reRender="ajax_login2" action="#{login.doLoginVerif}"/>
</h:inputText>
<h:outputText id="ajax_login2" value="#{login.login}"/>
<h:message id="error_login2"for="login2" showDetail="true" style="color: red"/>
<h:outputText id="test"/>
</h:panelGroup>
</a4j:region>
<a4j:region id="password1">
<h:outputText value="Password"/>
<h:inputSecret id="pass2" value="#{login.password}" required="true" requiredMessage="Ce champs est obligatoire">
<a4j:support event="onkeyup" action="#{login.passWordVerif}" reRender="validemotdepass" />
</h:inputSecret>
<h:message id="error_pass2"for="pass2" showDetail="true" style="color: red"/>
</a4j:region>
<a4j:region id="password2">
<h:outputText value="Verif Password"/>
<h:inputSecret id="verif_pass2"value="#{login.password2}" required="true" requiredMessage="Ce champs est obligatoire">
<a4j:support event="onkeyup" action="#{login.passWordVerif}" reRender="validemotdepass" />
</h:inputSecret>
<h:message id="error_verif_pass2"for="verif_pass2" showDetail="true" style="color: red"/>
<h:outputText id="validemotdepass"value="#{login.passwordVerif}" style="color: red"/>
</a4j:region>
<h:outputText value="Email"/>
<h:inputText id="email"value="#{login.email}" required="true" requiredMessage="Ce champs est obligatoire" validator="#{emailvalidation.validate}"/>
<h:message id="error_email"for="email" showDetail="true" style="color: red"/>
<h:commandButton value="Validez" action="#{login.doCreateCustomer}"/>
</h:panelGrid>
</h:form>
</h:panelGrid>
</f:view> |
et pour finir le code généré de ma page web :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<!-- RichFaces tag declaration-->
<script charset="utf-8" id="injection_graph_func" src="chrome://skype_ff_toolbar_win/content/injection_graph_func.js"></script></head><body>Bienvenue sur SAGACITY<link class="component" href="/sagacityWeb/faces/a4j/s/3_3_1.GAorg/richfaces/renderkit/html/css/basic_both.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__" rel="stylesheet" type="text/css"><link class="component" href="/sagacityWeb/faces/a4j/s/3_3_1.GAorg/richfaces/renderkit/html/css/extended_both.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__" rel="stylesheet" type="text/css"><script src="/sagacityWeb/faces/a4j/g/3_3_1.GAorg.ajax4jsf.javascript.AjaxScript" type="text/javascript"></script><script type="text/javascript">window.RICH_FACES_EXTENDED_SKINNING_ON=true;</script><script src="/sagacityWeb/faces/a4j/g/3_3_1.GAorg/richfaces/renderkit/html/scripts/skinning.js" type="text/javascript"></script><table id="panelPrincipal">
<tbody>
<tr>
<td>
<form id="formPrincipal" name="formPrincipal" method="post" action="/sagacityWeb/faces/Login.jsp" enctype="application/x-www-form-urlencoded">
<input name="formPrincipal" value="formPrincipal" type="hidden">
<table id="formPrincipal:panelLogin">
<tbody>
<tr>
<td>Login</td>
</tr>
<tr>
<td><input id="formPrincipal:login" name="formPrincipal:login" type="text"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>Password</td>
</tr>
<tr>
<td><input id="formPrincipal:pass" name="formPrincipal:pass" value="" type="password"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><input name="formPrincipal:j_id_id35" value="Validez" type="submit"></td>
</tr>
</tbody>
</table>
<input name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id1" type="hidden">
</form></td>
<td>
<form id="formEnregistrement" name="formEnregistrement" method="post" action="/sagacityWeb/faces/Login.jsp" enctype="application/x-www-form-urlencoded">
<input name="formEnregistrement" value="formEnregistrement" type="hidden">
enregistrez vous<table id="formEnregistrement:panelEnregistrement">
<tbody>
<tr>
<td>Firstname</td>
</tr>
<tr>
<td><input id="formEnregistrement:firstname" name="formEnregistrement:firstname" type="text"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>Lastname</td>
</tr>
<tr>
<td><input id="formEnregistrement:lastname" name="formEnregistrement:lastname" type="text"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>Login<input id="formEnregistrement:login2" name="formEnregistrement:login2" onkeyup="A4J.AJAX.Submit('formEnregistrement:ajax_region_1','formEnregistrement',event,{'similarityGroupingId':'formEnregistrement:j_id_id65','parameters':{'formEnregistrement:j_id_id65':'formEnregistrement:j_id_id65'} ,'actionUrl':'/sagacityWeb/faces/Login.jsp'} )" type="text"><span id="formEnregistrement:ajax_login2">k</span><span id="formEnregistrement:test"></span></td>
</tr>
<tr>
<td>Password<input id="formEnregistrement:pass2" name="formEnregistrement:pass2" value="" onkeyup="A4J.AJAX.Submit('formEnregistrement:password1','formEnregistrement',event,{'similarityGroupingId':'formEnregistrement:j_id_id82','parameters':{'formEnregistrement:j_id_id82':'formEnregistrement:j_id_id82'} ,'actionUrl':'/sagacityWeb/faces/Login.jsp'} )" type="password"></td>
</tr>
<tr>
<td>Verif Password<input id="formEnregistrement:verif_pass2" name="formEnregistrement:verif_pass2" value="" onkeyup="A4J.AJAX.Submit('formEnregistrement:password2','formEnregistrement',event,{'similarityGroupingId':'formEnregistrement:j_id_id94','parameters':{'formEnregistrement:j_id_id94':'formEnregistrement:j_id_id94'} ,'actionUrl':'/sagacityWeb/faces/Login.jsp'} )" type="password"><span id="formEnregistrement:validemotdepass" style="color: red;"></span></td>
</tr>
<tr>
<td>Email</td>
</tr>
<tr>
<td><input id="formEnregistrement:email" name="formEnregistrement:email" type="text"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><input name="formEnregistrement:j_id_id108" value="Validez" type="submit"></td>
</tr>
</tbody>
</table>
<input name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id1" type="hidden">
</form></td>
</tr>
</tbody>
</table>
<script>A4J.AJAX._scriptEvaluated=true;</script></body></html> |
je ne vois pas pourquoi rien ne s'affiche
j'envoi bien le message à la balise qui à pour id : formEnregistrement:error_login2 à moins que le id ne soit pas correct ou qu'il manque quelque chose
Avez vous une idée ?
Merci