在 RENDER_RESPONSE 期间重新创建复合组件
我正在尝试编写一个复合组件,可以将焦点设置到第一个验证失败的 UIIInput 上。
我的问题是 RENDER_RESPONSE 正在从 xhtml 重新创建我的复合组件,而不是简单地对我在 PROCESS_VALIDATIONS 期间更新的实例进行编码。我正在使用 Mojarra 2.0.4 (FCS b09)
复合实现是
<h:outputScript name="jfocus.js" library="js" target="head"/>
<h:panelGroup layout="span" id="jimo-FocusMgr">
<script type="text/javascript">
jimo.FocusMgr.request("#{cc.attrs.target}");
</script>
</h:panelGroup>
我的侦听器中的以下代码是在 After PhaseId.PROCESS_VALIDATIONS 期间设置复合的目标属性,并将复合的(唯一)子项添加到 renderIds 列表中。调试输出显示 prevEntry 是使用页面设置到组件中的值,failedId 是无效 UIInput 的 clientId()。
//set the target attribute of the composite component
Object prevEntry = mgr.getAttributes().put("target", failedId);
if(log.isDebugEnabled())
log.debug("Set mgr's target attribute='"+failedId
+"', previously='"+(prevEntry==null ? "null" : prevEntry.toString()+"'"));
PartialViewContext pvc = fc.getPartialViewContext();
Collection<String> renderids = pvc.getRenderIds();
//update target has to be an official component in the DOM, so append the child panelGroup ID
if(!renderids.contains(mgr.getClientId()))
pvc.getRenderIds().add(mgr.getClientId()+UINamingContainer.getSeparatorChar(fc)+MGR_ID);
//first invalid component wins
break;
在 PhaseId.RENDER_RESPONSE 之前调用 mgr.getAttributes().get("target") 会继续显示 failedID,但在 PhaseId.RENDER_RESPONSE 之后调用 mgr.getAttributes().get("target") 会显示目标已恢复为使用页面的值。
这是一个错误,还是我滥用/误用了复合材料?
任何指点将不胜感激
吉姆
I am trying to write a composite component that can set focus to the first UIINput that failed validation.
My problem is that RENDER_RESPONSE is recreating my composite component from it's xhtml, rather than simply encoding the instance that I'm updating during PROCESS_VALIDATIONS. I'm using Mojarra 2.0.4 (FCS b09)
The composite implementation is
<h:outputScript name="jfocus.js" library="js" target="head"/>
<h:panelGroup layout="span" id="jimo-FocusMgr">
<script type="text/javascript">
jimo.FocusMgr.request("#{cc.attrs.target}");
</script>
</h:panelGroup>
The following code in my listener is what sets the target attribute of the composite during After PhaseId.PROCESS_VALIDATIONS, and adds the composite's (only)child to the list of renderIds. The debug output shows that prevEntry is the value that the using page set into the component, and failedId is the clientId() of the invalid UIInput.
//set the target attribute of the composite component
Object prevEntry = mgr.getAttributes().put("target", failedId);
if(log.isDebugEnabled())
log.debug("Set mgr's target attribute='"+failedId
+"', previously='"+(prevEntry==null ? "null" : prevEntry.toString()+"'"));
PartialViewContext pvc = fc.getPartialViewContext();
Collection<String> renderids = pvc.getRenderIds();
//update target has to be an official component in the DOM, so append the child panelGroup ID
if(!renderids.contains(mgr.getClientId()))
pvc.getRenderIds().add(mgr.getClientId()+UINamingContainer.getSeparatorChar(fc)+MGR_ID);
//first invalid component wins
break;
Calling mgr.getAttributes().get("target") during Before PhaseId.RENDER_RESPONSE continues to show the failedID, but the same call during After PhaseId.RENDER_RESPONSE shows that target has reverted back to the using page's value.
Is this a bug, or am I abusing/misusing composites?
Any pointers would be appreciated
Jim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
复合滥用。
您无法以编程方式修改 cc.attrs 值 - 它不是使用其 NamingContainer UIComponent 属性映射来检索的。
调整了实现,让 cc.attr 引用托管Bean 属性,我使用 c:set 在复合 xhtml 中初始化该属性,并且可以通过它的 setter 在侦听器中自由更新。
Composite abuse.
You can't programaticaly modify a cc.attrs value -- it's not retrieved using it's NamingContainer UIComponent attribute map.
Tweaked the implementation to have the cc.attr refer to a managedBean property that I use c:set to initialize in the composite xhtml, and can freely update in my listener via it's setter.