我在使用属性"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>如果我在代码中添加了一个TAB视图,则所需的字段验证将不再有效,如下所示:
<!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>我不会在这里发布我尝试过的一切,但他们可以肯定我已经尝试过使用教程中概述的各种方法,其他用户的问题等。
尽管如此,我还是不能理解我哪里错了,你想给我一些提示,这样我就可以正确地执行验证了。
基本上,我的必需属性应该是动态的,根据表单中的字段填充与否。
提前感谢大家。
发布于 2013-03-30 05:22:53
如果您查看API文档http://www.primefaces.org/docs/api/3.5/org/primefaces/component/tabview/TabView.html
tabview正在实现javax.faces.component.NamingContainer,因此您需要使用命名容器分隔符":“来包含它的id。
form:tabView:input3发布于 2013-03-30 04:57:16
可能通过添加和,您更改了参数‘for :inputX’的路径,尝试将其更改为参数‘for:tab1:inputX’或参数‘for:tabView:tab1:inputX’。不确定确切的组合,但真的希望这是错误的原因。
https://stackoverflow.com/questions/15709219
复制相似问题