我有以下复合组件,我想使用 o:validateMultipleFields(更具体地说是 o:validateAllOrNone)。
<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:composite="http://java.sun.com/jsf/composite"
>
<composite:interface>
<composite:attribute name="target" />
<composite:attribute name="label"/>
<composite:attribute name="value" />
<composite:attribute name="required" />
<composite:attribute name="size" />
<composite:attribute name="disabled" />
<composite:attribute name="styleInput" required="false" />
<composite:editableValueHolder name="input" targets="input" />
<composite:clientBehavior name="change" event="change" targets="#{cc.attrs.target}" />
<composite:clientBehavior name="keypress" event="keypress" targets="#{cc.attrs.target}" />
</composite:interface>
<composite:implementation>
<p:outputLabel id="label" for="input" value="#{cc.attrs.label}" />
<h:panelGrid columns="3">
<p:inputText id="input" value="#{cc.attrs.value}"
style="#{cc.attrs.styleInput}" size="#{cc.attrs.size}"
disabled="#{cc.attrs.disabled}" required="#{cc.attrs.required}">
</p:inputText>
<p:message for="input" display="icon">
<p:effect type="pulsate" event="load" delay="500" />
</p:message>
</h:panelGrid>
</composite:implementation>
</html>
验证按预期工作,但 components
属性上指定的组件标签未显示。相反,它显示组件 ID。
<cetcomp:editar id="origem" label="Origem" size="10" />
<cetcomp:editar id="cst" label="CST" size="10" />
<o:validateAllOrNone id="origemCst" components="origem:input cst:input" showMessageFor="origem:input" />
最佳答案
ValidateMultipleFields
从 label
中提取标签物理输入组件的属性。这些标签也将在标准 JSF 验证中使用。你确实没有,它们只设置在<p:outputLabel>
上.
相应地添加它们:
<p:inputText ... label="#{cc.attrs.label}">
另一种方法是使用 <o:outputLabel>
而不是<p:outputLabel>
因为 OmniFaces 会自动将标签复制到关联的输入组件。
<o:outputLabel ... for="input" value="#{cc.attrs.label}" />
<p:inputText id="input" ... />
更新:事实证明它实际上仍然不起作用。 #{cc}
ValidateMultipleFields
期间不可用正在提取标签。此问题已按照 issue 134 修复。它将在 OmniFaces 2.1 中提供。
关于jsf - 复合组件标签和o :validateMultipleFields,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30495389/