Se afișează postările cu eticheta spring. Afișați toate postările
Se afișează postările cu eticheta spring. Afișați toate postările

luni, 8 aprilie 2013

JSF - Upload Image in Primefaces CKEditor

         JSF 2.0 is a framework interesting enough to get your attention; combined with a component library like Primefaces it really makes it worth. In addition to the 100+ rich set of JSF components from Primefaces you could also add the PrimeFaces Extensions. Having all these on hand, I noticed that the CKEditor that is integrated in Primefaces Extension doesn't have built-in support for uploading/rendering images.

Let's get rollin' on uploading/rendering an image in CKEditor using:
  • Primefaces Extension for CKEditor component
  • HttpServlet for CKEditorUploadServlet and for CKEditorGetImageServlet
  • JS for CKEditor configuration
  • Spring @Service for saving or getting images from db
1. Declare primefaces dependencies in your pom.xml

2. Add the editor.xhtml to your project

3.Include the editor.xhtml to any page - where it's needed


4. Configure the filebrowserImageUploadUrl from CKEditor, so it knows what servlet to use when the upload button is clicked. I saved the file in /resources/js/ as ckeditor.js.
5. Implement and declare CKEditorUploadServlet - this servlet will be responsible for uploading the images to db

5.1 Declare it in web.xml file 5.2 Implementation of CKEditorUploadServlet
6. Implement and declare CKEditorGetImageServlet - this servlet will be responsible for getting the images from db

6.1 Declare it in web.xml file 6.2 Implementation of CKEditorGetImageServlet
7. Here is the proof

Pages: 1 2 3 4

vineri, 22 martie 2013

Adding PMI (PerformanceMonitorInterceptor) to your application in 3 easy steps

Yesterday I found out that Spring cares about showing how fast it is, but not only that, it does make it easy for you, and without further ado let's get to business.

1. Declare the interceptor (PerformanceMonitorInterceptor) and its pointcut (declaring a pointcut) within the aspect configuration:

Save the below configuration into a config file (aop-config.xml).

2. Include the aop-config.xml file in the spring general configuration file: 
3. And enable logging for:

log4j.logger.org.springframework.aop.interceptor.PerformanceMonitorInterceptor=TRACE

The logging has to be to TRACE in order for you to see the following:

Line 22734: 178062 ["http-bio-8079"-exec-2] TRACE org.springframework.aop.interceptor.PerformanceMonitorInterceptor  - StopWatch ' com.mypackage.service.ApplicationParametersService.getApplicationParam': running time (millis) = 12

Line 23155: 178551 ["http-bio-8079"-exec-2] TRACE org.springframework.aop.interceptor.PerformanceMonitorInterceptor  - StopWatch 'com.mypackage.service.common.PaginatedTableService.getData': running time (millis) = 467