Showing posts with label mvc. Show all posts
Showing posts with label mvc. Show all posts

Thursday, November 18, 2010

Alfresco @MVC

I was never happy with webscripts and I always preferred using Java to Javascript server-side programming ... but that is just a personal opinion and preferences.

Alfresco 3.4 came with Springframework 3, I have to say that Alfresco has been really slow in adapting newer versions of different technologies and probably they will remain, but this move is a good one and I was waiting for that for a long time. A lot of people are using Springframewok and especially the @MVC annotations and now we can do the same with Alfresco, of course not out of the box.

To achieve that I wrote a webscript which enables the usage of Spring @MVC inside of any Alfresco modules (AMP). Sure, I must admit that Alfresco Share is using it but I am a partisan of using Alfresco as a platform and not only as a repository, therefore I prefer writing java code integrated with the Alfresco Java API. This way of working opens huge possibilities and you can be much faster in developing new controllers than new webscripts. This approach is a standalone webscript design and let Spring @MVC do the rest for you.

I did not yet published the code but will be done soon at Google code. However here is a preview of what you can do ...

Firstly you need to initialize the webscript as you would do with any other webscript

<bean id="webscript.com.gradecak.spring.dispatch.post" class="com.gradecak.spring.webscript.DispatcherWebScript" parent="webscript" scope="prototype">

<property name="contextConfigLocation" value="/WEB-INF/classes/alfresco/module/com.gradecak.spring/context/dispatcher/servlet-context.xml">

</property>

</bean>


than in the servlet-context.xml you simply enable Spring annotations and use all the Spring config you want ...

...
<context:annotation-config />

<context:component-scan base-package="com.gradecak.spring.controller" />

...


and than in the controller you are free to use Alfresco's Java API or any library that you want

@Controller
@RequestMapping("/user/*")
public class UserController {

@RequestMapping(value = "get", method = RequestMethod.GET)

public String getUser(@RequestParam String userId) {
....

}

}


Sure, some minor problems appear if you want to use Freemarker as the view but that is just a matter of having Alfresco include a newer Freemarker JAR file and if you want to use a JSON view, Spring is coming with Jackson, but for a higher integration we need a later version of Spring than 3.0.0 provided by Alfresco ... so let's the show go on ;)

Saturday, October 13, 2007

Rich Internet Application (RIA)

A non-expert talking about user interfaces should not be taken seriously, but here is some thoughts that came to my mind.
Well, a RIA is in fact a Web Application that has the features like a desktop application.

A classical web application (let's call it Web1.0 application) has something that we call web flows, presentations flows or whatever how else somebody use to call it. Those flows are page based flows and they dictate the way a user is browsing from one page to another and so on.
I would even say that the page flow is dictated by end user requirements for the usability of the application (i.e a real state application, bank application ... ).

A RIA (or Web2.0 apps) should not limit users to a predefined flow. I think there should be no flow at all, because the user should be able to do whatever he/she wants at any moment and in any way. For example, one should be able to lookup a contact information while writing an email.

Actually, MVC (model view controller) pattern helps in separating the user interface from the business logic. But, MVC has not much to do within this article so I will not discuss about it more.
In my mind a RIA should be totally decoupled from the server presentation flow, and there should be no presentation flow, as I said already.

What about loading the whole user interface at the startup time and let the user navigate through the application just the way he would do it in a desktop application? Well, there should be a possibility to enable some components to be loaded later for example the less used components. The communication with the server should be done using AJAX of course, but the presentation layer is entirely managed by the client side.

I agree that there are a lot of applications written following this principle already, but I guess there is some place to think about this and maybe add enhancements to this way of programming.