如何在s:装饰中显示适当的信息(信息或警告)?

时间:2023-01-16 20:01:49

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.

在bean中添加适当消息的代码。

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

edit.xhtml

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>

2 个解决方案

#1


1  

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

可能是模板吗?你试过没有模板的吗?

#2


0  

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.

希望它应该工作。

#1


1  

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

可能是模板吗?你试过没有模板的吗?

#2


0  

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.

希望它应该工作。