Ajax - Servlet -- MVC

Hi you all,

I am having some design problems that I can't find the solution to.

Here is the problem.

I am using a self made AJAX library to make requests to a servlet (controller), which basically fowards the request to the jsp page I need.

When the site is first loaded i need to fill in 4 main divs(Top, bottom, left, right), to do this I am using a main jsp, with the four main divs and within each one there is an included jsp file.

With this pattern I use JSTL as well, and everything runs fine. But there is one point here, if for eg some exception is thown on the server, what the user will see within one of those divs is a 500 error status. This doesn't fit the way our application is running. I wanted to use a MVC-2 like patern but it is being difficult to get that with AJAX. What I once did, was making multiple request to fill the initial page. Someone once told me that this approach was not the best, but at least I could have a better controll over the applications flow. Its good to use JSP/JSLT for further requests, but not for the first one.

Other thing, I know JSP/JSLT is a good way to build up the user interface, but doens't make more sense to send XML from the server rather then HTML? It can be a bit more tricky to get everything running in multiple browsers because if I was to send all the requests in XML I would have to parse the entire XML stream to create the different DOM objects... Well I haven't decided whats the best approach, of course it depends on the project as well, but resuming which one do you guys prefer: JSP/JSLT or JSP/XML

I would like very much to hear from you ;)

Many thanks,

Marco

[1702 byte] By [Me_Titusa] at [2007-11-26 16:13:00]
# 1

> With this pattern I use JSTL as well, and everything

> runs fine. But there is one point here, if for eg

> some exception is thown on the server, what the user

> will see within one of those divs is a 500 error

> status. This doesn't fit the way our application is

> running.

Not clear what you mean about this.

> Other thing, I know JSP/JSLT is a good way to build

> up the user interface, but doens't make more sense to

> send XML from the server rather then HTML?

JSTL is great for the dynamic work in JSP. JSPs are often used for creating a user interface, but is not limited to that alone. XML is great for transporting data. It is usually up to whatever client side technology you have that recieved the XML to convert the XML into a user interface.

> It can be

> a bit more tricky to get everything running in

> multiple browsers because if I was to send all the

> requests in XML I would have to parse the entire XML

> stream to create the different DOM objects...

You should look for pre-made tools to do it for you. Something undoubtedly already exists.

> Well I

> haven't decided whats the best approach, of course it

> depends on the project as well, but resuming which

> one do you guys prefer: JSP/JSLT or JSP/XML

JSTL (JSP Standard Tag Library) and XML (eXtensible Markup Language) are not mutually exclusive. JSP/JSTL are great for generating dynamic content to be served to the client. The content being generated is normally HTML (HyperText Markup Language), but does not need to be. If you are doing ANY dynamic content in JSP, I would use JSTL. Whether the content you generate is HTML or XML depends on where you want the view to be generated - on the client or on the server.

Use HTML if the server should generate and control the view. Use XML to allow clients to control the view. XML allows more options - the client is a web page with javascript turning the data into display today, and could be a Web Start application or some other technology tomorrow. On the otherhand, as you already suggested, getting client-side scripts that perform the same independently of what browser it is running on is complex, your view code gets pretty complicated. If you do go that way, I would try to make good use of CSS (Cascading Style Sheets) and pre-configured blocks of HTML that gets data inserted and removed from it, hidden and displayed, rather than re-building DOM objects each time.

That way, you can have a mini-client side MVC structure. The CSS and the pre-configured HTML make up the View. A series of javascript functions designed to assign data to the proper portion of the HTML, manipulating CSS to get the parts made visible in the correct order and locations, and the AJAX requests to the server to get the data makes the Controller part of the client-side app. Finally, the XML data and its translation makes up the Model.

>

>

> I would like very much to hear from you ;)

>

> Many thanks,

>

> Marco

stevejlukea at 2007-7-8 22:35:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thank you very much stevejluke,

>> That way, you can have a mini-client side MVC structure.

This is indeed what I am trying to get. I am creating my own javascript libraries to archieve this and so far everything is going very good. I have applied this library of mine to a .net project, and now i am improving it a bit so that I can tie it to this java project that I am working on.

Your reply was very helpull,... I am a bit lost by I think i will get what I need.

Many Thanks,

MeTitus

Me_Titusa at 2007-7-8 22:35:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
hijust refer following url http://javasoft.4000webs.com/tutorials/ajax.htmbyArunkumar SubramaniamSFRC IT Solutions Pvt Ltdwww.sfrcindia.com
Arunssofta at 2007-7-8 22:35:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...