UIForm用prependId ="假"休息< F:AJAX渲染> [英] UIForm with prependId="false" breaks <f:ajax render>

查看:343
本文介绍了UIForm用prependId ="假"休息< F:AJAX渲染>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于这个事实背后的理念问题,只有 UIForm 得到了属性 prependId 。为什么属性没有在 NamingContainer 接口指定?现在,您可能会说,这是因为其向后兼容性,但我会preferre打破compability,让它们实现该接口的用户,也实现了prependId事情的方法。

I have a question about the idea behind the fact, that only UIForm got the attribute prependId. Why is the attribute not specified in the NamingContainer interface? You will now probably say that's because of backward compability but I would preferre breaking the compability and let users which implement that interface, also implement methods for the prependId thing.

从我的角度对prependId在 UIForm 组件的主要问题是,它将打破 findComponent() 我希望,如果我用 prependId ,那么 NamingContainer 行为将发生变化,不仅关系到渲染同时也希望,当搜索组件,在组件树。

The main problem from my perspective about the prependId in the UIForm component is, that it will break findComponent() I would expect that if I use prependId, then the NamingContainer behaviour would change, not only related to rendering but also when wanting to search for components in the component tree.

下面一个简单的例子:

<h:form id="test" prependId="false">
  <h:panelGroup id="group"/>
</h:form>

现在,当我想要得到的panelGroup中组件我希望到字符串传递给方法 findComponent(),但它不会找到任何东西,我必须使用。测试:组而不是

Now when i want to get the panelGroup component I would expect to pass the string "group" to the method findComponent(), but it won't find anything, I have to use "test:group" instead.

具体问题,那就是,使用Ajax和 prependId =当假。阿贾克斯标签预计的属性更新和工艺,该数值关心命名容器。这是一个有些奇怪,当我使用 prependId =假,我必须指定完整的ID或路径,但没关系。

The concrete problem with that is, when using ajax with prependId="false". The ajax tag expects in the attributes update and process, that the values care of naming containers. It's a bit strange that when I use prependId="false" that I have to specify the full id or path, but okay.

<h:form id="test" prependId="false">
  <h:panelGroup id="group"/>
</h:form>
<h:form id="test1" prependId="false">
  <h:commandButton value="go">
    <f:ajax render="test:group"/>
  </h:commandButton>
</h:form>

嗯,这code将使没有问题,但它不会更新panelGroup中,因为它无法找到它。该 PartialViewContext 将只包含ID 作为renderIds的元素。我不知道,如果这种预期,可能是,但我不知道code。现在,我们来的地步方法 findComponent()找不到组件,因为作为参数传递前pression是,其中该方法所期望的。测试:组找到组件

Well this code will render without problems but it won't update the panelGroup because it cannot find it. The PartialViewContext will contain only the id "group" as element of the renderIds. I don't know if this is expected, probably it is but I don't know the code. Now we come to the point where the method findComponent() can not find the component because the expression passed as parameter is "group" where the method would expect "test:group" to find the component.

解决方案之一是写自己的 findComponent()这是我选择来处理这个问题的方式。在这种方法中我处理一个组件,它是一个 NamingContainer ,其属性prependId设置为false像一个正常的 UIComponent 。我将不得不做,每 UIComponent 它提供了一个prependId属性,这是不好的。反思,将有助于避开类型的静态定义,但它仍然不是一个真正干净的解决方案。

One solution is to write your own findComponent() which is the way I chose to deal with this problem. In this method i handle a component which is a NamingContainer and has the property prependId set to false like a normal UIComponent. I will have to do that for every UIComponent which offers a prependId attribute and that is bad. Reflection will help to get around the static definition of types but it's still not a really clean solution.

另一种方法会引入在 NamingContainer 接口prependId属性,并更改 findComponent的行为()工作像上面描述。

The other way would be introducing the prependId attribute in the NamingContainer interface and change the behaviour of findComponent() to work like described above.

最后提出的解决办法是改变了ajax标签的行为,通过全ID,但这只是解决了AJAX的问题,而不是背后的 findComponent()的实施。

The last proposed solution would be changing the behaviour of the ajax tag to pass the whole id, but this would only solve the ajax issue and not the programmatic issues behind the findComponent() implementation.

你怎么想到这一点,为什么是啥玩意实现这样呢?我不能成为第一个有这个问题,但我没能找到相关的话题?!

What do you think about that and why the hell is it implemented like that? I can't be the first having this problem, but I wasn't able to find related topics?!

推荐答案

事实上, UIComponent#findComponent()作为秉乘&LT; F: AJAX渲染&GT; 在使用失败&LT; H:形式prependId =假&GT; 。这个问题被称为是一个不会解决: JSF规范问题573

Indeed, UIComponent#findComponent() as done by <f:ajax render> fails when using <h:form prependId="false">. This problem is known and is a "Won't fix": JSF spec issue 573.

在我的愚见,他们根本就不应该加入 prependId 属性添加到 UIForm 在JSF 1.2时代。它只是做是为了让 j_security_check 用户满意谁愿意使用带有JSF输入组件的( j_security_check 需要精确的输入字段名为j_username 为j_password 不可能由配置进行修改)。但是,他们并没有完全认识到JSF 1.2中的另一项改进是引入了可让您只需继续使用&LT;形式GT; 为,而不是坚持&LT; H:形式GT; 。然后CSS / jQuery的纯粹主义者开始滥用 prependId =假,以避免转义分隔符的他们选择不当的CSS选择器。

In my humble opinion, they should never have added the prependId attribute to the UIForm during the JSF 1.2 ages. It was merely done to keep j_security_check users happy who would like to use a JSF form with JSF input components for that (j_security_check requires exact input field names j_username and j_password which couldn't be modified by configuration). But they didn't exactly realize that during JSF 1.2 another improvement was introduced which enables you to just keep using <form> for that instead of sticking to <h:form>. And then CSS/jQuery purists start abusing prependId="false" to avoid escaping the separator character : in their poorly chosen CSS selectors.

只要不使用 prependId =假,直到永远。

Just don't use prependId="false", ever.

有关 j_security_check ,只需使用&LT;形式GT; 或新的Servlet 3.0 的HttpServletRequest #login()。另请参见<一个href="http://stackoverflow.com/questions/2206911/performing-user-authentication-in-java-ee-jsf-using-j-security-check/2207147#2207147">Performing使用j_security_check 中的Java EE / JSF用户身份验证。

For j_security_check, just use <form> or the new Servlet 3.0 HttpServletRequest#login(). See also Performing user authentication in Java EE / JSF using j_security_check.

有关CSS选择器,如果你确实需要一个ID选择器(因此没有更多的可重复使用的类选择器),简单地包裹在一个普通的HTML感兴趣的组件&LT; D​​IV&GT; &LT;跨度&GT;

For CSS selectors, in case you absolutely need an ID selector (and thus not a more reusable class selector), simply wrap the component of interest in a plain HTML <div> or <span>.

  • 如何使用jQuery选择JSF组件?
  • <一个href="http://stackoverflow.com/questions/5878692/how-to-use-jsf-generated-html-element-id-with-colon-in-css-selectors">How使用JSF生成与结肠癌和QUOT HTML元素的ID;:&QUOT;在CSS选择器?
  • <一个href="http://stackoverflow.com/questions/10726653/by-default-jsf-generates-unusable-ids-which-are-incompatible-with-css-part-of">By默认情况下,JSF会生成无法使用的ID,这是与Web标准的CSS部分
  • 不兼容
  • How to select JSF components using jQuery?
  • How to use JSF generated HTML element ID with colon ":" in CSS selectors?
  • By default, JSF generates unusable ids, which are incompatible with css part of web standards

这篇关于UIForm用prependId =&QUOT;假&QUOT;休息&LT; F:AJAX渲染&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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