【问题标题】:JSF difficulty with EL expressionEL 表达式的 JSF 困难
【发布时间】:2013-03-20 12:10:25
【问题描述】:

我在使用“必需”JSF 2 + Prime Faces 3.5 属性时遇到问题。

以下代码完美运行:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 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:p="http://primefaces.org/ui">

<ui:decorate template="/templates/main_template.xhtml">
    <ui:define name="centro">
        <h:head>
        </h:head>
        <h:body>
            <f:view>
                <h:form id="form">

                    <h3>TITLE</h3>



                    <h:panelGrid id="panel1" columns="3">

                        <h:outputLabel for="input1" value="Input1" />
                        <p:inputText id="input1" value="#{controller.myObject.input1}" label="input1" required="#{empty param['form:input3']}"/>
                        <p:message for="input1" />

                        <h:outputLabel for="input2" value="Input2" />
                        <p:inputText id="input2" value="#{controller.myObject.input2}" label="input2" required="#{empty param['form:input3']}"/>
                        <p:message for="input2" />

                        <h:outputLabel for="input3" value="Input3" />
                        <p:inputText id="input3" value="#{controller.myObject.input3}" label="input3" required="#{empty param['form:input1']}"/>
                        <p:message for="input3" />

                    </h:panelGrid>


                    <p:commandButton id="btn" value="Save" update="form" actionListener="#{controller.save}" />

                </h:form>
            </f:view>
        </h:body>
</ui:define>
</ui:decorate>
</html>

如果我在代码中添加 TAB VIEW,必填字段验证将不再起作用,如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 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:p="http://primefaces.org/ui">

<ui:decorate template="/templates/main_template.xhtml">
    <ui:define name="centro">
        <h:head>
        </h:head>
        <h:body>
            <f:view>
                <h:form id="form">

                    <h3>#{msgs.clienteCadastroTitulo}</h3>

                    <p:tabView id="tabView">

                    <p:tab id="tab1" title="TAB 1">


                    <h:panelGrid id="panel1" columns="3">

                        <h:outputLabel for="input1" value="Input1" />
                        <p:inputText id="input1" value="#{controller.myObject.input1}" label="input1" required="#{empty param['form:input3']}"/>
                        <p:message for="input1" />

                        <h:outputLabel for="input2" value="Input2" />
                        <p:inputText id="input2" value="#{controller.myObject.input2}" label="input2" required="#{empty param['form:input3']}"/>
                        <p:message for="input2" />

                        <h:outputLabel for="input3" value="Input3" />
                        <p:inputText id="input3" value="#{controller.myObject.input3}" label="input3" required="#{empty param['form:input1']}"/>
                        <p:message for="input3" />
                    </h:panelGrid>

                    </p:tab>

                    </p:tabView>

                    <p:commandButton id="btn" value="Save" update="form" actionListener="#{controller.save}" />

                </h:form>
            </f:view>
        </h:body>
    </ui:define>
</ui:decorate>
</html>

我不会在这里发布我尝试过的所有内容,但他们可以肯定我已经尝试过使用教程中概述的各种方法、其他用户的问题等。

我仍然不明白我哪里出错了,你想给我一些提示,以便我可以正确地执行我的验证。

基本上,我需要的属性应该是动态的,取决于我表单中的字段是否填写。

提前谢谢大家。

【问题讨论】:

  • 我认为你不能像那样动态地使用所需的值。您需要检查 save 方法中的空值并根据您的逻辑抛出验证异常。

标签: java validation jsf-2 el required


【解决方案1】:

如果您查看 API 文档 http://www.primefaces.org/docs/api/3.5/org/primefaces/component/tabview/TabView.html

tabview 正在实现 javax.faces.component.NamingContainer 所以你需要像这样在命名容器分隔符“:”中包含它的 id

form:tabView:input3

【讨论】:

    【解决方案2】:

    可能通过添加 您更改了 param['form:inputX'] 的路径,尝试将其更改为 param['form:tab1:inputX'] 或 param['form :tabView:tab1:inputX']。不知道确切的组合,但真的希望这是错误的原因。

    【讨论】:

    • klimpond,谢谢。它工作得很好,它是 PATH。它是如此简单,但无法看到,这是给其他人的提示,用 Firebug 进行了 Inscpect 并正确选择了 PATH。谢谢
    猜你喜欢
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 2011-06-24
    • 2014-06-21
    • 1970-01-01
    • 1970-01-01
    • 2013-09-02
    • 2016-07-24
    相关资源
    最近更新 更多