JSF Webapp-Template for many Webapp-Projects - java

I'm searching for a hint/solution to generate one Template-Webapp with a custim design and then all my other Webapps should take the design from the Template-Webapp. Is that possible? The Idea behind is, that we I have multiple Webapps for Projects, but the Layout,... is the same on all Project. And when changing the Template-Webapp, all other Webapps are changed without changing the source-code in all Webapps.
I've got a running Webapp with my design(Template-Webapp). All is runing on a Tomcat 7. In another Webapp, I tried to use the template-file from the Template-Webapp, but I can't get it running. Perhaps its not possible to navigate through the webapp-folders on Tomcat? It's showing "invalid path"-failure. But, the path is correct. With selecting the path, I can easy access the template-file.
Does anybody had the same problem or knows how to solve it ?
Thanks for every help, even if it's small

You should look into breaking your front-end pieces up.
It ends up being like moving magnets around on a refrigerator. Except the magnets are components of your template!
It is called templating with composite values.
My Related Answer:
How does JSF render more than one JSP pages into 1 single view?
Documentation:
JSF 2 fu: Templating and composite components
Core J2EE Patterns - Composite View - Oracle
Hope that helps!

Take a look on some webresources how to work with templating (JSF > 2.0) and contracts (JSF > 2.2).
http://www.mkyong.com/jsf2/jsf-2-templating-with-facelets-example/
http://hantsy.blogspot.de/2013/08/jsf-22-theme.html
The best way to share one template across many projects is to bundle the contract including all recources into one *.jar
As far as i know, the template/contract/whatever should be in the right directorys, thus within the same project at least included as jar.

Related

Spring and thymeleaf with html as resources

I am learning java ee related technologies (and I am relatively newbie) and try to write simple web application with Spring and Thymeleaf as frontend, and i have some problems with
modularization.
I found that it is used to pack .html filesinto WEB-INF directory for security purposes, but, as far as i guess, it means I have to put there all of my views, have controllers in this projects. I want to avoid that by having many projects for example:
web-app
admin-module
user-module
core-module
and each of them has its own, module specific controllers and views (htmls) and web-app
combines them all into single, big project.
In Thymelaf i found something like ClassLoaderTemplateResolver and got (maybe stupid idea) how to divide big project into many ones - put htmls into classpath resource directory.
By this I can ask for any html view from any module project. Does this violates some security reasons?
I would like to ask does anyone has similar problem and found proper solution how to elegantly divide html web-app project into many smaller 'context-specific' projects?
Here is my current project structure. Blue arrow idicates which view is connected to which controller:
http://prntscr.com/4tqt9m
This is my first question asked here so I hope you will treat me with some understanding.
Thank you in advance.
You might be able to merge multiple Spring and Thymeleaf modules at runtime using classpath lookup. Just make sure you give different qualified name / folder structure (eg: two files named views/index.html on different packages might cause confusing inconsistencies)
With Spring if you configure the classpath scanning properly it should take into account jar packages on the classpath.
With Thymeleaf, try setup a TemplateResolver with prefix such as classpath:/templates/, then on different modules setup a folder structure such as src/main/resources/templates/package-a/foo.html, src/main/resources/templates/package-b/foo.html. I haven't yet tried this, and not 100% sure the class loader can merge these alright.

How to pack portlet+theme+layout into single WAR/web application in Liferay?

The ROOT application contains all of the items described (classic theme, approx 10 layouts and numerous portlets).
Is it possible or good practice to create own packages like this? How to?
Please, give a hint.
Theoretically it is possible to have a single project with a Portlet, Theme, Layout and a Hook all packed in one.
But it is not at all a good-practice to have all the four types togather, from both maintenance and development perspective.
Though sometimes you may have a portlet and hook in one project if they are somehow related for example like you want to have some Listeners to add data to your custom table and then your portlet would provide an interface to update or view that data, so in this case they are interdependent and if the portlet goes the hook is of no use. So go ahead and combine them.
So if the 4 types are related somehow or interdependent than I see a usecase to have them togather (it would be rare) but still from maintenance point of view I would rather keep the 4 separate. Atleast I would keep portlets and themes separate and may have a Portlet-hook combination and a theme-layout combination since they go well with each other even from the maintenance & development point-of-view.
Here is how you can do it
Let the name of the project be say MyCompletePackage-portlet
The project can live in the portlets folder of the plugins-sdk if you are using the plugins-sdk.
Now add the plugin-type specific stuff as you normally do, like:
liferay-hook.xml for hooks
liferay-portlet.xml for portlets
liferay-look-and-feel.xml for themes
liferay-layout-templates.xml for layouts
For hook and portlet combination you won't need to modify the build.xml file and just build as you normally do.
Even for theme and layout combination you won't need to modify the build.xml.
But for theme and portlet combination you would need to include theme specific stuff in your build.xml.
Since the deployer looks for the specific files in the project it would know what all things you are deploying and would register them accordingly.
Let me know if this works for you or if you face any issues.
Disclaimer: I have not tried the 6th point but it should work
Generally one would add all portlets in one war so that they can access the service without any problems and to save context reloading time.
However Themes with portlets might not be a good idea always since we change theme.. and thus while updating portlets reloading in unnecessary. Well that's once in months but still a statement to keep portlets away from themes war.

I would like to get some suggestion regarding multiple ejb-jars in one ear

I would like to get some advise. I have an application which consist of modules. A module is sliced to 3 parts, so every module has:
- libraries (shared jars, DTOs, beans)
- swing stuffs
- ejb stuffs
The whole is packaged in one ear file and it may contains many ejb jars, currently 3. To handle separated the ejb jars of the particular modules of my application is, I think, the easiest way to manage the whole. Later I would like to use OSGi to handle the modules. But, this is the future.
Every ejb jar has own persistence.xml and it works. I can deploy it, the hibernate creates the tables and I can use my application. But I have that feeling this is not the best or proper solution to handle this "multiple ejb jars in one ear" situation. I would like to know what is the best or proper solution or what is your suggestion.
Thanks in advance!
The way you do it is actually the best OO-solution: you seperate your concerns.
Moreover you also have more flexibility in the current situation: you can leave out or change one of the ejb jar files and your application will still deploy and keep working.

Design Web application

I want to build a java web application and I don't have any background how to do that.
Can you plz tell me what is the starting point to do that and where can I found useful open source codes that I can use them to design my web application.
There are many different frameworks and without more information it's difficult to know what would suit you.
http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#Java is a good starting point.
You have to know concepts such as Servlet, Servlet Container, Application Server(such as Apache tomcat) and little information about Html.
Exist several book for this goal, my opinion is : you start by a book related to Jsp/Servlet concept, these books good explained.
Here you can learn how java web applications work and here is a very basic java web application example to get you started. I hope this helps :)
You should follow the Java EE tutorial, its Web Tier part. I think it's the fastest way to get knowledge that would allow you to understand the base concepts...
The minimal structure of a web application is the following:
/WEB-INF
/classes - stores the compiled Java classes your webapp uses
/lib - contains the additional libraries your webapp may need to run
web.xml - key file in every webapp; explained below
web files and folders (HTML/JSP/CSS/Javascript)
You may want to start out with Eclipse for Java-EE, since it automatically creates the webapp structure for you, so it's the perfect place to start learning, in my opinion; you can find it here.
After you install, the basic steps to create your web application are:
Create your project by accessing File > New > Dynamic Web Project.
Name your project, click Next, Next and check the Generate deployment descriptor checkbox. Now hit Finish.
Now that the structure is created, your main points of interest will be:
Deployment Descriptor - Is an overview of your web.xml file. Here you can declare all your servlets and their URL paths, you can point to specific error pages triggered by specific codes (e.g 404, 500) or exceptions that occur in your Java/JSP code (e.g NullPointerException, FileNotFoundException), plus do many other things to enhance your webapp. You can trigger between text and graphical XML editing in the bottom-left of the code window.
Java Resources - Here you define your Java classes and servlets. The main role of a Java class in a webapp will be to collect and process data. For example you can define your own math class that exposes methods which do basic calculations. A servlet will usually call one of these classes and output the result to the response output stream. Be sure to provide a solid project structure with the help of packages.
WebContent - this will contain all the web pages your webapp will show, including scripts, images and stylesheets. You are free to create your own folder structure in this section.
Some useful tutorials to get you started:
HTML
JSP
Servlets, Server setup
CSS
Once you're done with your webapp, you can either Run it on a server directly from Eclipse, or you can export it as a WAR file and deploy it on the server of choice, which is usually done by copying the WAR file in the webapps folder.
Finally, try to experiment with all the webapp features Eclipse exposes to you. Good luck!

Splitting Large GWT app into several modules

I have an app written with GWT and GAE where every supported city has its own app. Clearly this is not the best way to manage the map so I want to merge them all into one app. Currently my app is at the urls sub1.myapp.com, sub2.myapp.com, sub3.myapp.com, etc, and I want them to be at myapp.com/sub1 ,myapp.com/sub2, etc. All the supported cities share common code, so I'm going to put all the that code in one module, and have a different module for each piece of unique code block. Is this going about it the right way? How will the different modules interact?
Also, I currently have JSPs at sub1.myapp.com/listofsomesort and I would like to move these to myapp.com/sub1/listofsomesort. Is there a simple way to accomplish this?
By making a module with EntryPoint for each old application, in one and the same application. Each module has one 'welcome page' which you can put in different directories. All the shared code can go into another module. The shared code can be used by the inherit setting in other modules.
The only thing I bumped into was that when you deploy to GAE, ALL modules should have an entry point, also the library modules. I solved it by adding a dummy EntryPoint to them, that does nothing, but still searching for a better solution. See my question at How to deploy GWT Project containing GWT modules without entry points with Eclipse GAE plugin?.
This seems like the job for Code Splitting :) It might require some changes in the structure of your code, though - depends how tightly coupled your classes are. A compile report should tell you if your code splits up nicely, or if not, where the connections are.

Categories

Resources