有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JSF与EL表达式的困难

在使用属性“required”JSF2+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>

如果向代码中添加选项卡视图,则所需的字段验证将不再有效,如下所示:

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

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

但我仍然无法理解我哪里出了问题,以及您希望给我什么提示,以便我能够正确执行验证

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

提前谢谢大家


共 (2) 个答案

  1. # 2 楼答案

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