开发者

Composite component re-created during RENDER_RESPONSE

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" tar开发者_开发知识库get="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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜