我在托管 bean 中有 if 条件。我想在条件为真时显示警报。我该怎么做?就像是:
public void catInsert()
{
if(abr.searchCategoryByCategoryName(CategoryName)!=null){
// msg = "<div style = 'color:red'>CategoryName already exist!</div>";
// System.out.println(msg);
// i want alert here
}else
{
abr.addCategory(CategoryName);
CategoryName="";
}
}
而xhtml页面是;
<table class="nostyle">
<tr>
<td align="right">
<h:outputText value="Category Name:"></h:outputText>
</td>
<td>
<h:inputText id="txtcatname" value="#{categoryBean.categoryName}" required="true" requiredMessage="Enter category Name" >
</h:inputText>
</td>
<td ><h:message for="txtcatname" style="color: #df0000"></h:message></td>>
</tr>
<tr>
<td></td>
<td align="left">
<h:commandButton id="submit" type="Submit" value="submit" action="#{categoryBean.catInsert()}" >
</h:commandButton>
</td>
</tr>
</table>