I have if condition in managed bean. I want to display alert when condition is true. How I do that? something like:
    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="";
            }
         }
and xhtml page is;
<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>
 
    