How does Direct Web Remoting (DWR) work? - java

How exactly or what exactly does Direct Web Remoting (DWR) do?
While I have already gone through the official site http://directwebremoting.org/
I wanted to understand in simple language..
Specifically I have following questions;
1. While engine.js is standard Javascript library, how exactly does it help in including that in our app ?
2. What is so special about DWR that cannot be done by normal Javascript / AJAx combination?
Thank you.

OK, I've only had a brief look at DWR and I was wondering the same thing. As far as I can gather DWR builds and includes on your page some javascript that mirrors your server-side java. It will generate client-side proxies that you can call in your javascript. So instead of using jquerys $.ajax(...) command and specifying the url, data type, data, etc, you can just use RemoveObj.doSomeStuff(...) and it'll do the actual AJAX request for you, behind the scenes.
This is basically what ASP.NET does too when you declare a [WebMethod]. Its simply a shortcut and might save time with maintenance, e.g. if your urls change I suspect DWR will update its client-side code too.
My only issue with this is that it seems to pollute the namespace.
To actually answer your question it does nothing you can't do with normal javascript and servlets.

Related

HTML/HTML5 website creating using Jodd(java) framework

I've been reading about Jodd(java) framework and it looks interesting to me. But I see that it seems to be jsp/servlet based. Can you develop strictly html/html5 dynamic website without jsps with it?
Absolutely. As you can see, in Jodd Madvoc you have this concept of Result : each (java) action returns it. Results are the one that defines how you are going to render the page. By default, there are JSP results, as this is a standard, right; but nothing stops you to simply have a i.e. Freemarker result or to use any other template engine. People are doing this often. Moreover, Results are made to be configured. See: http://jodd.org/doc/madvoc/results.html
Result does not need only to return HTML content. There is a JsonResult for example, or RawResult that can return a JSON or any string.
If you want REST-ish interface that only results with JSONs, you can do that as well, checkout: http://jodd.org/doc/madvoc/rest.html
Madvoc should be configurable enough to fit your needs. Just don't think of it as a 'solution-in-a-box', but a real framework, that you need to dig just a little, but you will find what you need :)
You can develop strictly html/html5 dynamic Websites without JSPs for sure, there are many ways to do it, but in my personal opinion, I believe that you can use AngularJS for your front-end development (HTML5/CSS3). This framework will allow you to implement all your client side without minor issues. It is based on HTML5, so no JSP files will be required. If you are used to MVC or MVVM, well this framework will allow you to work with any of these two approaches.
Dynamic Web Application? Need to show data from a database or store records? No problem, Angular supports AJAX calls to REST Web Services which you can implement with the programming language you feel more comfortable. If it is Java, then you can go for some REST Web Services using Jersey.
Hope this information is useful for you.
Happy coding.

How can I convert an Applets application into an Web application using JSP and Javascript?

I have a project that is built on Applets and that also comprises of Corba calls to backend (which is in C language). Now I need to remove Applets and convert it into JSP and Javascript combination. But the code seems to be complex as it also consist of backend calls. I am facing problem in figuring out what is to be converted in JSP and what in Javascript.
If I convert all the applet logic in Javascript, how will I pass the javascript data to the Java objects to pass it as input for corba calls.
I can't implement all the logic in JSP as the existing logic depends on the dynamic change of data by user.
I tried various links but couldn't find the proper solution to my problem.
I read somewhere that Google Web Toolkit (GWT) might help me converting Java Logic to Javascript, but couldn't figure out what exactly needs to be done for that.
Can anyone guide me how should I start and what exactly should I do to complete my project?
First the bad news. There is no generic and magic solution that can convert your legacy (as you are describing it) into modern n-tiers web application.
I can suggest you the following steps.
decide what kind of client and server side technologies you are going to use and learn them to become familiar enough to start coding.
learn your legacy code and re-design it. Decide which parts of the code must be re-written, what you can use as-is and what you have to change and/or re-package.
To choose client side technology try to search for "client side javascript frameworks" or something like this. Popularity of GWT that you mentioned is going down now. The most modern framework these days are AngularJS.
Concerning server side technologies I personally prefer Spring but you can take a look on Guice and EJB too. You can also implement whole server side as as collection of servlets. It is up to you.
Start learning this amazing world and come back with more concrete questions. Good luck.

Is it possible to substitute pure html and js for JSP?

I'm learning JavaEE now and I kind of feel that JSP can be messy... I hate to mix my Java code with HTML... I want to separate the front end view and Java code as much as possible.
I've ever tried Twitter Bootstrap and I find it amazing. Is there any way that I can use HTML and JS(maybe some framework like Bootstrap) to substitute for JSP view technique? How should I accomplish the data interaction?
Yes, that is what all the kids are doing. You use REST.
You can see an example of just that in this Quickstart.
Strictly speaking, no. JSP is a server-side technology. That means that the code you write in the page is executing on your server in the environment you have set up there. HTML and JavaScript are client-side technologies; the code you write in these languages executes in the web browser of the people viewing your website. Neither technology is a complete replacement for the other; both are needed.
Even if you move more of functionality out of JSP into JavaScript (a "heavy client" implementation), you still need some server technology for your JavaScript to call to. You could get rid of JSP by moving some of the server functionality into other technologies: webservices (JAX-WS, Axis, etc.), RESTful services (JAX-RS, ApacheCXF, etc.), or straight up synchronous web-pages. But the point is regardless of what you use or whether you get rid of JSP entirely, you still need a server-side technology.

DWR and other possible tools for build java application level Ajax framework

I would assume that this question would have been asked in different ways already, but I could not find one so posting it. Sorry if its a repetition
The basic idea which I am trying to explore is to design a common Ajax framework/API for our application. The main requirement is to have a common framework in the product which every module in the application can call whenever it needs to provide Ajax behavior.
We basically have a page based application and not everything would be Ajax for sure. Mostly it will be smaller pieces of work which Ajax will handle.
We have used GWT and it works great. But we have some constraints because of which certain areas in the application need to build standard jsp and html pages only
I know little bit about dwr and it looks very promising (as even answered by some people).
I wanted to know what are the other possible frameworks like dwr which I can evaluate too, before making the decision
This might help http://en.wikipedia.org/wiki/List_of_Ajax_frameworks#Java
But DWR works great. It is simple and very effective. I suggest you go for DWR.

What would be the light way to render a JSP page without an App/Web Server

First, some background:
I will have to work on code for a JSP that will demand a lot of code fixing and testing. This JSP will receive a structure of given objects, and render it according to a couple of rules.
What I would like to do, is to write a "Test Server" that would read some mock data out of a fixtures file, and mock those objects into a factory that would be used by the JSP in question.
The target App Server is WebSphere and I would like to code, change, code in order to test appropriate HTML rendering. I have done something similar on the past, but the JSP part was just calling a method on a rendering object, so I created an Ad Hoc HTTP server that would read the fixture files, parse it and render HTML.
All I had to do was run it inside RAD, change the HTML code and hit F5.
So question pretty much goes down to: Is there any stand alone library or lightweight server (I thought of Jetty) that would take a JSP, and given the correct contexts (Request, Response, Session, etc.) render the proper HTML?
You need more than a web server. You've got to have a servlet/JSP engine, so there's no getting around that.
Jetty's quite light. Maybe Resin deserves a look, too.
I've never used JSPs, but I have played around with OOWeb. It's definitely lightweight, and follows the request/response model, but you'll be hard pressed to connect it with your JSPs without a lot of glue.
A couple lightweight containers are listed here. It looks like Tiny Java Web Server in particular is actively being developed. Unfortunately there's not much documentation available for it.
jetty and tomcat
those may be not light enough for your tastes though.
you'll find plenty of users and support on SO for tomcat, so that counts for something.
There is none ( afaik ) .
The only workaround I could suggest is to use Velocity instead. But, of course you would have to resign to jsp altogether and that could not the an option.
IF you do then you can isolate your test with Velocity move the result into a web.
Here's an article on how to use Velocity + Ruby ( or JRuby ) for an standalone solution.
http://martinfowler.com/bliki/JRubyVelocity.html

Categories

Resources