I have a command button on my page.
<h:commandButton id="makeSearch" value="#{msg.makeWycena}">
<f:ajax event="click" render="@all" listener="#{searchBean.makeSearch()}"/>
</h:commandButton>
makeSearch()
method first checks value from database, and if this value is null
it performs some logic. But when the value isn't null
, then I would like to display an error message.
I thought about making <h:outputtext rendered = {not null XXX}/>
and make special variable XXX for that reason, but I'm pretty much sure it can be done with plain <h:message />
form, but can't find how.
My code looks like this :
else {
FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage(null , new FacesMessage("XXXXXXXX"));
return null;
}
I want the message XXXXXXXXX to be displayed in:
<h:message for="makeSearch" globalOnly="true" style="color:red;margin:8px;"/>
next to command button I posted before. Right now it's rendered at the bottom of a page
After few changes my code looks like this right now :
<h:form id="detailsForm" prependId="false">
<h:commandButton id="makeSearch" value="#{msg.makeWycena}">
<f:ajax event="click" render="@all" listener="#{searchBean.makeSearch()}"/>
</h:commandButton>
<h:message for="makeSearch" id ="makeSearchError" style="color:red;margin:6px;left-margin:10px;"/>
and bean code :
else {FacesContext.getCurrentInstance().addMessage("detailsForm:makeSearchError" ,
new FacesMessage("XXXXXXXXXXXX")); }
but still. message don't render in h:message. I tried also detailForm:makeSeach and it didn't help either