Monday, May 11, 2009

Ajax - the proper way

Here's the problem: I need to call a method that will return some JSON that will be evaluated by the client and according to the result of this operation some action must be taken. All should take place in the browser and the server should return only a JSON response with the data I need. Nothing more.

Let's see - nope! No can do, man! Because you have the feature A, B, C,... Z it's not possible! You have to keep the view state (WTH?) up to date! You need the view state on the other end (what for?).

Here's how it's done in almost any framework out there that makes use of the MVC pattern:

1. Create a method or a class and a method (depending on the technology) that will contain the actual server-side code.
2. Find out the address (usually it's as simple as /controller/method called an action in this case)
3. Use jQuery to make the call and do the rest of the processing.

Can anyone tell me why it is so hard to do in JSF?

2 comments:

  1. It can be done by Servlets in that way. But view state is must...
    view state is needed for easy binding beans with values of controls.

    ReplyDelete