开发者

How to display the appropriate message (info or warn) in s:decorate?

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 bea开发者_StackOverflown.

    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">

    <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>


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


Change the code to

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

Hopefully it should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜