jsf - How to send a custom FacesMessage to page when the clientId is not actually present -
i using jsf 2.2 on glassfish 4.
i want send messages <h:message .../>
tag.
for below login page, want send custom facesmessage
on login failure clientid login-error
userbean
.
my login.xhtml
:
<h:form id="login-form"> <table> <tr> <td><h:outputlabel value="username" for="username" /></td> <td><h:inputtext id="username" value="#{userbean.username}" /></td> </tr> <tr> <td><h:outputlabel value="password" for="password" /></td> <td><h:inputsecret id="password" value="#{userbean.password}" /></td> </tr> <tr> <td></td> <td><h:commandbutton value="submit" action="#{userbean.login()}" /></td> </tr> </table> <div> <h:message for="login-error" errorclass="err" /> </div> </h:form>
my userbean
:
@named @sessionscoped public class userbean implements serializable { . . . public string login() { if (validate(username, password)) { return "/success?faces-redirect=true"; } facescontext ctx = facescontext.getcurrentinstance(); string msgtext = "username or password incorrect"; facesmessage msg = new facesmessage(facesmessage.severity_error, msgtext, msgtext); ctx.addmessage("login-error", msg ); return ""; } }
i below messages in server console:
2017-04-14t21:43:02.298+0530|warning: unable find component id login-error in view. 2017-04-14t21:43:04.923+0530|warning: unable find component id login-error in view. 2017-04-14t21:43:04.923+0530|info: warning: facesmessage(s) have been enqueued, may not have been displayed. sourceid=login-error[severity=(error 2), summary=(username or password incorrect), detail=(username or password incorrect)]
i've tried using clientid login-form:login-error
didn't work.
so, question how send custom facesmessage page when clientid not present? approach incorrect?
i know can use <h:messages />
instead don't want use it.
Comments
Post a Comment