JSF 2复合和绑定验证 [英] JSF 2 composites and binding for validation

查看:80
本文介绍了JSF 2复合和绑定验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个JSF复合问题,它验证了内部输入字段。
以下代码段只要包含一个复合词即可。

I have a problem with a JSF composite which validates internal input fields. Following code snippet works as long as only one composite is included.

<div id="#{cc.clientId}" >
  <h:panelGroup styleClass="#{not firstname.valid ? 'fmError' : ''}">
    <div class="col220">
        <h:outputLabel for="firstname" value="Vorname(n):" />
    </div>
    <div class="col220">
        <h:inputText id="firstname" styleClass="fmTxt " 
            value="#{cc.attrs.person.firstname}" binding="#{firstname}">
            <f:validateRequired />
        </h:inputText>

    </div>
  </h:panelGroup>
</div>

正如您所见,我使用cc.clientId用于包装复合并具有复合内部组件的唯一ID。因此,可以在一个页面上包含多个复合体。

As you can see I use the cc.clientId to wrap the composite and having unique IDs for the components inside the composite. So it is possible to include more than one composites on a single page.

问题始于验证和绑定inputText组件的需要。我需要这个来询问panelGroup中的验证结果,不仅突出显示inputField而且还突出显示标签。

The problems starts with the validation and the need to bind the inputText component. I need this to ask the validation outcome in the panelGroup for highlighting not only the inputField but also the label.

当在页面上只使用一个复合时,此代码工作正常。使用第二个时,inputField的'firstname'不再显示。我想这与绑定及其硬编码'#{firstname}'有关。

This code is working perfectly when using only one composite on a page. When using a second one, the inputField 'firstname' is not shown anymore. I guess it has to do with the binding and its hardcoded '#{firstname}'.

现在的问题是:如何为绑定属性创建唯一标识符?

Now the question: How can I create a unique identifier for the binding attribute?

我很感激任何提示。谢谢!

I'm thankful for any hint. Thanks!

推荐答案

我建议创建一个具有唯一ID的别名,并将其存储在请求范围内。

I suggest to create an alias with an unique ID and store it in request scope.

<div id="#{cc.clientId}">
  <ui:param name="firstname" value="#{cc.clientId}_firstname" />
  <h:panelGroup styleClass="#{not requestScope[firstname].valid ? 'error' : ''}">
    <div class="col220">
        <h:outputLabel for="firstname" value="Vorname(n):" />
    </div>
    <div class="col220">
        <h:inputText id="firstname" styleClass="fmTxt " 
            value="#{cc.attrs.value}" binding="#{requestScope[firstname]}">
            <f:validateRequired />
        </h:inputText>

    </div>
  </h:panelGroup>
</div>

这篇关于JSF 2复合和绑定验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆