Re: Correct way to JS in tapestry 5.4

2014-06-16 Thread Geoff Callender
Are you sure openLayers isn't available in registerAddressChangeListener? I 
don't think you need to use require in there.

Aside from that, I would lean toward a different structure:

- A component, say MyMap, which you put wherever you want the map to be. It 
would have a corresponding js, say my-map.js, with a showMap method which is 
invoked by MyMap, and a showAddress method which can be called by other modules.

- A mixin, say ShowOnMyMap, which you use in address fields. It would have a 
corresponding js, say show-on-my-map.js, which depends on my-map module. On 
change of the address field it would call my-map's showAddress function with 
the address as a parameter.

This way you can have more than one address field linked to the map.

If you need to use the MyMap component more than once on the same page then 
there's more to do, but that's a different problem that I won't cover here.

If there's only one module in the js source file (recommended) then there's no 
need to name your module in the source, so in a file called openstreetmaps.js 
then this is sufficient:

define([ 'open-layers', 'jquery', 't5/core/console' ], function(openLayers, $, 
console) {
// etc
}

I've found that a good structure within each module is to follow the js 
structure that comes out of coffeescript, eg. for my-map.js:

define([ 'open-layers', 'jquery', 't5/core/console' ], function(openLayers, $, 
console) {

var init = function(clientId) {
// This would probably do what "showMap" does in your example.
}

var showAddress = function(address) {
// etc
}

var otherFunction = function(params) {
}

return {
init : init,
showAddress : showAddress
};

});

The thing I like about this pattern is that it leaves you in no doubt about 
what's "public" and what's not.

I'm no JavaScript or RequireJS guru, so I'd also like to hear the opinions of 
others.

Geoff

On 17 Jun 2014, at 9:01 am, Sanket Sharma  wrote:

> Thats odd. I've been noticing my emails to the list appear after a delay -
> not sure whats causing it. And now the code disappears! But thanks for your
> help.
> 
> Anyways, in the meantime I already started playing with modules and
> require.js and got it to work. I have a few questions though. I'm not a
> great javascript programmer but I find the AMD approach refreshing and very
> clean. So +1 for AMD in 5.4!
> 
> I struggled somewhat finding the right syntax to use between require.js,
> jquery and mixins! So, using my open street maps example, here is what I
> did (and I hope code goes through this time):
> 
> To monitor any changes to the textfield component, I defined a mixin:
> 
> 
> 
> In the implementation, class - invoked the module/javascript initialization:
> 
> javaScriptSupport.require("openstreetmaps").invoke("registerAddressChangeListener").with(clientElement.getClientId());
> 
> and in the openstreetmaps.js:
> 
> 
> define('openstreetmaps', [ 'open-layers', 'jquery', 't5/core/console' ],
> function(
> openLayers, $, console) {
> 
> return {
> 
> showMap : function(clientId) {
> var map = new openLayers.Map(clientId);
> map.addLayer(new openLayers.Layer.OSM());
> map.addLayer(new openLayers.Layer.Markers("Markers"));
> map.zoomToExtent();
> 
> },
> 
> registerAddressChangeListener : function(clientId) {
> $('#addressLineTwo').on('input propertychange paste',function() {
> require([ 'open-layers' ], function(openLayers) {
> console.debug(openLayers);
> })});
> }
> 
> };
> 
> });
> 
> My question/concern is around the code I wrote in
> registerAddressChangeListener. To update the map, I have to use the
> open-layers module. Now, as far as my understanding goes, there is no
> clean/easy way to store a 'reference' to that module locally the openLayers
> module (please correct me here!). So the only way is to define a function,
> which in turn defines in a function in the format:
> 
> require(['dependencies'], function(dependencies) {..}
> 
> 
> The parameter from the define method is available in the return closure
> functions, but as this is an event handler that gets called randomly, the
> context changes and that variable is not available anymore? The tapestry
> JavaScriptSUpport class also seems to follow the same pattern...calling
> require('module name').invoke('parameters').
> 
> I guess this more of a Javascript question than a tapestry question - but
> spent last few hours searching for this and could not find anything. Would
> appreciate any help on this matter.
> 
> 
> Best Regards,
> Sanket
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> On Mon, Jun 16, 2014 at 4:05 PM, Thiago H de Paula Figueiredo <
> thiag...@gmail.com> wrote:
> 
>> On Sun, 15 Jun 2014 21:35:34 -0300, Sanket Sharma 
>> wrote:
>> 
>> Hi,
>>> 
>> 
>> Hi!
>> 
>> Now, in my application I have a open street map control that needs to be
>>> updated when a selection/text changes on the form. I w

Re: Correct way to JS in tapestry 5.4

2014-06-16 Thread Sanket Sharma
Thats odd. I've been noticing my emails to the list appear after a delay -
not sure whats causing it. And now the code disappears! But thanks for your
help.

Anyways, in the meantime I already started playing with modules and
require.js and got it to work. I have a few questions though. I'm not a
great javascript programmer but I find the AMD approach refreshing and very
clean. So +1 for AMD in 5.4!

I struggled somewhat finding the right syntax to use between require.js,
jquery and mixins! So, using my open street maps example, here is what I
did (and I hope code goes through this time):

To monitor any changes to the textfield component, I defined a mixin:



In the implementation, class - invoked the module/javascript initialization:

javaScriptSupport.require("openstreetmaps").invoke("registerAddressChangeListener").with(clientElement.getClientId());

and in the openstreetmaps.js:


define('openstreetmaps', [ 'open-layers', 'jquery', 't5/core/console' ],
function(
openLayers, $, console) {

return {

showMap : function(clientId) {
var map = new openLayers.Map(clientId);
map.addLayer(new openLayers.Layer.OSM());
map.addLayer(new openLayers.Layer.Markers("Markers"));
map.zoomToExtent();

},

registerAddressChangeListener : function(clientId) {
$('#addressLineTwo').on('input propertychange paste',function() {
require([ 'open-layers' ], function(openLayers) {
console.debug(openLayers);
})});
}

};

});

My question/concern is around the code I wrote in
registerAddressChangeListener. To update the map, I have to use the
open-layers module. Now, as far as my understanding goes, there is no
clean/easy way to store a 'reference' to that module locally the openLayers
module (please correct me here!). So the only way is to define a function,
which in turn defines in a function in the format:

require(['dependencies'], function(dependencies) {..}


The parameter from the define method is available in the return closure
functions, but as this is an event handler that gets called randomly, the
context changes and that variable is not available anymore? The tapestry
JavaScriptSUpport class also seems to follow the same pattern...calling
require('module name').invoke('parameters').

I guess this more of a Javascript question than a tapestry question - but
spent last few hours searching for this and could not find anything. Would
appreciate any help on this matter.


Best Regards,
Sanket

















On Mon, Jun 16, 2014 at 4:05 PM, Thiago H de Paula Figueiredo <
thiag...@gmail.com> wrote:

> On Sun, 15 Jun 2014 21:35:34 -0300, Sanket Sharma 
> wrote:
>
>  Hi,
>>
>
> Hi!
>
>  Now, in my application I have a open street map control that needs to be
>> updated when a selection/text changes on the form. I was wondering what
>> is the best way to do it in T5.4?
>> I can potentially create a Mixin as described in jumpstart:
>>
>
> The code you pasted in your e-mail didn't make it to the mailing list, so
> we cannot comment on it.
>
> Mixins are a very powerful and interesting tool. The scenario you describe
> seems a good match for a mixin.
>
>  Not sure if that is the best way? I can also inject script directly
>> using javaScriptSupport.addScript
>> or can create a module that gets loaded and initiated when the page
>> finishes loading..
>>
>
> JavaScriptSupport.addScript() is deprecated, so a module is the way to go
> in 5.4.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


Re: WebSocket for tapestry

2014-06-16 Thread Bogdan Ivascu
That did it. Sorry to keep hitting this nail but, I stumbled across another
one. As described above, the push targets will "prepend" a block on every
update. Inside this bock, I have eventLinks that are rendered correctly
after I put in the configuration. These eventLinks are supposed to be ajax.
The eventLink rendered with the last block correctly calls the page via
ajax, however all other eventLinks in blocks already displayed no longer
make ajax calls. It looks as if they get deregistered somehow from the
Tapestry "onClick" handler that makes ajax calls.

Thanks.


On Mon, Jun 16, 2014 at 3:40 AM, Lance Java 
wrote:

> See the "configuration" section here
> https://github.com/uklance/tapestry-offline
> On 16 Jun 2014 05:44, "Bogdan Ivascu"  wrote:
>
> > Makes sense, thanks for the reply.
> >
> > Another thing that is odd. I seem to have trouble while rendering
> > eventLinks inside a block that is a delagate of a pushTarget.
> >
> > in tml:
> > 
> > 
> > 
> >
> > 
> > a bunch of html markup
> > 
> >
> > in the java class
> > public Block getTokenPlayHistoryBlock(){
> >switch based on conditions
> >   retun blockXXX;
> > }
> >
> > Above works great until I try to add an eventLink in block:
> >
> > 
> >a bunch of html markup
> > THIS BREAKS IT
> > 
> >
> > Error:
> > 2014-Jun-16 00:29:09 ioc.internal.RecursiveServiceCreationCheckWrapper
> > org.apache.tapestry5.ioc.internal.OperationException: *Symbol
> > 'tapestry-offline.serverName' is not defined.*
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:121)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:88)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.services.MasterObjectProviderImpl.provide(MasterObjectProviderImpl.java:45)
> > at $MasterObjectProvider_23570e7547da.provide(Unknown Source)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.RegistryImpl.getObject(RegistryImpl.java:871)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.ObjectLocatorImpl.getObject(ObjectLocatorImpl.java:57)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.util.InternalUtils.calculateInjection(InternalUtils.java:257)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.util.InternalUtils.access$000(InternalUtils.java:50)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.util.InternalUtils$4.invoke(InternalUtils.java:289)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.util.InternalUtils$4.invoke(InternalUtils.java:286)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.util.InternalUtils.calculateParameters(InternalUtils.java:293)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.util.InternalUtils$23.invoke(InternalUtils.java:1488)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.util.InternalUtils$23.invoke(InternalUtils.java:1483)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.util.InternalUtils.createConstructorConstructionPlan(InternalUtils.java:1480)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.getPlan(ConstructorServiceCreator.java:52)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.createObject(ConstructorServiceCreator.java:61)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.SingletonServiceLifecycle.createService(SingletonServiceLifecycle.java:29)
> > at
> >
> >
> org.apache.tapestry5.ioc.internal.Lifec

Re: Correct way to JS in tapestry 5.4

2014-06-16 Thread Thiago H de Paula Figueiredo
On Sun, 15 Jun 2014 21:35:34 -0300, Sanket Sharma   
wrote:



Hi,


Hi!


Now, in my application I have a open street map control that needs to be
updated when a selection/text changes on the form. I was wondering what  
is the best way to do it in T5.4?

I can potentially create a Mixin as described in jumpstart:


The code you pasted in your e-mail didn't make it to the mailing list, so  
we cannot comment on it.


Mixins are a very powerful and interesting tool. The scenario you describe  
seems a good match for a mixin.



Not sure if that is the best way? I can also inject script directly
using javaScriptSupport.addScript
or can create a module that gets loaded and initiated when the page
finishes loading..


JavaScriptSupport.addScript() is deprecated, so a module is the way to go  
in 5.4.


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

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



Re: Multi file upload

2014-06-16 Thread Sanket Sharma
Thanks!
Will give it a shot today.

Thank you once again.

Sanket


On Sun, Jun 15, 2014 at 8:54 AM, Ilya Obshadko 
wrote:

> I have integrated jQuery-File-Upload in my project recently. This library
> is more flexible and up-to date.
> My integration scenario uses MultipartDecoder service override described in
> the blog post you are referring to.
>
> I have created a public gist, feel free to use and extend it:
> https://gist.github.com/xfyre/83f82f6e5145ee041217
> Currently it doesn't support multiple files upload, but it's very easy to
> add this functionality.
>
>
>
> On Sun, Jun 15, 2014 at 4:19 AM, Sanket Sharma 
> wrote:
>
> > Hi,
> >
> > I'm looking for a mechanism to allow users to upload multiple files in
> the
> > application. I know it is possible via AJAX but not sure if there is any
> > component that currently supports it.
> >
> > The only documentation I came across was this - which was written about
> > three years back
> > http://tawus.wordpress.com/2011/06/25/ajax-upload-for-tapestry/
> >
> > Not sure if it is still compatible and if it will work - will give it
> shot
> > tomorrow.
> >
> >
> > Thank you for your help.
> >
> >
> > Sanket
> >
>
>
>
> --
> Ilya Obshadko
>


Re: WebSocket for tapestry

2014-06-16 Thread Lance Java
See the "configuration" section here
https://github.com/uklance/tapestry-offline
On 16 Jun 2014 05:44, "Bogdan Ivascu"  wrote:

> Makes sense, thanks for the reply.
>
> Another thing that is odd. I seem to have trouble while rendering
> eventLinks inside a block that is a delagate of a pushTarget.
>
> in tml:
> 
> 
> 
>
> 
> a bunch of html markup
> 
>
> in the java class
> public Block getTokenPlayHistoryBlock(){
>switch based on conditions
>   retun blockXXX;
> }
>
> Above works great until I try to add an eventLink in block:
>
> 
>a bunch of html markup
> THIS BREAKS IT
> 
>
> Error:
> 2014-Jun-16 00:29:09 ioc.internal.RecursiveServiceCreationCheckWrapper
> org.apache.tapestry5.ioc.internal.OperationException: *Symbol
> 'tapestry-offline.serverName' is not defined.*
> at
>
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:121)
> at
>
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:88)
> at
>
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
> at
>
> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
> at
>
> org.apache.tapestry5.ioc.internal.services.MasterObjectProviderImpl.provide(MasterObjectProviderImpl.java:45)
> at $MasterObjectProvider_23570e7547da.provide(Unknown Source)
> at
>
> org.apache.tapestry5.ioc.internal.RegistryImpl.getObject(RegistryImpl.java:871)
> at
>
> org.apache.tapestry5.ioc.internal.ObjectLocatorImpl.getObject(ObjectLocatorImpl.java:57)
> at
>
> org.apache.tapestry5.ioc.internal.util.InternalUtils.calculateInjection(InternalUtils.java:257)
> at
>
> org.apache.tapestry5.ioc.internal.util.InternalUtils.access$000(InternalUtils.java:50)
> at
>
> org.apache.tapestry5.ioc.internal.util.InternalUtils$4.invoke(InternalUtils.java:289)
> at
>
> org.apache.tapestry5.ioc.internal.util.InternalUtils$4.invoke(InternalUtils.java:286)
> at
>
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
> at
>
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
> at
>
> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
> at
>
> org.apache.tapestry5.ioc.internal.util.InternalUtils.calculateParameters(InternalUtils.java:293)
> at
>
> org.apache.tapestry5.ioc.internal.util.InternalUtils$23.invoke(InternalUtils.java:1488)
> at
>
> org.apache.tapestry5.ioc.internal.util.InternalUtils$23.invoke(InternalUtils.java:1483)
> at
>
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
> at
>
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
> at
>
> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
> at
>
> org.apache.tapestry5.ioc.internal.util.InternalUtils.createConstructorConstructionPlan(InternalUtils.java:1480)
> at
>
> org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.getPlan(ConstructorServiceCreator.java:52)
> at
>
> org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.createObject(ConstructorServiceCreator.java:61)
> at
>
> org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
> at
>
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
> at
>
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
> at
>
> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
> at
>
> org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
> at
>
> org.apache.tapestry5.ioc.internal.SingletonServiceLifecycle.createService(SingletonServiceLifecycle.java:29)
> at
>
> org.apache.tapestry5.ioc.internal.LifecycleWrappedServiceCreator.createObject(LifecycleWrappedServiceCreator.java:46)
> at
>
> org.apache.tapestry5.ioc.internal.AdvisorStackBuilder.createObject(AdvisorStackBuilder.java:63)
> at
>
> org.apache.tapestry5.ioc.internal.InterceptorStackBuilder.createObject(InterceptorStackBuilder.java:54)
> at
>
> org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:60)
> at
>
> org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
> at
>
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
> at
>
> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
> at
>
> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
> at
>
> org.apache.tapestry5.ioc.internal.Operat