Code: Select all
<h2>Create New Category</h2>
<h:form id="mqCreateForm">
<h:panelGrid cellspacing="4" columns="3">
<h:outputLabel value="Category Name:" />
<p:inputText id="mqCat" size="30"
value="#{maintCategory.newCategory.name}"
/>
<p:message for="mqCat" />
<h:outputLabel value="Count:" />
<h:outputText value="#{maintCategory.count}" />
</h:panelGrid>
<p:commandButton value="Create New Category"
actionListener="#{maintCategory.doNewCategory}"
update=":mqCreateForm :mqForm:mqDataTable" />
<br/>
<p:messages />
</h:form>
Code: Select all
FacesContext fc = FacesContext.getCurrentInstance();
FacesMessage fm = null;
String s = newCategory.getName();
if (s == null || s.isEmpty()) {
fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Not Created",
"Category Name May Not Be Empty");
fc.addMessage("mqCat", fm);
}
// if an error occured, just return
if (fm != null) return null;
The showcase example doesn't show this pattern -- where an fc.addMessage(clientID .. case is used. Is this supposed to work or am I doing something wrong? This seems like a textbook example.