Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 如何在自定义组件中计算FacesComponent属性_Jsf_Jsf 2_Omnifaces - Fatal编程技术网

Jsf 如何在自定义组件中计算FacesComponent属性

Jsf 如何在自定义组件中计算FacesComponent属性,jsf,jsf-2,omnifaces,Jsf,Jsf 2,Omnifaces,最近,我一直在做一个动态表单项目,但遇到了一个自定义组件问题。我所拥有的: formField的面组件: @FacesComponent(value = "formField") public class FormFieldCompositeComponent { private boolean email; } 自定义组件jsf: <o:validator for="email_text" validatorId="emailValidator" disabled="#{no

最近,我一直在做一个动态表单项目,但遇到了一个自定义组件问题。我所拥有的:

formField的面组件:

@FacesComponent(value = "formField")
public class FormFieldCompositeComponent { 
    private boolean email;
}
自定义组件jsf:

<o:validator for="email_text" validatorId="emailValidator" disabled="#{not cc.email}" />
我的问题是:

1.)如果我使用一个普通的f:validator,就像我上面使用的那样,然后使用c:If来启用/禁用它,那么它将无法工作。根据我读过的一些文章,这是因为f:validator在构建时验证,而不是在呈现时验证

2.)如果我使用o:validator,它可以工作,但问题是每次点击submit时,p:messages中会添加一行新的无效电子邮件错误。例如,我点击提交按钮3次,然后我收到3次电子邮件错误

有什么想法吗

更多信息(项目剖析) 示例我有一个带有字段电子邮件的页面用户,它将包括以下自定义组件:

+user.xhtml
 +formPanel
 +formField (this is where the validator is defined)
  +formButtons (the action button)
  +p:messages is defined
user.xhtml

<formPanel>
  <formField field="email" />
  <formButtons />
</formPanel>

命令按钮类似于(formButtons):


formPanel上定义的p:消息:

<p:messages id="formMessages" showDetail="true" showSummary="false" redisplay="false"></p:messages>

注:
1.)我注意到验证器被调用了n次,其中n是提交或单击完成的次数

xhtml-

标签-


bean组件-

似乎没有机会使用f:validator,所以我通过o:validator找到了一个解决方法。如果错误已在FacesMessages列表中,则需要捕获:

boolean match = false;
for (FacesMessage fm : context.getMessageList()) {
    if (fm.getDetail().equals(message)
            || fm.getSummary().equals(message)) {
        match = true;
        break;
    }
}

if (!match) {
    throw new ValidatorException(facesMessage);
}

可能在
p:messages
上使用
redisplay=false
。您好,p:messages的redisplay已设置为false,因此这不是问题所在。如您之前关于此主题的问题所述,请发布SSCCE。在这种情况下,
for
属性的用法非常奇怪,我无法重新创建您的代码,因此无法重现您的问题。至少,for属性只能在模板客户端上的复合实现之外使用。另请参阅一个真实世界的示例:嗨,巴卢斯,很抱歉。我正在更新上面的文章,以获取真实世界的示例。哦,好吧,这样你就可以嵌套复合材料了。这只是一些没有SSCCE风格的代码,但我现在可以从某个地方开始了。如果我有更多的时间,我会仔细看看。
<formPanel>
  <formField field="email" />
  <formButtons />
</formPanel>
<p:commandButton id="saveButton" rendered="#{cc.attrs.edit}"
    value="#{messages['action.save']}"
    action="#{cc.attrs.backingBean.saveOrUpdate()}" icon="ui-icon-check"
    ajax="#{cc.attrs.ajaxSubmit}">
    <c:if test="#{cc.attrs.backingBean.lcid != null}">
        <f:param name="cid" value="#{cc.attrs.backingBean.lcid}" />
    </c:if>
</p:commandButton>
<p:messages id="formMessages" showDetail="true" showSummary="false" redisplay="false"></p:messages>
boolean match = false;
for (FacesMessage fm : context.getMessageList()) {
    if (fm.getDetail().equals(message)
            || fm.getSummary().equals(message)) {
        match = true;
        break;
    }
}

if (!match) {
    throw new ValidatorException(facesMessage);
}