[
https://issues.apache.org/jira/browse/MYFACES-2640?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12854020#action_12854020
]
Werner Punz edited comment on MYFACES-2640 at 4/6/10 3:20 PM:
--------------------------------------------------------------
Ok I wrote myself a small testcase and ran it against myfaces and Mojarra to
make sure to get the picture right:
what happens is:
super.encodeBegin(context, component);
ResponseWriter writer = context.getResponseWriter();
writer.startElement("div", component);
writer.writeAttribute("id",component.getClientId(context), null );
writer.write("hello world"+Math.random());
writer.endElement("div");
writer = context.getResponseWriter();
writer.startElement("div", component);
writer.writeAttribute("id",component.getClientId(context)+":_second",
null );
writer.write("hello world"+Math.random());
writer.endElement("div");
MyFaces id wrong here it constantly adds more or less the div at refresh
because of the insert code, but what happens in Mojarra is following:
it cherry pics the writer.startElement("div", component);
writer.writeAttribute("id",component.getClientId(context), null );
writer.write("hello world"+Math.random());
writer.endElement("div");
and omits the second part:
writer = context.getResponseWriter();
writer.startElement("div", component);
writer.writeAttribute("id",component.getClientId(context)+":_second",
null );
writer.write("hello world"+Math.random());
writer.endElement("div");
hence only the first element in my testcase is updated.
I am willing to follow this approach, but I am not sure it is the correct one,
I am not even sure if you can get it right, in either way, the fix for me is
simply to follow mojarras approach of cherry picking the correct element with
the same identifier (recursively) to get the same behavior over both
implementations.
So Mark you approach is basically the one Mojarra does and in this case I will
gladly use your code.
Werner
was (Author: werpu):
Ok I wrote myself a small testcase and ran it against myfaces and Mojarra
to make sure to get the picture right:
what happens is:
super.encodeBegin(context, component);
ResponseWriter writer = context.getResponseWriter();
writer.startElement("div", component);
writer.writeAttribute("id",component.getClientId(context), null );
writer.write("hello world"+Math.random());
writer.endElement("div");
writer = context.getResponseWriter();
writer.startElement("div", component);
writer.writeAttribute("id",component.getClientId(context)+":_second",
null );
writer.write("hello world"+Math.random());
writer.endElement("div");
MyFaces id wrong here it constantly adds more or less the div at refresh
because of the insert code, but what happens in Mojarra is following:
it cherry pics the writer.startElement("div", component);
writer.writeAttribute("id",component.getClientId(context), null );
writer.write("hello world"+Math.random());
writer.endElement("div");
and omits the second part:
writer = context.getResponseWriter();
writer.startElement("div", component);
writer.writeAttribute("id",component.getClientId(context)+":_second",
null );
writer.write("hello world"+Math.random());
writer.endElement("div");
hence only the first element in my testcase is updated.
I am willing to follow this approach, but I am not sure it is the correct one,
I am not even sure if you can get it right, in either way, the fix for me is
simply to follow mojarras approach of cherry picking the correct element with
the same identifier (recursively) to get the same behavior over both
implementations.
> (JSF.js) Ajax Render component problem, replace with whole fragment not one
> element.
> ------------------------------------------------------------------------------------
>
> Key: MYFACES-2640
> URL: https://issues.apache.org/jira/browse/MYFACES-2640
> Project: MyFaces Core
> Issue Type: Bug
> Components: JSR-314
> Affects Versions: 2.0.0-beta-3
> Environment: tomcat 6.0.20 java (mac os x )
> Reporter: Mark Li
> Original Estimate: 4h
> Remaining Estimate: 4h
>
> after ajax submit, jsf.js will re-render some element depending on
> jsf.ajax.request({render:" some elements "});
> but this js code will cause some problem.
> jsf.js:
> myfaces._impl._util._Utils.replaceHtmlItem = function (request, context,
> itemIdToReplace, newTag, form) {
> ......
> var fragment = range.createContextualFragment(newTag);
> evalNode = item.parentNode.replaceChild(fragment, item)
> .....
> }
> sometime fragment will has more than one childNodes, or the childNode not has
> clientId, but the childNode of childNode has clientId.
> this will cause html unstable.
> Please fix it.
> this is my suggestion:
> myfaces._impl._util._Utils.replaceHtmlItem = function (request, context,
> itemIdToReplace, newTag, form) {
> .............
> Orginal:
> var fragment = range.createContextualFragment(newTag);
> evalNode = item.parentNode.replaceChild(fragment, item)
> fix:
> var fragment = range.createContextualFragment(newTag);
> var replaceItem =
> myfaces._impl._util._Utils.findHtmlItemFromFragment(fragment,
> itemIdToReplace);
> if(replaceItem == null)replaceItem = fragment;
> evalNode = item.parentNode.replaceChild(replaceItem, item)
> ..................
> }
> myfaces._impl._util._Utils.findHtmlItemFromFragment = function(fragment,
> itemId){
> if(fragment.childNodes == null)
> return null;
> for(var i = 0; i < fragment.childNodes.length ; i++ ){
> var c = fragment.childNodes[i];
> if(c.id == itemId)
> return c;
> }
> for(var i = 0; i < fragment.childNodes.length ; i++ ){
> var c = fragment.childNodes[i];
> var item =
> myfaces._impl._util._Utils.findHtmlItemFromFragment(c, itemId);
> if(item != null)
> return item;
> }
> return null;
> };
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.