Hello, I’m having some problems with a JQuery component that I added to my project, It’s almost working but I haven’t been able to retrieve an array of a method on the javascript. I was trying to find some example of how to do it but I couldn’t find anything, so I did this:
The component is a simple div with the ‘Sortable’ widget called SortableView. Im catching the events and calling the methods I need.
So basically what I did was to create a the method
constructArray
on my javascript
and added a ‘event’ called
triggerGetArray
on my AbstractJavaScriptComponent:
js:
$(function() {
getArray = function(id, info) {
//console.log("*********currentSelf:" + element.id );
self.triggerGetArray(info);
};
viewMod = function(info) {
//console.log("*********currentSelf:" + element.id );
self.onViewMod(info);
};
});
...
this.conArray = function(id) {
var array = $("#" + id + "").sortable("toArray");
getArray(array);
};
java:
[code]
public class SortableView extends AbstractJavaScriptComponent {
…
…
this.addFunction(“triggerGetArray”, new JavaScriptFunction(){
@Override
public void call(JSONArray arguments) throws JSONException {
System.out.println( "id:" + getViewId() + " ls2:"+ sortArraylistener.size()+ " array:" + arguments.toString() );
for( SortArrayListener ls2 : sortArraylistener){
ls2.sortArrayReceived(res);
}
}});
…
…
public void getArray(){
this.callFunction(“conArray”, this.getViewId());
}
[/code]
I have two SortableView:
SortableView svCatalog = new SortableView ("gCatalog") //Items on the db.
svCatalog.addOnSortArrayListener( return new SortArrayListener(){
private static final long serialVersionUID = -8212235728223500129L;
@Override
public void handleAction(Object sender, Object target) {
}
@Override
public void sortArrayReceived(JSONArray a) {
Notification.show("JSON recived", Notification.Type.TRAY_NOTIFICATION);
}
);
SortableView svSearch = new SortableView ("gSearch") //searchResults;
if a get the array without any changes on the
svSearch
, the svCatalog works fine:
svCatalog.getArray();
tomcat console: id:gCatalog ls2:1 array:[[{ … }]
] //all values are correct
but after a do a search then this is what I get when I get the array:
svCatalog.getArray();
tomcat console: id:gSearch ls2:0 array:[[{ … }]
]
the id of the component is
gSearch
and
0 listeners
, even when I call
svCatalog
.
Im guessing its because of the
scoope of ‘this’
on my javascript, changes to the component ‘gSearch’,
So my questions are two:
-
The way Im using to retrieve the results of the .toArray(), Its OK? or there are other more correct method?, If so, where I can see examples.
-
If this is OK, how do I
‘bind’
to the method I use to get the getArray, I did it with the event on
sortchange
but I dont know if I can do the same thing with a method.
.
$(“#” + id + “”).bind(‘sortchange’, function(e, ui) {
viewMod(‘some info…’);
});
Thanks in advance.