You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Boris Horvat <ho...@gmail.com> on 2014/02/15 19:25:27 UTC

How to pass a javascript function in tapestry mixin

Hi everyone,

I have a tapestr5-jquery component that to which I need to pass a function
in the configuration.

The component is
http://tapestry5-jquery.com/components/docsajaxupload;jsessionid=2CD857F51B90113A175C5B10EE09B138.57B580630AEA

My code looks like this

java

public JSONObject getUploadParams() {
        JSONObject params = new JSONObject();
        params.put("onSubmit", new
JSONLiteral(String.format("showUploadProgress()")));
        return params;
    }

tml file

<j:ajaxUpload t:id="imageUpload" t:multiple="false"
t:params="uploadParams">                                        <noscript>
             <p>JavaScript must be activated!</p>
         </noscript>
 </j:ajaxUpload>

javascript file

function showUploadProgress() {
    var showUploadProgress = function(id, fileName) {
        alert(123)
        $('.photo').removeClass('photo').addClass('photo-progress-reveal');
    }
    return showUploadProgress;
}

Technically speaking the code above works, however it breaks my ajax by
throwing the following errors (on remove server ajax wont even refresh only
error is thrown)

Communication with the server failed: null
Ajax failure: Status 200 for #{request.url}: null
Communication with the server failed: null
Ajax failure: Status 200 for #{request.url}: null
Communication with the server failed: null

I was advised on a certain occasion to user javascript closers (
https://github.com/got5/tapestry5-jquery/issues/244) but as seen above this
doesn't really help.

Does anyone have any better idea how to pass a function from configuration
to tapestry component?

Cheers

-- 
Sincerely
*Boris Horvat*

Re: How to pass a javascript function in tapestry mixin

Posted by Boris Horvat <ho...@gmail.com>.
well that javascript wont work...I will have to find the right properties
to trigger it :)


On Sun, Feb 16, 2014 at 7:36 PM, Boris Horvat <ho...@gmail.com>wrote:

> As mentioned the code actually do what it was suppose to do, it is just
> that it breaks ajax (some browser security concerns as it is sent from the
> server, not too sure about specifics)
>
> I would expected that either tapestry has a good way to solve this issue
> or at least a nice workaround...
>
> I will try to add javascript as you have suggested but the tricky part
> would be to make it correct for each id, I guess mixin?
>
>
> On Sun, Feb 16, 2014 at 1:24 AM, Christian Riedel <cr.mlist@googlemail.com
> > wrote:
>
>> Hi Boris,
>>
>> passing the whole function code as JSONLiteral could work, I guess:
>>
>>         params.put("onSubmit", new JSONLiteral("function () {
>> showUploadProgress(); }"));
>>
>> But Thiago has a point. Passing more complex code around like this is not
>> a good idea.
>> Instead you can alter the fileuploader’s option object directly:
>>
>>         $('#uploader').data('fileuploader')._options.onSubmit =
>> showUploadProgress;
>>
>> Didn’t test this, though. And of course this code works just as long as
>> the fileuploader library isn’t replaced by a newer one.
>>
>> T5-jQuery’s AjaxUpload component should provide a better interface for
>> this.
>>
>> Best
>> Christian
>>
>>
>> Am 16.02.2014 um 00:49 schrieb Boris Horvat <ho...@gmail.com>:
>>
>> > Sadly that doesnt really help. Same error, same issue.
>> >
>> > I have changed the JSONLiberal call to
>> >
>> >        params.put("onSubmit", new JSONLiteral("showUploadProgress"));
>> >
>> > My javascript that is generated at the end looks like this
>> >
>> >  "uploadable" : [
>> >    {
>> >      "elementId" : "imageUpload",
>> >      "onSubmit" : showUploadProgress,
>> >      "maxConnections" : 3,
>> >      "action" : "/assets.assetdata.updateassetimage.imageupload:upload",
>> >      "sizeLimit" : 0,
>> >      "showMessagesDialog" : "uploadErrorMesages",
>> >      "multiple" : false,
>> >      "messages" : {
>> >        "cancelLabel" : "Cancel",
>> >        "failedLabel" : "Failed",
>> >        "uploadLabel" : "Upload Image(s)",
>> >        "typeError" : "{file} has an invalid extension. Only {extensions}
>> > are allowed.",
>> >        "sizeError" : "{file} is too large, maximum file size is
>> > {sizeLimit}.",
>> >        "onLeave" : "The files are being uploaded, if you leave now the
>> > upload will be canceled.",
>> >        "dropAreaLabel" : "Drag and drop images here.",
>> >        "minSizeError" : "{file} is too small, minimum file size is
>> > {minSizeLimit}.",
>> >        "emptyError" : "{file} is empty, please select files again
>> without
>> > it."
>> >      }
>> >    }
>> >
>> > That's something to avoid as much as possible.
>> >
>> >
>> > Any suggestion how to avoid this? I need to pass a function that I want
>> to
>> > call when a file is submitted, so how can I do that?
>> >
>> > Thanks for help
>> >
>> >
>> > On Sat, Feb 15, 2014 at 9:37 PM, Thiago H de Paula Figueiredo <
>> > thiagohp@gmail.com> wrote:
>> >
>> >> On Sat, 15 Feb 2014 16:25:27 -0200, Boris Horvat <
>> horvat.z.boris@gmail.com>
>> >> wrote:
>> >>
>> >> Hi everyone,
>> >>>
>> >>
>> >> Hi!
>> >>
>> >>
>> >> I have a tapestr5-jquery component that to which I need to pass a
>> >>> function in the configuration.
>> >>>
>> >>
>> >> That's something to avoid as much as possible.
>> >
>> >
>> > Any suggestion to
>> >
>> >>
>> >>
>> >> The component is
>> >>> http://tapestry5-jquery.com/components/docsajaxupload;jsessionid=
>> >>> 2CD857F51B90113A175C5B10EE09B138.57B580630AEA
>> >>>
>> >>> My code looks like this
>> >>>
>> >>> java
>> >>>
>> >>> public JSONObject getUploadParams() {
>> >>>        JSONObject params = new JSONObject();
>> >>>        params.put("onSubmit", new
>> >>> JSONLiteral(String.format("showUploadProgress()")));
>> >>>        return params;
>> >>>    }
>> >>>
>> >>
>> >> Your code has an useless String.format() call. In addition, it's
>> passing
>> >> the value resulting of calling showUploadProgress(), not passing the
>> >> function itself. It should have been new JSONLiteral("
>> >> showUploadProgress").
>> >>
>> >> --
>> >> Thiago H. de Paula Figueiredo
>> >> Tapestry, Java and Hibernate consultant and developer
>> >> http://machina.com.br
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> >> For additional commands, e-mail: users-help@tapestry.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > Sincerely
>> > *Boris Horvat*
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> Sincerely
> *Boris Horvat*
>



-- 
Sincerely
*Boris Horvat*

Re: How to pass a javascript function in tapestry mixin

Posted by Boris Horvat <ho...@gmail.com>.
As mentioned the code actually do what it was suppose to do, it is just
that it breaks ajax (some browser security concerns as it is sent from the
server, not too sure about specifics)

I would expected that either tapestry has a good way to solve this issue or
at least a nice workaround...

I will try to add javascript as you have suggested but the tricky part
would be to make it correct for each id, I guess mixin?


On Sun, Feb 16, 2014 at 1:24 AM, Christian Riedel
<cr...@googlemail.com>wrote:

> Hi Boris,
>
> passing the whole function code as JSONLiteral could work, I guess:
>
>         params.put("onSubmit", new JSONLiteral("function () {
> showUploadProgress(); }"));
>
> But Thiago has a point. Passing more complex code around like this is not
> a good idea.
> Instead you can alter the fileuploader’s option object directly:
>
>         $('#uploader').data('fileuploader')._options.onSubmit =
> showUploadProgress;
>
> Didn’t test this, though. And of course this code works just as long as
> the fileuploader library isn’t replaced by a newer one.
>
> T5-jQuery’s AjaxUpload component should provide a better interface for
> this.
>
> Best
> Christian
>
>
> Am 16.02.2014 um 00:49 schrieb Boris Horvat <ho...@gmail.com>:
>
> > Sadly that doesnt really help. Same error, same issue.
> >
> > I have changed the JSONLiberal call to
> >
> >        params.put("onSubmit", new JSONLiteral("showUploadProgress"));
> >
> > My javascript that is generated at the end looks like this
> >
> >  "uploadable" : [
> >    {
> >      "elementId" : "imageUpload",
> >      "onSubmit" : showUploadProgress,
> >      "maxConnections" : 3,
> >      "action" : "/assets.assetdata.updateassetimage.imageupload:upload",
> >      "sizeLimit" : 0,
> >      "showMessagesDialog" : "uploadErrorMesages",
> >      "multiple" : false,
> >      "messages" : {
> >        "cancelLabel" : "Cancel",
> >        "failedLabel" : "Failed",
> >        "uploadLabel" : "Upload Image(s)",
> >        "typeError" : "{file} has an invalid extension. Only {extensions}
> > are allowed.",
> >        "sizeError" : "{file} is too large, maximum file size is
> > {sizeLimit}.",
> >        "onLeave" : "The files are being uploaded, if you leave now the
> > upload will be canceled.",
> >        "dropAreaLabel" : "Drag and drop images here.",
> >        "minSizeError" : "{file} is too small, minimum file size is
> > {minSizeLimit}.",
> >        "emptyError" : "{file} is empty, please select files again without
> > it."
> >      }
> >    }
> >
> > That's something to avoid as much as possible.
> >
> >
> > Any suggestion how to avoid this? I need to pass a function that I want
> to
> > call when a file is submitted, so how can I do that?
> >
> > Thanks for help
> >
> >
> > On Sat, Feb 15, 2014 at 9:37 PM, Thiago H de Paula Figueiredo <
> > thiagohp@gmail.com> wrote:
> >
> >> On Sat, 15 Feb 2014 16:25:27 -0200, Boris Horvat <
> horvat.z.boris@gmail.com>
> >> wrote:
> >>
> >> Hi everyone,
> >>>
> >>
> >> Hi!
> >>
> >>
> >> I have a tapestr5-jquery component that to which I need to pass a
> >>> function in the configuration.
> >>>
> >>
> >> That's something to avoid as much as possible.
> >
> >
> > Any suggestion to
> >
> >>
> >>
> >> The component is
> >>> http://tapestry5-jquery.com/components/docsajaxupload;jsessionid=
> >>> 2CD857F51B90113A175C5B10EE09B138.57B580630AEA
> >>>
> >>> My code looks like this
> >>>
> >>> java
> >>>
> >>> public JSONObject getUploadParams() {
> >>>        JSONObject params = new JSONObject();
> >>>        params.put("onSubmit", new
> >>> JSONLiteral(String.format("showUploadProgress()")));
> >>>        return params;
> >>>    }
> >>>
> >>
> >> Your code has an useless String.format() call. In addition, it's passing
> >> the value resulting of calling showUploadProgress(), not passing the
> >> function itself. It should have been new JSONLiteral("
> >> showUploadProgress").
> >>
> >> --
> >> Thiago H. de Paula Figueiredo
> >> Tapestry, Java and Hibernate consultant and developer
> >> http://machina.com.br
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
> > --
> > Sincerely
> > *Boris Horvat*
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Sincerely
*Boris Horvat*

Re: How to pass a javascript function in tapestry mixin

Posted by Christian Riedel <cr...@googlemail.com>.
Hi Boris,

passing the whole function code as JSONLiteral could work, I guess:

	params.put("onSubmit", new JSONLiteral("function () { showUploadProgress(); }"));

But Thiago has a point. Passing more complex code around like this is not a good idea.
Instead you can alter the fileuploader’s option object directly:

	$('#uploader').data('fileuploader')._options.onSubmit = showUploadProgress;

Didn’t test this, though. And of course this code works just as long as the fileuploader library isn’t replaced by a newer one.

T5-jQuery’s AjaxUpload component should provide a better interface for this.

Best
Christian


Am 16.02.2014 um 00:49 schrieb Boris Horvat <ho...@gmail.com>:

> Sadly that doesnt really help. Same error, same issue.
> 
> I have changed the JSONLiberal call to
> 
>        params.put("onSubmit", new JSONLiteral("showUploadProgress"));
> 
> My javascript that is generated at the end looks like this
> 
>  "uploadable" : [
>    {
>      "elementId" : "imageUpload",
>      "onSubmit" : showUploadProgress,
>      "maxConnections" : 3,
>      "action" : "/assets.assetdata.updateassetimage.imageupload:upload",
>      "sizeLimit" : 0,
>      "showMessagesDialog" : "uploadErrorMesages",
>      "multiple" : false,
>      "messages" : {
>        "cancelLabel" : "Cancel",
>        "failedLabel" : "Failed",
>        "uploadLabel" : "Upload Image(s)",
>        "typeError" : "{file} has an invalid extension. Only {extensions}
> are allowed.",
>        "sizeError" : "{file} is too large, maximum file size is
> {sizeLimit}.",
>        "onLeave" : "The files are being uploaded, if you leave now the
> upload will be canceled.",
>        "dropAreaLabel" : "Drag and drop images here.",
>        "minSizeError" : "{file} is too small, minimum file size is
> {minSizeLimit}.",
>        "emptyError" : "{file} is empty, please select files again without
> it."
>      }
>    }
> 
> That's something to avoid as much as possible.
> 
> 
> Any suggestion how to avoid this? I need to pass a function that I want to
> call when a file is submitted, so how can I do that?
> 
> Thanks for help
> 
> 
> On Sat, Feb 15, 2014 at 9:37 PM, Thiago H de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
> 
>> On Sat, 15 Feb 2014 16:25:27 -0200, Boris Horvat <ho...@gmail.com>
>> wrote:
>> 
>> Hi everyone,
>>> 
>> 
>> Hi!
>> 
>> 
>> I have a tapestr5-jquery component that to which I need to pass a
>>> function in the configuration.
>>> 
>> 
>> That's something to avoid as much as possible.
> 
> 
> Any suggestion to
> 
>> 
>> 
>> The component is
>>> http://tapestry5-jquery.com/components/docsajaxupload;jsessionid=
>>> 2CD857F51B90113A175C5B10EE09B138.57B580630AEA
>>> 
>>> My code looks like this
>>> 
>>> java
>>> 
>>> public JSONObject getUploadParams() {
>>>        JSONObject params = new JSONObject();
>>>        params.put("onSubmit", new
>>> JSONLiteral(String.format("showUploadProgress()")));
>>>        return params;
>>>    }
>>> 
>> 
>> Your code has an useless String.format() call. In addition, it's passing
>> the value resulting of calling showUploadProgress(), not passing the
>> function itself. It should have been new JSONLiteral("
>> showUploadProgress").
>> 
>> --
>> Thiago H. de Paula Figueiredo
>> Tapestry, Java and Hibernate consultant and developer
>> http://machina.com.br
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
> 
> 
> -- 
> Sincerely
> *Boris Horvat*


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to pass a javascript function in tapestry mixin

Posted by Dmitry Gusev <dm...@gmail.com>.
https://github.com/got5/tapestry5-jquery/issues/244#issuecomment-36102130


On Wed, Feb 26, 2014 at 3:50 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Tue, 25 Feb 2014 21:30:39 -0300, Boris Horvat <ho...@gmail.com>
> wrote:
>
>  Sorry Thaigo, but I am not sure what you had in mind.
>>
>> If you think about
>>
>> That's something to avoid as much as possible.
>>
>
> What are you talking about?
>
>
>  Well first I am not sure why is this the case. If tapestry supports
>> passing configurations in this way then it should support passing
>> functions when those configurations are expecting them. However I would be
>> open to
>> avoid doing this but I dont see a way to do it, other then overwriting
>> javascript files and putting my code directly there.
>>
>> I was able to identify the scenario that leads to this problem. The
>> ajaxUpload component needs to be surrounded by the zone, if that is not
>> the
>> case then a function can be passed without any issues.
>> Sadly in my code the zone is necessary.
>>
>> I will try to reach to the tapestry5-jquery developer to see if he thinks
>> this is a bug and can it be fixed.
>>
>> Thanks for the help and please if you have any idea how to avoid passing
>> the function (that doesn't involve overwriting existing files) I will be
>> happy to try it out.
>>
>> Cheers
>>
>>
>> On Tue, Feb 25, 2014 at 3:10 AM, Thiago H de Paula Figueiredo <
>> thiagohp@gmail.com> wrote:
>>
>>  On Mon, 24 Feb 2014 19:53:59 -0300, Boris Horvat <
>>> horvat.z.boris@gmail.com>
>>> wrote:
>>>
>>>  Anyone has any idea about this? :)
>>>
>>>>
>>>>
>>> I already gave you my suggestion.
>>>
>>>
>>> --
>>> Thiago H. de Paula Figueiredo
>>> Tapestry, Java and Hibernate consultant and developer
>>> http://machina.com.br
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>>
>>
>>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com

Re: How to pass a javascript function in tapestry mixin

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 25 Feb 2014 21:30:39 -0300, Boris Horvat  
<ho...@gmail.com> wrote:

> Sorry Thaigo, but I am not sure what you had in mind.
>
> If you think about
>
> That's something to avoid as much as possible.

What are you talking about?

> Well first I am not sure why is this the case. If tapestry supports
> passing configurations in this way then it should support passing  
> functions when those configurations are expecting them. However I would  
> be open to
> avoid doing this but I dont see a way to do it, other then overwriting
> javascript files and putting my code directly there.
>
> I was able to identify the scenario that leads to this problem. The
> ajaxUpload component needs to be surrounded by the zone, if that is not  
> the
> case then a function can be passed without any issues.
> Sadly in my code the zone is necessary.
>
> I will try to reach to the tapestry5-jquery developer to see if he thinks
> this is a bug and can it be fixed.
>
> Thanks for the help and please if you have any idea how to avoid passing
> the function (that doesn't involve overwriting existing files) I will be
> happy to try it out.
>
> Cheers
>
>
> On Tue, Feb 25, 2014 at 3:10 AM, Thiago H de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
>> On Mon, 24 Feb 2014 19:53:59 -0300, Boris Horvat  
>> <ho...@gmail.com>
>> wrote:
>>
>>  Anyone has any idea about this? :)
>>>
>>
>> I already gave you my suggestion.
>>
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Tapestry, Java and Hibernate consultant and developer
>> http://machina.com.br
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>


-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to pass a javascript function in tapestry mixin

Posted by Boris Horvat <ho...@gmail.com>.
On Wed, Feb 26, 2014 at 1:02 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Tue, 25 Feb 2014 21:30:39 -0300, Boris Horvat <ho...@gmail.com>
> wrote:
>
>  Sorry Thaigo, but I am not sure what you had in mind.
>> If you think about
>> That's something to avoid as much as possible.
>>
>
> I wasn't clear. I meant to say you should avoid passing a whole function
> definition. Just passing a function value (in JavaScript, functions are
> objects as any other) is something trivial. Just declare the function in
> some .js file included by your component, mixin or page and pass its
> reference (its name) to the parameter.



Ok, now this (with comments and code samples from Dmitry makes much more
sens to me


>
>
>  Well first I am not sure why is this the case. If tapestry supports
>> passing configurations in this way then it should support passing
>> functions when those configurations are expecting them.
>>
>
> Tapestry already does. That's JSONLiteral. In your case,
> params.put("onSubmit", new JSONLiteral("showUploadProgress"));. Notice
> there's no parenthesis, so you're passing the function itself, not the
> result of calling it.
>
>
For me the code wasn't working without parentheses but that was due to
missing few this as Dmitry pointed out


>
>  I was able to identify the scenario that leads to this problem. The
>> ajaxUpload component needs to be surrounded by the zone, if that is not
>> the case then a function can be passed without any issues.
>> Sadly in my code the zone is necessary.
>>
>
> So you're blaming Tapestry when the culprit isn't actually Tapestry, but a
> third-party component which expects a Zone event handler return and you may
> be trying to use it in a way it wasn't supposed. The error you posted
> earlier in this thread means something wrong went on the server side.


I would say blaming is such a strong word to be used here. I really never
meant to pass the blame to anyone (or anything for that matter) as I was
merely searching for help to resolve my issue. Also I wouldn't say that it
is nice to pass the *blame *to the third party component as I have
experienced the same issue (long time ago) with autocomplete (solution then
was a bit different then, but probably not that different for someone with
better understanding).

If anyone is to take the blame it is probably me and my lack of true
understanding of how things are working in Tapestry.

Anyway I appreciated the help you provided here.

Dmitry thank you very much on the code sample of the initialization that I
was missing for the ajax request. I have created a mixin that is now able
to inject code properly so I dont have to do manual insertion every time :)

Thanks everyone again,

Cheers



>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Sincerely
*Boris Horvat*

Re: How to pass a javascript function in tapestry mixin

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 25 Feb 2014 21:30:39 -0300, Boris Horvat  
<ho...@gmail.com> wrote:

> Sorry Thaigo, but I am not sure what you had in mind.
> If you think about
> That's something to avoid as much as possible.

I wasn't clear. I meant to say you should avoid passing a whole function  
definition. Just passing a function value (in JavaScript, functions are  
objects as any other) is something trivial. Just declare the function in  
some .js file included by your component, mixin or page and pass its  
reference (its name) to the parameter.

> Well first I am not sure why is this the case. If tapestry supports
> passing configurations in this way then it should support passing  
> functions when those configurations are expecting them.

Tapestry already does. That's JSONLiteral. In your case,  
params.put("onSubmit", new JSONLiteral("showUploadProgress"));. Notice  
there's no parenthesis, so you're passing the function itself, not the  
result of calling it.

> I was able to identify the scenario that leads to this problem. The
> ajaxUpload component needs to be surrounded by the zone, if that is not  
> the case then a function can be passed without any issues.
> Sadly in my code the zone is necessary.

So you're blaming Tapestry when the culprit isn't actually Tapestry, but a  
third-party component which expects a Zone event handler return and you  
may be trying to use it in a way it wasn't supposed. The error you posted  
earlier in this thread means something wrong went on the server side.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to pass a javascript function in tapestry mixin

Posted by Boris Horvat <ho...@gmail.com>.
Sorry Thaigo, but I am not sure what you had in mind.

If you think about

That's something to avoid as much as possible.


Well first I am not sure why is this the case. If tapestry supports
passing configurations in this way then it should support passing functions
when those configurations are expecting them. However I would be open to
avoid doing this but I dont see a way to do it, other then overwriting
javascript files and putting my code directly there.

I was able to identify the scenario that leads to this problem. The
ajaxUpload component needs to be surrounded by the zone, if that is not the
case then a function can be passed without any issues.
Sadly in my code the zone is necessary.

I will try to reach to the tapestry5-jquery developer to see if he thinks
this is a bug and can it be fixed.

Thanks for the help and please if you have any idea how to avoid passing
the function (that doesn't involve overwriting existing files) I will be
happy to try it out.

Cheers


On Tue, Feb 25, 2014 at 3:10 AM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Mon, 24 Feb 2014 19:53:59 -0300, Boris Horvat <ho...@gmail.com>
> wrote:
>
>  Anyone has any idea about this? :)
>>
>
> I already gave you my suggestion.
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Sincerely
*Boris Horvat*

Re: How to pass a javascript function in tapestry mixin

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 24 Feb 2014 19:53:59 -0300, Boris Horvat  
<ho...@gmail.com> wrote:

> Anyone has any idea about this? :)

I already gave you my suggestion.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to pass a javascript function in tapestry mixin

Posted by Boris Horvat <ho...@gmail.com>.
Anyone has any idea about this? :)


On Sat, Feb 22, 2014 at 10:07 PM, Boris Horvat <ho...@gmail.com>wrote:

> In case it helps the method is defined like this
>
> function showUploadProgress() {
>     var showUploadProgress = function(id, fileName) {
>         alert(123)
>         $('.photo').removeClass('photo').addClass('photo-progress-reveal');
>     }
>     return showUploadProgress;
> }
>
>
> Cheers
>
>
> On Sat, Feb 22, 2014 at 10:02 PM, Boris Horvat <ho...@gmail.com>wrote:
>
>> Sadly I did posted it
>>
>> Communication with the server failed: null
>> Ajax failure: Status 200 for #{request.url}: null
>> Communication with the server failed: null
>>
>> Not much more info then this. In the console I can see
>>
>>
>>    1. Communication with the server failed: null t5-console-jquery.js:64<http://localhost:8080/assets/e55b8baca63242ca/jquery/t5-console-jquery.js>
>>       1. errort5-console-jquery.js:64<http://localhost:8080/assets/e55b8baca63242ca/jquery/t5-console-jquery.js>
>>       2. $.extend.invokeLoggertapestry-jquery.js:160<http://localhost:8080/assets/e55b8baca63242ca/jquery/tapestry-jquery.js>
>>       3. $.extend.errortapestry-jquery.js:120<http://localhost:8080/assets/e55b8baca63242ca/jquery/tapestry-jquery.js>
>>       4. $.tapestry.utils.ajaxFailureHandlertapestry-jquery.js:1138<http://localhost:8080/assets/e55b8baca63242ca/jquery/tapestry-jquery.js>
>>       5. firejquery-1.7.2.js:1075<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>
>>       6. self.fireWithjquery-1.7.2.js:1193<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>
>>       7. donejquery-1.7.2.js:7550<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>
>>       8. callbackjquery-1.7.2.js:8334<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>
>>
>> Ajax failure: Status 200 for #{request.url}: null
>>
>>
>> Yea showUploadProgress() is defined in the main.js which is include.
>> Also I can see the effect of that code so I know it works, however it
>> breaks ajax requests.
>>
>> When I pass the parameter such as
>>
>>         params.put("onSubmit", new JSONLiteral("showUploadProgress()"));
>>
>> in the page I can see
>>
>> "uploadable" : [ { "elementId" : "imageUpload", "onSubmit" :
>> showUploadProgress(), "maxConnections" : 3, "action" :
>> "/assets.assetdata.updateassetimage.imageupload:upload", "sizeLimit" : 0,
>> "showMessagesDialog" : "uploadErrorMesages", "multiple" : false, "messages"
>> : { "cancelLabel" : "Cancel", "failedLabel" : "Failed", "uploadLabel" :
>> "Upload Image(s)", "typeError" : "{file} has an invalid extension. Only
>> {extensions} are allowed.", "sizeError" : "{file} is too large, maximum
>> file size is {sizeLimit}.", "onLeave" : "The files are being uploaded, if
>> you leave now the upload will be canceled.", "dropAreaLabel" : "Drag and
>> drop images here.", "minSizeError" : "{file} is too small, minimum file
>> size is {minSizeLimit}.", "emptyError" : "{file} is empty, please select
>> files again without it." } },
>>
>> and then I can see the effects of the method (without parentheses the
>> code doesn't work but the error is still present).
>>
>> Is there any other way to pass this method to the component?
>>
>>
>>  On Mon, Feb 17, 2014 at 1:26 PM, Thiago H de Paula Figueiredo <
>> thiagohp@gmail.com> wrote:
>>
>>> On Sat, 15 Feb 2014 21:49:11 -0200, Boris Horvat <
>>> horvat.z.boris@gmail.com> wrote:
>>>
>>>  Sadly that doesnt really help. Same error, same issue.
>>>>
>>>
>>> What's the JavaScript error? I don't recall you posting it.
>>>
>>>
>>>  That's something to avoid as much as possible.
>>>>
>>>
>>> What exactly do you want to avoid and why?
>>>
>>>
>>>  Any suggestion how to avoid this? I need to pass a function that I want
>>>> to call when a file is submitted, so how can I do that?
>>>>
>>>
>>> Does the showUploadProgress() function exists in some JavaScript file
>>> you include in the page or component? If you're going to use new
>>> JSONLiteral("showUploadProgress"), you need that.
>>>
>>>
>>> --
>>> Thiago H. de Paula Figueiredo
>>> Tapestry, Java and Hibernate consultant and developer
>>> http://machina.com.br
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>>
>> --
>> Sincerely
>> *Boris Horvat*
>>
>
>
>
> --
> Sincerely
> *Boris Horvat*
>



-- 
Sincerely
*Boris Horvat*

Re: How to pass a javascript function in tapestry mixin

Posted by Boris Horvat <ho...@gmail.com>.
In case it helps the method is defined like this

function showUploadProgress() {
    var showUploadProgress = function(id, fileName) {
        alert(123)
        $('.photo').removeClass('photo').addClass('photo-progress-reveal');
    }
    return showUploadProgress;
}


Cheers

On Sat, Feb 22, 2014 at 10:02 PM, Boris Horvat <ho...@gmail.com>wrote:

> Sadly I did posted it
>
> Communication with the server failed: null
> Ajax failure: Status 200 for #{request.url}: null
> Communication with the server failed: null
>
> Not much more info then this. In the console I can see
>
>
>    1. Communication with the server failed: null t5-console-jquery.js:64<http://localhost:8080/assets/e55b8baca63242ca/jquery/t5-console-jquery.js>
>       1. errort5-console-jquery.js:64<http://localhost:8080/assets/e55b8baca63242ca/jquery/t5-console-jquery.js>
>       2. $.extend.invokeLoggertapestry-jquery.js:160<http://localhost:8080/assets/e55b8baca63242ca/jquery/tapestry-jquery.js>
>       3. $.extend.errortapestry-jquery.js:120<http://localhost:8080/assets/e55b8baca63242ca/jquery/tapestry-jquery.js>
>       4. $.tapestry.utils.ajaxFailureHandlertapestry-jquery.js:1138<http://localhost:8080/assets/e55b8baca63242ca/jquery/tapestry-jquery.js>
>       5. firejquery-1.7.2.js:1075<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>
>       6. self.fireWithjquery-1.7.2.js:1193<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>
>       7. donejquery-1.7.2.js:7550<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>
>       8. callbackjquery-1.7.2.js:8334<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>
>
> Ajax failure: Status 200 for #{request.url}: null
>
>
> Yea showUploadProgress() is defined in the main.js which is include. Also
> I can see the effect of that code so I know it works, however it breaks
> ajax requests.
>
> When I pass the parameter such as
>
>         params.put("onSubmit", new JSONLiteral("showUploadProgress()"));
>
> in the page I can see
>
> "uploadable" : [ { "elementId" : "imageUpload", "onSubmit" :
> showUploadProgress(), "maxConnections" : 3, "action" :
> "/assets.assetdata.updateassetimage.imageupload:upload", "sizeLimit" : 0,
> "showMessagesDialog" : "uploadErrorMesages", "multiple" : false, "messages"
> : { "cancelLabel" : "Cancel", "failedLabel" : "Failed", "uploadLabel" :
> "Upload Image(s)", "typeError" : "{file} has an invalid extension. Only
> {extensions} are allowed.", "sizeError" : "{file} is too large, maximum
> file size is {sizeLimit}.", "onLeave" : "The files are being uploaded, if
> you leave now the upload will be canceled.", "dropAreaLabel" : "Drag and
> drop images here.", "minSizeError" : "{file} is too small, minimum file
> size is {minSizeLimit}.", "emptyError" : "{file} is empty, please select
> files again without it." } },
>
> and then I can see the effects of the method (without parentheses the
> code doesn't work but the error is still present).
>
> Is there any other way to pass this method to the component?
>
>
>  On Mon, Feb 17, 2014 at 1:26 PM, Thiago H de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
>> On Sat, 15 Feb 2014 21:49:11 -0200, Boris Horvat <
>> horvat.z.boris@gmail.com> wrote:
>>
>>  Sadly that doesnt really help. Same error, same issue.
>>>
>>
>> What's the JavaScript error? I don't recall you posting it.
>>
>>
>>  That's something to avoid as much as possible.
>>>
>>
>> What exactly do you want to avoid and why?
>>
>>
>>  Any suggestion how to avoid this? I need to pass a function that I want
>>> to call when a file is submitted, so how can I do that?
>>>
>>
>> Does the showUploadProgress() function exists in some JavaScript file you
>> include in the page or component? If you're going to use new JSONLiteral("showUploadProgress"),
>> you need that.
>>
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Tapestry, Java and Hibernate consultant and developer
>> http://machina.com.br
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> Sincerely
> *Boris Horvat*
>



-- 
Sincerely
*Boris Horvat*

Re: How to pass a javascript function in tapestry mixin

Posted by Boris Horvat <ho...@gmail.com>.
Sadly I did posted it

Communication with the server failed: null
Ajax failure: Status 200 for #{request.url}: null
Communication with the server failed: null

Not much more info then this. In the console I can see


   1. Communication with the server failed: null
t5-console-jquery.js:64<http://localhost:8080/assets/e55b8baca63242ca/jquery/t5-console-jquery.js>
      1. errort5-console-jquery.js:64<http://localhost:8080/assets/e55b8baca63242ca/jquery/t5-console-jquery.js>
      2. $.extend.invokeLoggertapestry-jquery.js:160<http://localhost:8080/assets/e55b8baca63242ca/jquery/tapestry-jquery.js>
      3. $.extend.errortapestry-jquery.js:120<http://localhost:8080/assets/e55b8baca63242ca/jquery/tapestry-jquery.js>
      4. $.tapestry.utils.ajaxFailureHandlertapestry-jquery.js:1138<http://localhost:8080/assets/e55b8baca63242ca/jquery/tapestry-jquery.js>
      5. firejquery-1.7.2.js:1075<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>
      6. self.fireWithjquery-1.7.2.js:1193<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>
      7. donejquery-1.7.2.js:7550<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>
      8. callbackjquery-1.7.2.js:8334<http://localhost:8080/assets/e55b8baca63242ca/jquery/jquery_core/jquery-1.7.2.js>

Ajax failure: Status 200 for #{request.url}: null


Yea showUploadProgress() is defined in the main.js which is include. Also I
can see the effect of that code so I know it works, however it breaks ajax
requests.

When I pass the parameter such as

        params.put("onSubmit", new JSONLiteral("showUploadProgress()"));

in the page I can see

"uploadable" : [ { "elementId" : "imageUpload", "onSubmit" :
showUploadProgress(), "maxConnections" : 3, "action" :
"/assets.assetdata.updateassetimage.imageupload:upload", "sizeLimit" : 0,
"showMessagesDialog" : "uploadErrorMesages", "multiple" : false, "messages"
: { "cancelLabel" : "Cancel", "failedLabel" : "Failed", "uploadLabel" :
"Upload Image(s)", "typeError" : "{file} has an invalid extension. Only
{extensions} are allowed.", "sizeError" : "{file} is too large, maximum
file size is {sizeLimit}.", "onLeave" : "The files are being uploaded, if
you leave now the upload will be canceled.", "dropAreaLabel" : "Drag and
drop images here.", "minSizeError" : "{file} is too small, minimum file
size is {minSizeLimit}.", "emptyError" : "{file} is empty, please select
files again without it." } },

and then I can see the effects of the method (without parentheses the
code doesn't work but the error is still present).

Is there any other way to pass this method to the component?


On Mon, Feb 17, 2014 at 1:26 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Sat, 15 Feb 2014 21:49:11 -0200, Boris Horvat <ho...@gmail.com>
> wrote:
>
>  Sadly that doesnt really help. Same error, same issue.
>>
>
> What's the JavaScript error? I don't recall you posting it.
>
>
>  That's something to avoid as much as possible.
>>
>
> What exactly do you want to avoid and why?
>
>
>  Any suggestion how to avoid this? I need to pass a function that I want
>> to call when a file is submitted, so how can I do that?
>>
>
> Does the showUploadProgress() function exists in some JavaScript file you
> include in the page or component? If you're going to use new JSONLiteral("showUploadProgress"),
> you need that.
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Sincerely
*Boris Horvat*

Re: How to pass a javascript function in tapestry mixin

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sat, 15 Feb 2014 21:49:11 -0200, Boris Horvat  
<ho...@gmail.com> wrote:

> Sadly that doesnt really help. Same error, same issue.

What's the JavaScript error? I don't recall you posting it.

> That's something to avoid as much as possible.

What exactly do you want to avoid and why?

> Any suggestion how to avoid this? I need to pass a function that I want  
> to call when a file is submitted, so how can I do that?

Does the showUploadProgress() function exists in some JavaScript file you  
include in the page or component? If you're going to use new  
JSONLiteral("showUploadProgress"), you need that.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to pass a javascript function in tapestry mixin

Posted by Boris Horvat <ho...@gmail.com>.
Sadly that doesnt really help. Same error, same issue.

I have changed the JSONLiberal call to

        params.put("onSubmit", new JSONLiteral("showUploadProgress"));

My javascript that is generated at the end looks like this

  "uploadable" : [
    {
      "elementId" : "imageUpload",
      "onSubmit" : showUploadProgress,
      "maxConnections" : 3,
      "action" : "/assets.assetdata.updateassetimage.imageupload:upload",
      "sizeLimit" : 0,
      "showMessagesDialog" : "uploadErrorMesages",
      "multiple" : false,
      "messages" : {
        "cancelLabel" : "Cancel",
        "failedLabel" : "Failed",
        "uploadLabel" : "Upload Image(s)",
        "typeError" : "{file} has an invalid extension. Only {extensions}
are allowed.",
        "sizeError" : "{file} is too large, maximum file size is
{sizeLimit}.",
        "onLeave" : "The files are being uploaded, if you leave now the
upload will be canceled.",
        "dropAreaLabel" : "Drag and drop images here.",
        "minSizeError" : "{file} is too small, minimum file size is
{minSizeLimit}.",
        "emptyError" : "{file} is empty, please select files again without
it."
      }
    }

That's something to avoid as much as possible.


Any suggestion how to avoid this? I need to pass a function that I want to
call when a file is submitted, so how can I do that?

Thanks for help


On Sat, Feb 15, 2014 at 9:37 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Sat, 15 Feb 2014 16:25:27 -0200, Boris Horvat <ho...@gmail.com>
> wrote:
>
>  Hi everyone,
>>
>
> Hi!
>
>
>  I have a tapestr5-jquery component that to which I need to pass a
>> function in the configuration.
>>
>
> That's something to avoid as much as possible.


Any suggestion to

>
>
>  The component is
>> http://tapestry5-jquery.com/components/docsajaxupload;jsessionid=
>> 2CD857F51B90113A175C5B10EE09B138.57B580630AEA
>>
>> My code looks like this
>>
>> java
>>
>> public JSONObject getUploadParams() {
>>         JSONObject params = new JSONObject();
>>         params.put("onSubmit", new
>> JSONLiteral(String.format("showUploadProgress()")));
>>         return params;
>>     }
>>
>
> Your code has an useless String.format() call. In addition, it's passing
> the value resulting of calling showUploadProgress(), not passing the
> function itself. It should have been new JSONLiteral("
> showUploadProgress").
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Sincerely
*Boris Horvat*

Re: How to pass a javascript function in tapestry mixin

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sat, 15 Feb 2014 16:25:27 -0200, Boris Horvat  
<ho...@gmail.com> wrote:

> Hi everyone,

Hi!

> I have a tapestr5-jquery component that to which I need to pass a  
> function in the configuration.

That's something to avoid as much as possible.

> The component is
> http://tapestry5-jquery.com/components/docsajaxupload;jsessionid=2CD857F51B90113A175C5B10EE09B138.57B580630AEA
>
> My code looks like this
>
> java
>
> public JSONObject getUploadParams() {
>         JSONObject params = new JSONObject();
>         params.put("onSubmit", new
> JSONLiteral(String.format("showUploadProgress()")));
>         return params;
>     }

Your code has an useless String.format() call. In addition, it's passing  
the value resulting of calling showUploadProgress(), not passing the  
function itself. It should have been new JSONLiteral("showUploadProgress").

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org