HTML/HTML5 website creating using Jodd(java) framework - java

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.

Related

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.

Integrating Javascript Frameworks with Java Web Frameworks

I have what I think might be a strange question to ask.
Recently I was playing with some java web frameworks (jsf with primefaces) and I noticed that it's quite good at handling form data or when you play along with the jsf components. I also did a project using grails and again it was useful for form data.
But the moment you want to do something which requires a little deviation; then I found myself doing weird things (examples are tag clouds with large strength values using primefaces and single page webapp forms with grails).
This resulted in some very messy html+javascript code for my grails things(which I blame on my inexperience with javascript). This was done because I was using expression language (grails in this case) to populate some of the javascript. The worst part was that I had a bunch of custom javascript code inline with my server pages (I could of refactored a little out but I think one would still have alot of javascript calls inside a single page).
So now to the question(s) :)
[main question] Are there any resources that demonstrates how to design or at least implement maintainable javascript with server pages (gsp, xhtml, etc) ?
The reason is that I find that there are some neat javascript frameworks, but using them with server pages seems a bit unnatural if one takes into account the expression languages for server side frameworks? Unless it's normal to do this type of thing :) ?
Are there appropriate frameworks for Single page webapps using java?
My current answer is that GWT, Vaadin (based off GWT) and perhaps JavaFX qualify. Maybe ZK, Flex and (Grails/Roo + Flex/GWT) also qualify as well?
Are java web frameworks still useful for presentation layers?
My current answer is that they might be when you are dealing with portal type webapps or Web 1.0 apps for lack of a better word. The other case is that they could be when you use alot of role based security and you want to filter things out based on roles, but even that has counter arguments.
My other answer to this is that it might be better to use a java server to provide your web services and then rely on something else to do the front end?
This might be OP, but for single page apps, it's easier to serve up data from the server via JSON(P)/XML/whatever and then use things like Backbone to process and modify the view(s) accordingly. That way, the server can use REST/SOAP/websockets/whatever, and the browser app becomes a full-fledged app.
I haven't actually done this, so don't quote me, but I imagine that it should make sense.

Converting Java app into a web app, will i benefit from using a framework?

I have created a Java desktop application, and have decided to turn it into a web app. The app carries out basic statistical tests on data and is fairly small around 1000 lines for main functions.
So far i have created the interface using Jquery UI with all requests sent via Ajax. I am now ready to start developing the back end, the plan was to code basic Servlets to link my interface to the core Java classes.
Would this be a ok approach for a small app? or is there a specific framework i should follow?
I have looked over struts but it seems massive and also spring mvc, but again i am not sure if that would work with my one page interface.
(This whole app is for learning purposes, so i am always willing to extend my knowledge, however looking for that doesn't take too long to learn.)
I've started building my webapps as Jersey + Jackson backends, offering up a REST API to a static HTML/JQuery/Angular front end.
It's worked out to be really scalable as you can heavily cache the front end and stick it on Amazon Cloud Front, and the backend can scale horizontally as needed. The need is much lower than traditionally as it's only actual operations that hit the Java server.
If your program is only 1000 lines, you will probably spend more time learning a framework then the time it will save you. You can make a well designed MVC server without a fancy framework.
There are some APIs that might be useful though, like a logging API or Hibernate if you need a database.
I agree with the other answers that REST is a good idea.
A framework can get routine off you shoulders. The JAX-RS mentioned above will handle URL-to-service mapping and conversion from JSON to your types and back.
Now, what to choose is entirely up to you. For a small application, the time you spend learning the framework can be so huge that you won't care about the benefits any more. On the other hand, frameworks give you a code which is easier to read and thus easier to maintain.
I would suggest to expose a RESTful API using some JAX-RS framework (e.g. Jersey) instead of pure servlets.
Also, as a representation I suggest to use JSON, which is very conveniently used in Javascript with/or without JQuery .

Server side technology with ext-js

I have chosen Ext-JS to develop the UI for my next application. I am wondering what is the best way for Ext-JS to interact with my server.
Should I use plain JSPs which return a JSON response? Should I use DWR or Jabsorb which provides direct remoting with backend java code. Any other solution?
I am more concerned about performance and nothing else.
You can certainly use plain JSPs or servlets, manually handling your requests and forming JSON responses. You'll make life easier on yourself using DWR or something like it to handle the plumbing for you, and the performance shouldn't be noticeably different.
Current versions of Ext JS use the Ext.Direct stack for integrating supported back ends into the UI data layer, making it much simpler to bind components like grids and forms to your back end services. Here is a grid sample that demonstrates such remoting. Here is the Ext.Direct forums -- you should have a look at what others are doing. Look at this post to see what Ext.Direct providers are currently available for Java.
Again, you can certainly make your calls manually from Ext using Ext.Ajax directly (or using the standard Store methods for making calls), but the Ext.Direct stack can make it much easier to integrate everything together.
we'r using the extdirect library for Spring MVC 3 in our Company and it works fantastic !
Extdirectspring
You can ask me when you've troubles configuring it.

How do I separate markup from application code when building a Java website?

I'm a .NET web developer who has just been asked to produce a small demo website using NetBeans IDE 5.5. I have no experience with Java up to this point.
I've followed a couple of quick tutorials, one which just uses a JSP file and another which uses a servlet. My concern at this early stage is that it looks difficult to keep my application code away from my markup.
Using JSP files looks quite similar to the old days of classic ASP. On the other hand, servlets look useful but seem to involve a lot of writing out markup to the output stream, which I'm not happy with either.
Is there an equivalent to the ASP .NET code-behind model, or any other strategies for separating out markup and code? Is it possible to keep markup in the JSP and then use the servlet from the JSP?
You can't do something similar with ASP.NET code behind using pure Java EE technologies. You need to use an MVC framework like Spring MVC or Struts. The idea is that you create your controller (Java Class) and a JSP page and configure an action to tie the JSP page with the controller.
It isn't a simple as the ASP.NET as it requires configuration and an external framework.
Netbeans has JSF framework embedded. Have a look at this tutorial.
The thing about Java is that it doesn't really come 'bundled' with stuff in the same way .NET does... you generally go looking for the goods.
This makes starting with web apps in Java daunting because there are so many options. Many of them are built off JSPs, which is a plus.
If you are set on using vanilla JSPs you are not going to have a good time. Otherwise, I would suggest Wicket, Stripes or Spring MVC.
Stripes is probably the simplest of the three (Spring is a little complicated and Wicket is conceptually different from the other two). Having said that Spring MVC is probably the most used of the three..
All Stripes really is is JSPs and ActionBeans. Action beans are Java classes that contain actions, which are methods that perform your actions. Theses ActionBean classes also contain the data for the current page.
This page has more information about Stripes.
Wicket has "proper mark-up/logic separation" (as they put it).
You might want to take a look at Custom Tag Libraries in JSPs
For a simple website I would use Struts and Tiles, and make use of the Tag Libs that they provide to make the JSPs look neat and marked up, and separate the code into Actions in the Controller - an Action is just a block of code the Struts servlet calls after doing its work.
It doesn't take long to get the basics of Struts 2 and Tiles, you can pick it up in a day easily.
And yes, Servlets are quite a simple level to write such systems, and it is easy to end up with HTML generators there, which as you've said, is clearly not right. I think you need to be putting more values on the request and session objects, and then formatting them within the JSP.
The strength here is that you can pick your MVC framework to match the scale of your application, yet still have access to raw servlets should you require them for specific actions (e.g., one thing I did in the past was generating and serving an Excel file from values in the database).
If you want to get something out quickly (I note you're putting together a demo), I would perhaps forgo the Java web frameworks, and simply use the servlet solution, combined with a simple templating solution.
Either Velocity or Freemarker will provide the facility of separating your markup from your code. Velocity is simpler than Freemarker. Freemarker is more powerful than Velocity.
I'm not down on the various frameworks mentioned. It's just that if your timescales are short and you're happy to program to the servlet interface for this requirement, then the above may provide the quickest/dirtiest solution :-)
You can use this and do the same as what you did in .NET! It is a very good MVC framework.

Categories

Resources