Thinking about html e-mails for our e-commerce site I thought about reusing jsf and other 3rd party libraries as a template engine to create the e-mails on our application server (Glassfish 3, EAR).
Is it possible to manually run jsf with a local file and initialize the necessary bean to capture the html output to be saved in a String?
Why have a look at other template frameworks if jsf provides much flexibility and could do the job.
I am currently using JSF on glassfish for generating emails inside of a EJB. I based my work on the following blog post:
https://rogerkeays.com/how-to-create-email-from-jsf-templates
Basically it works when the JSF is rendered in a request that was made from the web.
I currently try to also use JSF in unit tests and scheduled executions but I currently have trouble to start JSF.
The following class is doing the initialization of Faces:
com.sun.faces.config.FacesInitializer
Unfortunately it requires a complete implementation of the Servlet 3.0 implementation. In my cases starting the servlet engine also requires an JMX server.
From my current experience I would recommend to use a template engine with less dependencies e.g.
Velocity http://velocity.apache.org/
Freemarker http://freemarker.org/
Related
I have been working on an infrastructure project that has a myriad of pages that used in numerous flow based scenarios. I eager to use a standard framework for facilitating this flows. I have a glance on spring web flow and I realize it is difficult to deal with all of the XML stuff like flow files. Could you please tell me is there an annotation base version instead of these XML files? Or Is there any other frameworks that use annotation based approach for this purpose. Moreover, I saw Seam framework, but like Spring Web Flow it has an XML based feature. Additionally, I read some articles about Netui Page Flows. Even though it has annotation based flows, as you know it is a very old framework and discontinued now.
I use this links:
spring web flow support in intellij idea 12
Spring Web Flow Ref Book
spring web flow
As I need this xml based file for create a web flow for my JSP pages into my enterprise application, after month looking for best solutions and frameworks, finally I find Spring Statemachine for my porpuse. I put that here for someone in future that looks for object-oreinted state machine that can be used in her/his page flow.
Thank you Spring :)
I'm just new with drools and web development, I'm just wondering if how can i integrate Drools in a Web Application, I'm using JSP and Servlet technology if I'm not mistaken with the term. I'm also planning of using MVC pattern not SpringMVC.
What I already done is:
Downloaded Drools and jBPM as plug-in in eclipse ( Able to create a Drools Project as a proof)
Already create a Dynamic Web Project, running and using Tomcat as a server
My question is where should i put Drool library for me to use the rules depends on the user's input in a JSP? Or if i missing something kindly tell me.
In general, libraries (jar files) should be put in the WEB-INF/lib folder of your web application, which can then be packaged as a whole in a .war file. Tomcat (or whichever servlet container you decide to use) will then load them in the classpath as part of its webapp initialisation. Drools might require specific configuration to tell it where it will find the rule files to load them, check the Drools documentation for that.
I can assure you it works from within a web app and also within an application using the Spring framework. I've seen it work with web services using JAX-WS (Apache CXF) with Spring on Tomcat exposing web services which use Drools to determine what business logic to apply.
When asking this I answered myself: use a jsp.
But ok, what about a lightweight, easy to use framework?
It would be perfect if this framework had Eclipse plugin,
so that I could generate all code in one click and simply fill one method body (populate it with the data), then in one click
create a war file using a wizard
and deploy it on Tomcat.
Are there such frameworks?
p.s. I use spring, but I think there are ways to integrate it into every framework.
Take a look at Spring Roo.
If you only want to list a few DB records, I would just implement it dirty with a simple JSP with scriptlets. But you could also use the JSP SQL Tag library for that.
A simple one method body controller that needs that forwards to a view can most easily be writen with the Stripes framework that forwards to a JSP view (see wikipedia code example for how easy this can be done).
Generating nice tables in JSP can quickly be done by the popular Display Tag library.
If your not afraid to learn something new take a look at Grails
One of the big advantages of Grails is that its a full stack environment. Meaning that out of the box you get everything you need for your web app development
Test Servlet container (Tomcat)
Test database (hypersonic)
ORM (hibernate)
etc.....
Once installed just run
> grails create-app
Then you have a complete runnable application. (Auto bootstraps your project creation and config)
I am using springMVC and hibernate in my current j2ee project.
The view as of now consists of plain jsp, with JSTL to make things a bit simple.
Looking at the extjs project, I believe it can be used as a substitute for the view. I have been looking at the extjs docs but frankly, I am not sure how to integrate it in spring.
Does anyone have any tutorial, blog, books recomendation, to get me started on this?
Or on the other hand, if extjs would be better managed from a different java MVC framework, then please suggest the same.
Here is an example of a ProgressBar Pager integrated with Spring 3.0
It Demonstrates that Ext JS provides a helper class, XMLStore, which is automatically configured with an XMLReader which is used to read data from server.
It uses Xstream from codehaux for serialization to XML.
XStream is easily configurable with annotations,
I like to use Spring views to return JSON data. Requests arrive and handled by a ThrowAwayController or MultiActionController or annotations (depending on the version of Java) which eventually passes a model to a JsonView. There are libraries/packages that create JSON from Java objects - I recommend using one. The client is a single page web-app - generated from JavaScript when the site initially loads - and it makes requests to the server (as described above) in response to user requests. JSP and JSTL are not discarded entirely, but their role is less important.
You can have a look on http://www.jprovocateur.org (Spring + Hibernate + Ext J.S) that allows the configuration of the ext j.s views(forms and grids) using xml.
Regards,
M.
I've been looking into OSGi recently and think it looks like a really good idea for modular Java apps.
However, I was wondering how OSGi would work in a web application, where you don't just have code to worry about - also HTML, images, CSS, that sort of thing.
At work we're building an application which has multiple 'tabs', each tab being one part of the app. I think this could really benefit from taking an OSGi approach - however I'm really not sure what would be the best way to handle all the usual web app resources.
I'm not sure whether it makes any difference, but we're using JSF and IceFaces (which adds another layer of problems because you have navigation rules and you have to specify all faces config files in your web.xml... doh!)
Edit: according to this thread, faces-config.xml files can be loaded up from JAR files - so it is actually possible to have multiple faces-config.xml files included without modifying web.xml, provided you split up into JAR files.
Any suggestions would be greatly appreciated :-)
You are very right in thinking there are synergies here, we have a modular web app where the app itself is assembled automatically from independent components (OSGi bundles) where each bundle contributes its own pages, resources, css and optionally javascript.
We don't use JSF (Spring MVC here) so I can't comment on the added complexity of that framework in an OSGi context.
Most frameworks or approaches out there still adhere to the "old" way of thinking: one WAR file representing your webapp and then many OSGi bundles and services but almost none concern themselves with the modularisation of the GUI itself.
Prerequisites for a Design
With OSGi the first question to solve is: what is your deployment scenario and who is the primary container? What I mean is that you can deploy your application on an OSGi runtime and use its infrastructure for everything. Alternatively, you can embed an OSGi runtime in a traditional app server and then you will need to re-use some infrastructure, specifically you want to use the AppServer's servlet engine.
Our design is currently based on OSGi as the container and we use the HTTPService offered by OSGi as our servlet container. We are looking into providing some sort of transparent bridge between an external servlet container and the OSGi HTTPService but that work is ongoing.
Architectural Sketch of a Spring MVC + OSGi modular webapp
So the goal is not to just serve a web application over OSGi but to also apply OSGi's component model to the web UI itself, to make it composable, re-usable, dynamic.
These are the components in the system:
1 central bundle that takes care of bridging Spring MVC with OSGi, specifically it uses code by Bernd Kolb to allow you to register the Spring DispatcherServlet with OSGi as a servlet.
1 custom URL Mapper that is injected into the DispatcherServlet and that provides the mapping of incoming HTTP requests to the correct controller.
1 central Sitemesh based decorator JSP that defines the global layout of the site, as well as the central CSS and Javascript libraries that we want to offer as defaults.
Each bundle that wants to contribute pages to our web UI has to publish 1 or more Controllers as OSGi Services and make sure to register its own servlet and its own resources (CSS, JSP, images, etc) with the OSGi HTTPService. The registering is done with the HTTPService and the key methods are:
httpService.registerResources()
and
httpService.registerServlet()
When a web ui contributing bundle activates and publishes its controllers, they are automatically picked up by our central web ui bundle and the aforementioned custom URL Mapper gathers these Controller services and keeps an up to date map of URLs to Controller instances.
Then when an HTTP request comes in for a certain URL, it finds the associated controller and dispatches the request there.
The Controller does its business and then returns any data that should be rendered and the name of the view (a JSP in our case). This JSP is located in the Controller's bundle and can be accessed and rendered by the central web ui bundle exactly because we went and registered the resource location with the HTTPService. Our central view resolver then merges this JSP with our central Sitemesh decorator and spits out the resulting HTML to the client.
In know this is rather high level but without providing the complete implementation it's hard to fully explain.
Our key learning point for this was to look at what Bernd Kolb did with his example JPetstore conversion to OSGi and to use that information to design our own architecture.
IMHO there is currently way too much hype and focus on getting OSGi somehow embedded in traditional Java EE based apps and very little thought being put into actually making use of OSGi idioms and its excellent component model to really allow the design of componentized web applications.
Check out SpringSource dm Server - an application server built entirely in terms of OSGi and supporting modular web applications. It is available in free, open source, and commercial versions.
You can start by deploying a standard WAR file and then gradually break your application into OSGi modules, or 'bundles' in OSGi-speak. As you might expect of SpringSource, the server has excellent support for the Spring framework and related Spring portfolio products.
Disclaimer: I work on this product.
Be aware of the Spring DM server licensing.
We've been using Restlet with OSGi to good effect with an embedded Http service (under the covers it's actually Jetty, but tomcat is available too).
Restlet has zero to minimal XML configuration needs, and any configuration we do is in the BundleActivator (registering new services).
When building up the page, we just process the relevant service implementations to generate the output, decorator style. New bundles getting plugged in will add new page decorations/widgets the next time its rendered.
REST gives us nice clean and meaningful URLs, multiple representations of the same data, and seems an extensible metaphor (few verbs, many nouns).
A bonus feature for us was the extensive support for caching, specifically the ETag.
SpringSource seems to be working on an interesting modular web framework built on top of OSGi called SpringSource Slices. More information can be found in the following blog posts:
Modular Web Applications with SpringSource Slices
Pluggable styling with SpringSource Slices
Slices Menu Bar Screencast
Have a look at RAP! http://www.eclipse.org/rap/
Take a look at http://www.ztemplates.org which is simple and easy to learn. This one allows you to put all related templates, javascript and css into one jar and use it transparently. Means you even have not to care about declaring the needed javascript in your page when using a provided component, as the framework does it for you.
Interesting set of posts. I have a web application which is customized on a per customer basis. Each customer gets a core set of components and additional components depending on what they have signed up for. For each release we have to 'assemble' the correct set of services and apply the correct menu config (we use struts menu) based on the customer, which is tedious to say the least. Basically its the same code base but we simply customize navigation to expose or hide certain pages. This is obviously not ideal and we would like to leverage OSGi to componentize services. While I can see how this is done for service APIs and sort of understand how resources like CSS and java script and controllers (we use Spring MVC) could also be bundled, how would you go about dealing with 'cross cutting' concerns like page navigation and general work flow especially in the scenario where you want to dynamically deploy a new service and need to add navigation to that service. There may also be other 'cross cutting' concerns like services that span other of other services.
Thanks,
Declan.