[英]JSF difficulty with EL expression
使用屬性“必需” 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>
我不會在這里發布我嘗試過的所有內容,但是他們可以確保我已經嘗試過使用教程概述的各種方法,其他用戶的問題等。
仍然我不明白我要去哪里哪里以及您想給我一些提示,以便我可以正確執行驗證。
基本上,我的必填屬性應根據表單中的填充域動態變化,而不是根據表單中的字段動態變化。
謝謝大家。
如果您查看API文檔http://www.primefaces.org/docs/api/3.5/org/primefaces/component/tabview/TabView.html
tabview正在實現javax.faces.component.NamingContainer,因此您還需要在命名容器分隔符“:”中包含其ID,如下所示:
form:tabView:input3
可能是通過添加<p:tabView>和<p:tab>來更改param ['form:inputX']的路徑,嘗試將其更改為param ['form:tab1:inputX']或param ['form:tabView: tab1:inputX']。 不確定確切的組合,但真的希望這是錯誤的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.