PDA

View Full Version : Ext and Ajax Pro



rodiniz
26 Feb 2007, 4:33 AM
Hi Jack I am making some classes to integrate Ext with AjaxPro .
And I already made possible to load the Ext Grid with a .Net DataSet.
But I had to do some code changes...( I was using alpha 1.0) in the connection class
..
but now I am lost

Now I wonder where is Ext.lib.Ajax defined????

Arikon
26 Feb 2007, 4:44 AM
Ext.lib.Ajax defined in YUI/jQuery adapter in Ext-1.0-Alpha2.
In Alpha1 - in similar purpose file, can't rember it name =)

rodiniz
26 Feb 2007, 5:14 AM
I see only the mimified version...

jack.slocum
26 Feb 2007, 5:36 AM
The uncompressed file is under "experimental".

Just so you know, you should be using a new proxy to work with another libs results (e.g. DWR, AjaxPro) in a generic manner. This way you can contribute the proxy and we can have built in integration. :)

timb
26 Feb 2007, 6:28 AM
I use AjaxPro as well, and I'd love to see a proxy for this. Last week I was trying use the yui connection utility with AjaxPro, but it doesn't work well at this time (non-standard JSON). Michael is currently working on a new release which will allow other client side Ajax libraries, but there's no info on when this will be available (the last I heard was that there would be a beta in October 2006, but this isn't available yet). So a proxy in Ext for AjaxPro would be great.

Rodiniz, if you'd like a tester or some feedback, please don't hesitate to PM me.

Jack, any pointers on creating the proxy?

Regards,
Tim

rodiniz
26 Feb 2007, 6:47 AM
The uncompressed file is under "experimental".

Just so you know, you should be using a new proxy to work with another libs results (e.g. DWR, AjaxPro) in a generic manner. This way you can contribute the proxy and we can have built in integration. :)
I am using a new Proxy but the code does not work unless this lines


if(this.AjaxProMethod){
YAHOO.util.Connect.initHeader("x-ajaxpro-method",this.AjaxProMethod);
}

are wright before


this.transId = Ext.lib.Ajax.request(method, url, cb, p);

I will check again to see if it works on my ProxyClass

rodiniz
26 Feb 2007, 6:51 AM
I use AjaxPro as well, and I'd love to see a proxy for this. Last week I was trying use the yui connection utility with AjaxPro, but it doesn't work well at this time (non-standard JSON). Michael is currently working on a new release which will allow other client side Ajax libraries, but there's no info on when this will be available (the last I heard was that there would be a beta in October 2006, but this isn't available yet). So a proxy in Ext for AjaxPro would be great.

Rodiniz, if you'd like a tester or some feedback, please don't hesitate to PM me.

Jack, any pointers on creating the proxy?

Regards,
Tim

Hi Tim.. My AjaxProProxy class is working fine and I was able to implement also
a DataSetReader so you can " bind" the Ext grid to a .net Dataset.
As soon as I solve the problem in the post above.. I will post a sample at my website.

jack.slocum
26 Feb 2007, 7:22 AM
Doesn't Ajax pro have it's own connection methods?

timb
26 Feb 2007, 7:59 AM
Hi Jack,

Yes, it does. However, it is possible to retrieve data using yui Connect utility if the InitHeader is set, as shown by rodiniz. It will return non-standard JSON, and most encode/decode functions will not be able to handle all data types, specifically dates. The client side library for AjaxPro uses an eval statement to decode the JSON string. Michael is currently working on this, and I'm hoping for a new release soon. I'm curious to see how rodiniz handles this (and to see if it works with date parameters).

I'd have to see rodiniz's proxy, but until Michael updates AjaxPro, I think it would be best to use his client side ajax library and create a proxy that deals with that.

Note: Even though AjaxPro returns non-standard JSON, I still think it's a great library. I've been using it for quite a while now, and it's a pretty solid product. Once it produces standard JSON, it will be that much better.

Regards,
Tim

rodiniz
26 Feb 2007, 8:47 AM
Hi Tim... you can see what I have done
here http://www.rodrigodiniz.qsh.eu/datasetYahooGrid.aspx
I haven't tested with datetime yet.
But i followed Michael recomendations to encode the parameters.

Ian
26 Feb 2007, 9:40 AM
We've been using AjaxPro with Ext; haven't converted the .40 stuff into 1.0 stuff but that's what I'll be doing this week.

FWIW, we're currently having AjaxPro return JSON via Newtonsoft's JSON.Net, which is free: http://www.newtonsoft.com/products/json/

I ended up having to tweak the JSONSerializer classes a bit to get them into a format that Ext would like better. I'd be happy to post our code if anyone would want it, I think it basically just entailed stripping out an element or two to get the output more in line with what an ExtGrid was happy with.

Ian

timb
26 Feb 2007, 10:19 AM
Hi rodiniz,

I took a quick look and it looks pretty good. I'll test it out a little later this week and let you know if I find any problems.

I have one suggestion, though. On line 82 of AjaxProProxy, I suggest that you replace this:

var obj=response.responseText.replace("/*","");
with something like this:

var obj=response.responseText + "*/";
Michael put the "/*" because some servers would put some extra text at the end of the string. By ending it with "*/" before using eval, you will ensure that any extra stuff is commented out.

Ian, I haven't tried Newtonsoft's JSON.Net library yet, but I did try Jayrock (which appears to be similar). I found that the Jackrock serialization methods couldn't serialize some of my classes which AjaxPro had no problems with. I was hesitant to try Newtonsoft's JSON.NET library because of this. I'd still be interested in seeing the code, though.

Regards,
Tim[/code]

timb
4 May 2007, 12:02 PM
For those interested in using AjaxPro and Ext together, please see the following post. I would like to get some opinions on this before I submit it to be included with AjaxPro:
http://extjs.com/forum/showthread.php?p=28287#post28287

creativestandards
12 May 2007, 1:50 AM
Ian,

I am currently having problems using AjaxPro's serializer with NHibernate-created objects. There is no error, just a complete crash. JSON.NET has been tested and works without a problem. I know that using it as a serializer w/ AjaxPro involves implementing IJavaScriptConverter, but documentation is sparse. I would appreciate any information you have. Thanks.

creativestandards
13 May 2007, 4:17 AM
After some more testing, it seems that even my base object (that NHibernate is creating an inherited proxy of) crashes AjaxPro on serialization. I am guessing it has something to do with the (somewhat complicated) generic inheritance. After some further reading, I have decided to go with using DTOs to simplify what is sent to the client. The only downside to this is the added maintenance and complexity of two-way binding domain objects to DTOs. Ah well... these are the tools available at the moment.

franklt69
13 May 2007, 5:54 AM
hi, creativestandards what is DTOs?

kind regards
Frank

creativestandards
13 May 2007, 2:24 PM
Frank,

A DTO is a Data Transfer Object. It is a "lightweight" object containing only data that is relevant to the current presentation requirements. For example, if you have an "Account" class that has detailed or sensitive information (like a password or birth date) that you don't want serialized to the client for security reasons, you could create a "AccountDto" class with just the username, first name, etc. You could also combine information from multiple classes (think sql joins) into one DTO to make presentation easier. Basically, you can use a DTO as an object-oriented replacement for a DataSet, which in turn (de)serializes to/from JSON much better.

Pattern:
http://www.martinfowler.com/eaaCatalog/dataTransferObject.html

Pseudo-Code Example:


public class Account
{
public string Username;
public string Name;
public string Password;
public string Birthdate;

public void DoStuff()
{
...
}
...
}

public class AccountDto
{
public AccountDto(Account account)
{
this.Username = account.Username;
this.Name = account.Name;
}

public string Username;
public string Name;
}


In code-behind:


public void Page_Load(...)
{
.....
GetAccountDto();
}

[AjaxMethod]
public AccountDto GetAccountDto()
{
//Get Account object from database
Account a = GetAccountFromDatabase();
AccountDto jsObject = new AccountDto(a);
return jsObject;
}


In javascript:


function getTheAccount()
{
var myAccount = MyServerNameSpace.MyASPClass.GetAccountDto(getTheAccount_callback);
}

function getTheAccount_callback(account)
{
alert(account.Username + ": " + account.Name);
}


Hope that was clear, heh...

franklt69
13 May 2007, 5:38 PM
thanks creativestandards, now DTO is more clear to me, about AjaxPro, do you now if I can use this library to convert from xmltojson?, I want to show in a tree a xml (master-detail, 4 levels) I have to convert it to json but I don't know if AjaxPro can help me in it.

kind regards
Frank

creativestandards
14 May 2007, 5:33 AM
AjaxPro doesn't do XML natively I think, but you can use ASP.NET AJAX or JSON.NET:
http://www.topxml.com/rbnews/XmlDocument/re-38715_Json-NET-1-1--Converting-between-XML-and-JSON.aspx

indulgence
17 May 2007, 1:54 PM
There is not a need to create a DTO for objects w/ AjaxPro. You can use attribute AjaxPro.AjaxNonSerializableAttribute

creativestandards
19 May 2007, 2:55 PM
When I tried using objects with complex bidirectional relationships and NHibernate, AjaxPro's serializer flat-out crashed (the entire framework). Plus, having to decorate your domain model with AjaxPro serialization attributes introduces dependency throughout your whole application. Depending on the scale and scope of your application (and how obsessive-compulsive you are), that may be considered bad practice.

indulgence
22 May 2007, 6:42 AM
But maintaining DTO's means effectively maintaining the same object twice... You change update ObjectA - you've might have to update its DTO... It introduces more room for error.

And really your business objects should be in their own layer -- and you would introduce the AjaxPro dependency on that - which only becomes an issue (albeit minor) if you reuse it for a desktop application. Where you would have to ship the desktop version with the AjaxPro library.

Also - what happens when you need to serialize the business object to multiple areas and each output different data (I've had this case)... One version of the object is serialized to AjaxPro, and another to an XmlSerializer... I would hate to maintain 2 seperate DTOs for the same business object. I would much prefer to maintain just the business object and its serialization descriptors on fields.

creativestandards
22 May 2007, 8:24 PM
I see your point but it's still moot in my case since AjaxPro's serializer chokes on my domain model.

indulgence
24 May 2007, 2:04 PM
I see your point but it's still moot in my case since AjaxPro's serializer chokes on my domain model.

AjaxPro does allow you to create a serializer...