views:

464

answers:

1

I am actually checking for availability of a login name and would like to show the info image or warn image with an appropriate message. Currently we get 2 error messages on non availability of a login name.

            <s:decorate id="loginIdField" template="/layout/edit.xhtml">
                <ui:define name="label">Desired Login Name</ui:define>
                <a:region>
                    <h:inputText id="loginId" required="true" value="#{userHome.instance.loginId}"/>
                    <s:message warnStyle="color: red" infoStyle="color: green"/>
                    <div class="actionButtons">
                        <a:commandButton id="submit" value="Check Availability"
                            action="#{userHome.isUnique(userHome.instance.loginId)}" reRender="loginIdField"/>
                    </div>
                </a:region>
            </s:decorate>

Code to add appropriate messages in the bean.

    if (!unique) {
        statusMessages
                .addToControlFromResourceBundle(
                        "loginId",
                        WARN,
                        "LoginIdNotUnique",
                        new Object[] { inputLoginId });
    } else {
        statusMessages.addToControlFromResourceBundle("loginId", INFO,
                "LoginIdUnique",
                new Object[] { inputLoginId });
    }

edit.xhtml

<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:rich="http://richfaces.org/rich"
                 xmlns:s="http://jboss.com/products/seam/taglib"&gt;

    <div class="prop">

        <s:label styleClass="name #{invalid?'errors':''}">
            <ui:insert name="label"/>
            <s:span styleClass="required" rendered="#{required}">*</s:span>
        </s:label>
        <div style="clear: both"/>

        <span class="value #{invalid?'errors':''}">
            <s:validateAll>
                <ui:insert/>
            </s:validateAll>
        </span>

        <span class="error">
            <h:graphicImage value="/img/error.gif" rendered="#{invalid}" styleClass="errors"/>
            <s:message styleClass="errors"/>
        </span>

    </div>

</ui:composition>
+1  A: 

Maybe it's the template? Have you tried this without the template?

Joshua Davis