[ 
https://issues.apache.org/jira/browse/WICKET-5039?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13580535#comment-13580535
 ] 

Ernesto Reinaldo Barreiro commented on WICKET-5039:
---------------------------------------------------

Sven,

I think code 

var res = text.match(new RegExp("^([a-z|A-Z_][a-z|A-Z|0-9_]*)\\|((.|\\n)*)$")); 

if (res !== null) { 
var f = jQuery.noop; 
text = "f = function(" + res[1] + ") {" + res[2] + "};"; 

try { 
// do the evaluation 
eval(text); 
f(notify); 
} catch (exception) { 
Wicket.Log.error("Wicket.Ajax.Call.processEvaluation: Exception evaluating 
javascript: " + exception + ", text: " + text); 
} 

} 

will never get called on Wicket 6.x. I have tried the following

<p>
    <a wicket:id="correctexpression">Correct Expression</a>
</p>

and

AjaxLink<Void> correctexpression = new AjaxLink<Void>("correctexpression") {
                        
                        private static final long serialVersionUID = 1L;

                        @Override
                        public void onClick(AjaxRequestTarget target) {
                                
target.appendJavaScript("A|alert('Correct');A();");
                                
target.prependJavaScript("A|alert('Correct');A();");
                                target.addListener(new 
AjaxRequestTarget.IListener() {
                                        
                                        @Override
                                        public void onBeforeRespond(Map<String, 
Component> map,
                                                        AjaxRequestTarget 
target) {
                                                
                                        }
                                        
                                        @Override
                                        public void onAfterRespond(Map<String, 
Component> map,
                                                        IJavaScriptResponse 
response) {
                                                
response.addJavaScript("A|alert('Correct');A();");
                                                
                                        }
                                });
                        }
                };              
                add(correctexpression);

but then generated JavaScript will be 

INFO:
<?xml version="1.0" 
encoding="UTF-8"?><ajax-response><evaluate><![CDATA[(function(){A|alert('Correct');A();})();]]></evaluate><priority-evaluate><![CDATA[(function(){A|alert('Correct');A();})();]]></priority-evaluate><evaluate><![CDATA[(function(){A|alert('Correct');A();})();]]></evaluate></ajax-response>
ERROR: Wicket.Ajax.Call.processEvaluation: Exception evaluating javascript: 
ReferenceError: A is not defined, text: (function(){A|alert('Correct');A();})();
ERROR: Wicket.Ajax.Call.processEvaluation: Exception evaluating javascript: 
ReferenceError: A is not defined, text: (function(){A|alert('Correct');A();})();
ERROR: Wicket.Ajax.Call.processEvaluation: Exception evaluating javascript: 
ReferenceError: A is not defined, text: (function(){A|alert('Correct');A();})();
INFO: Response processed successfully.
INFO: refocus last focused component not needed/allowed
INFO: focus removed from correctexpression2
INFO: focus set on wicketDebugLink
INFO: focus removed from wicketDebugLink


Then because of the "anonymous" function (function(){ ...})(); around 
expression it will  never match regular expression. So, feature A|...A(); is 
not really supported on 6.x

                
> ajax post call handlers might not get called because of failure on AJAX 
> processEvaluation function
> --------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-5039
>                 URL: https://issues.apache.org/jira/browse/WICKET-5039
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4.21, 1.5.8, 6.5.0
>         Environment: any
>            Reporter: Ernesto Reinaldo Barreiro
>            Priority: Trivial
>         Attachments: WICKET-5039.patch
>
>   Original Estimate: 0h
>  Remaining Estimate: 0h
>
> We are having problems on Wicket 1.4.x with and "AJAX function" 
> processEvaluation... and I see the code is practically the same at 6.x. So, 
> let's bring the subject to the list... 
> Our problem is that after evaluating some expressions with errors, screen 
> "freezes" because post-call handlers are not called. Problem seems to be 
> related to the code. 
>                                 // test if the javascript is in form of 
> identifier|code
>                               // if it is, we allow for letting the 
> javascript decide when the rest of processing will continue
>                               // by invoking identifier();
>                               var res = text.match(new 
> RegExp("^([a-z|A-Z_][a-z|A-Z|0-9_]*)\\|((.|\\n)*)$"));
>                               if (res !== null) {
>                                       var f = jQuery.noop;
>                                       text = "f = function(" + res[1] + ") {" 
> + res[2] + "};";
>                                       try {
>                                               // do the evaluation
>                                               eval(text);
>                                               f(notify);
>                                       } catch (exception) {
>                                               
> Wicket.Log.error("Wicket.Ajax.Call.processEvaluation: Exception evaluating 
> javascript: " + exception + ", text: " + text);
>                                       }
>                               } 
>  In case of error. Shouldn't it be
>                                       try {
>                                               // do the evaluation
>                                               eval(text);
>                                               f(notify);
>                                       } catch (exception) {
>                                               
> Wicket.Log.error("Wicket.Ajax.Call.processEvaluation: Exception evaluating 
> javascript: " + exception + ", text: " + text);
>                                                 notify();
>                                       }
> So that next steps in processing get called. The above solves or freezing 
> problem in case of error

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to