为什么prependId ="false"?在一个jsf形式? [英] Why prependId="false" in a jsf form?

查看:232
本文介绍了为什么prependId ="false"?在一个jsf形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道prependId="false"的作用.它设置了标志,以使表单的ID不位于子表单的ID的前面,但是为什么呢?您是否愿意在ID前面加上任何特殊原因?

I know what prependId="false" does. It set the flag so that the id of the form does not prepend the id of the form child, but why? any particular reason why you do or dont want to prepend id?

推荐答案

以我的经验,我从不使用此属性.但是,在某些情况下它可能会有用.

In my experience, I never use this attribute. However, in some cases it can be useful.

使用Facelets时,您可以创建模板或将页面包含在另一个页面中.因此,您可以想象一个页面可以包含在几个不同的页面中.以父页面包含form(具有不同ID)的示例为例:

When you use Facelets, you can create templates or include pages inside another page. So you can imagine that a page could be included in several different pages. Take the example where the parent pages contain a form, with different id:

第1页:

<h:form id="form1">
    <ui:include src="pages/my-page.xhtml"/>
    ...
</h:form>

第2页:

<h:form id="form2">
    <ui:include src="pages/my-page.xhtml"/>
    ...
</h:form>

现在,在my-page.xhtml中,您有一个<h:inputText id="foo"/>.在第一种情况下,输入的真实ID为form1:foo,而在第二种情况下,输入的真实ID为form2:foo.如果您需要使用Javascript或Java(使用findComponent("...")方法)直接访问此组件,则可能会导致复杂的情况.

Now, in the my-page.xhtml, you have a <h:inputText id="foo"/>. In the first case, the real ID of the input will be form1:foo, while in the second case, it will be form2:foo. This could create complex situations if you need a direct access to this component in Javascript or in Java (using findComponent("...") method).

如果使用prependId="false"(或在某些组件forceId="true"上),则实际ID将只是foo,然后您的代码将变得更加简单,因为您不必在乎输入字段的容器

If you use prependId="false" (or on some components forceId="true"), the real ID will be simply foo, and then your code will be simpler as you will not have to care about the container of the input field.

但是,您将必须谨慎使用此属性,因为如果您经常使用此prepend属性,则可能会得到重复的ID错误...

However, you will have to use this attribute carefully, as you may get a duplicate ID error if you use this prepend attribute too often...

在现代jsf版本中,它也可能会破坏ajax,请参见带有prependId =的UIForm 假"破坏< f:ajax渲染>

In modern jsf versions it might also break ajax, see UIForm with prependId="false" breaks <f:ajax render>

这篇关于为什么prependId ="false"?在一个jsf形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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