JSF验证消息未显示在模板的内容部分中

时间:2017-01-29 19:04:40

标签: html jsf

当我使用模板时,我的表单上出现了非显示验证错误消息的问题。

它确认验证正常,因为我可以看到我没有转发到下一页,但我没有看到错误消息。

当我在没有定义布局模板部分的情况下尝试相同的代码时,它会打印消息。

这是我的表单代码:

<h:form>
        <h:panelGrid columns="2">
            <h:outputLabel for="mname">Username&nbsp;</h:outputLabel>
            <h:inputText required="true" requiredMessage="Username is required.">

            </h:inputText>                                
            <h:commandButton value="Submit"></h:commandButton>
        </h:panelGrid>
</h:form>

当我定义内容时,这是我的代码 part:

        <!-- Content -->
        <ui:define name="content">               
            <h:form>
                <h:panelGrid columns="2">
                    <h:outputLabel for="mname">Username&nbsp;</h:outputLabel>
                    <h:inputText required="true" requiredMessage="Username is required.">

                    </h:inputText>                                
                    <h:commandButton value="Submit"></h:commandButton>
                </h:panelGrid>
            </h:form>
        </ui:define>

任何人都有理由在我定义布局页面时看不到错误消息。

这是我的layout.xhtml内容部分。

<div id="content">
        <ui:insert name="content">
            <ui:include src="/template/content.xhtml" />
        </ui:insert>
</div>

1 个答案:

答案 0 :(得分:1)

最终你需要一个h:message标签.. requiredMessage是关于在消息标签中打印什么的框架的提示。

所以你应该有一个像:

这样的设置
<h:form>
    <h:message showSummary="true" showDetail="false"
        id="errorsMessages"
        for="txt"/>
        <h:panelGrid columns="2">
            <h:outputLabel for="mname">Username&nbsp;</h:outputLabel>
            <h:inputText id="txt" required="true" requiredMessage="Username is required.">

            </h:inputText>                                
            <h:commandButton value="Submit"></h:commandButton>
        </h:panelGrid>
</h:form>
相关问题