Thursday, October 26, 2017

How to transform Play project as Eclipse project

To transform a new Play project into Eclipse workspace.
the following steps can be followed.

1. navigate into the play project root directory. eg. C:\my-play-project

2. add the following plugin into the end of project/plugins.sbt

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.2")



3. add the following configuration into the end of build.sbt

EclipseKeys.preTasks := Seq(compile in Compile, compile in Test)
EclipseKeys.projectFlavor := EclipseProjectFlavor.Java  
EclipseKeys.createSrc := EclipseCreateSrc.ValueSet(EclipseCreateSrc.ManagedClasses, EclipseCreateSrc.ManagedResources) 


Wednesday, October 25, 2017

How to create new Play Java project

1. make sure sbt is installed in your OS
2. create a new folder, eg. "my-play-project"
3. open command prompt, and navigate to the newly create folder
4. in the command prompt, type "sbt new playframework/play-java-seed.g8"
  a) enter project name
  b) enter organization
  c) enter scala version
  d) enter play version
  e) enter sbt version

Wednesday, October 18, 2017

How to easily get logged in user in Liferay.



ServiceContextThreadLocal.getServiceContext().getUserId();


reference:
http://liferay-hacks.blogspot.my/2014/01/get-current-logged-in-user-easily-in.html

Sunday, September 24, 2017

How to delay Quartz Scheduler startup in a web application

Quartz scheduler startup can be delayed by configuration in web.xml or programmatically.

1. Configuration in web.xml
<context-param>
<param-name>quartz:start-delay-seconds</param-name>
<param-value>DELAY_IN_SECONDS</param-value>
</context-param>

2. Programmatically
    scheduler.startDelayed(DELAY_IN_SECONDS);


Done!!

Saturday, September 23, 2017

How to create angular 4 module

This tutorial assuming all prerequisite to start an Angular 4 application has been properly setup with Angular cli.

To create angular 4 module, follow the steps below.
1. navigate to the root directory of your Angular 4 application.

2. run the following command to generate a new module class
    ng generate module moduleName

    eg. ng generate module ferrari
3. run the following command to generate a new component under the above module
    ng generate component moduleName/componentName

    eg. ng generate component ferrari/ferrari-list
4. create a routing class in the same directory with module class  

    eg. ferrari-routing.module.ts



Wednesday, August 16, 2017

Quick access to httpSession in Liferay

The following syntax can access to Http Session Object in Liferay without going through PortletSession Object.

Setting session object

PortalSessionThreadLocal.getHttpSession().setAttribute("sessionAttributeName", value); 



Retrieving session object by key 

PortalSessionThreadLocal.getHttpSession().getAttribute("sessionAttributeName");




Done!!

Monday, August 7, 2017

How to disable Chrome autofill with jQuery

To disable the Google Chrome autofill,
the solution is to set the autocomplete in the input element to off.
with the following jQuery function, all the input element in the page will be set autocomplete to off.

$(document).ready(function(){ 
    $("input").each(function () {
         $(this).attr("autocomplete", "off");
       })
})



Done!!

Wednesday, July 5, 2017

How to disable browser back behavior with javascript

in certain scenario, we might want to disable the browser back behavior.
eg,
in an ajax application, the application screens changed, but the browser url remains unchanged.
if the user click on the browser back button now
the application is navigate away from what the user doing,
where the user simply wants to navigate to the previous screen.
thus, disable the browser back behavior is very important here.

Saturday, June 24, 2017

How to pass date type parameter in a restful service

In certain use case, we might need to pass date type parameter from service consumer to service provider.
But date as a object is not allowed to transfer via http.

The are only 2 additional steps to resolve this problem
1. at consumer side, convert the date object to long value
2. at provider side, convert the long value back to date object.

in Javascript / Play / SpringBoot consumer, convert the date object to long value

new Date().getTime();



in Play / SpringBoot provider, convert the long date value to date object.

new Date( dateValueInLong );




Done!!



Friday, June 23, 2017

Saving and Updating a document with json in MongoDB

In MongoDB, we can use the same save(DBObject document) to save or update a json into MongoDB.


String jsonString = "{'Page':1,'Fruits':['apple','peach','pear']}";  // some json string
DBObject dbObject = (DBObject)JSON.parse(jsonString);

MongoClient mongo = new MongoClient( Arrays.asList(new ServerAddress("localhost", 27017)) );
DB db = mongo.getDB("myDB");
DBCollection collection = db.getCollection("myCollection");
collection.save(dbObject);



the save(DBObject document) will identify if this is new document,
it will perform insert
otherwise it will perform update.


Done!!

Thursday, June 22, 2017

Quick Start Angular 2 module in Liferay

Platform:
Angular 2
Liferay 6.x, Liferay 7

Steps
1. download the sample project done by devsoftcz from github

2. extract the sample project, and change the project folder name.

3. open bnd.bnd, change the Bundle-SymbolicName to desired name

4. open package.json, change the "name" and "description" in the top part.

Monday, May 22, 2017

How to add ui-bootstrap in AngularJS Portlet

Platform:
Liferay 6.x, 7.x
AngularJS 1.6.x

To addui-boostrap into AngularJS, we will reuse the AngularJS portlet created earlier with ui-router.

Steps to add ui-bootrap are pretty simple, we just need to import ui-bootstrap-tpls-2.5.0.min.js in view.jsp

<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.min.js" />



and also bootstrap.min.css

<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>


Lastly, we can start using bootstrap components by referring the bootstrap demo page.


Done!!

Tuesday, May 16, 2017

How to use ui-router in AngularJS Portlet

Platform:
- Liferay 6.x, Liferay 7.0
- AngularJS 1.6.x

In this example, we will also continue from the first angularJS portlet created in earlier post.
the differences with the ngRoute example are main.jsp

Steps
1. create 2 new jsp for the ui-routing example in the same folder with view.jsp
- page1.jsp, with the following content

<h2>This is the page 1.</h2>


- page2.jsp, with the following content

<h2>This is the page 2.</h2> 


Thursday, May 11, 2017

How to use ngRoute in AngularJS Portlet

Platform:
- Liferay 6.x, Liferay 7.0
- AngularJS 1.6.x

In this example, we will continue from the angularJS portlet created in earlier post.
1. create 2 new jsp for the routing example in the same folder with view.jsp
- first.jsp, with the following content.

<h2>This is the first page.</h2>


- second.jsp, with the following content

<h2>This is the second page.</h2>



Saturday, May 6, 2017

How to create AngularJS portlet in Liferay

Platform:
- Liferay 6.x, 7.0
- AngularJS 1.6.x

Hello World in Liferay Angular Portlet
1. create liferay plugin with liferay mvc portlet tempalte
File > New > Other > Liferay > Liferay Plugin Project > Next
    Fill in "Project name" > Finish.

Friday, May 5, 2017

How to create slanted PREVIEW div

the code below is to create a slanted Preview like the image below.


<div
    style="position: absolute; top: 75px; left: -225px; width: 600px; height: 28px; margin: 0px; padding: 10px; font-size: 24px; text-align: center; color: rgb(255, 255, 255); font-family: &quot;trebuchet ms&quot;,verdana,arial,sans-serif; transform: rotate(-45deg); transform-origin: 50% 0px 0px; border: 1px solid transparent; z-index: 1200; background-color: rgb(0, 0, 0);" >
    Preview
</div>


Done!!

Thursday, April 20, 2017

How to query with Pattern / Case insensitive in mongoDB

 This following example is showing how to query the mongoDB with LIKE


BasicDBObject criteria = new BasicDBObject();
List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
if(firstName != null && firstName.length() > 0) {

//            search the firstName field with case sensitive LIKE operator  
    obj.add(new BasicDBObject("firstName", Pattern.compile(firstName));
}
if(lastName != null && lastName.length() > 0) {

//            search the lastName field with case insensitive LIKE operator
    obj.add(new BasicDBObject("lastName", 
        java.util.regex.Pattern.compile(lastName, Pattern.CASE_INSENSITIVE)));
}        
if(obj != null && obj.size() > 0) {
    criteria.put("$and", obj);            
}




Done!!

Tuesday, April 18, 2017

How to run Liferay blade in windows 10

1. download blade.jar from Liferay.

2. open the command prompt, and navigate to the downloaded blade.jar directory.

3. type the following command in the command prompt

java -cp blade.jar com.liferay.blade.cli.blade create -d path/of/the/liferay/module portlet




Done!!

Wednesday, April 12, 2017

How to get HTML element from PrimeFaces

In some scenarios, we might want to get the HTML element of a PrimeFaces component and process in javascript.
Assume we have a PrimeFaces inputText component like below.


<p:inputText id="address" value="#{myBean.address}" widgetVar="addrWV" />



1. widgetVar

addrWV.jq.get(0);



2. #{p:component('compId')}

document.getElementById('#{p:component(&quot;address&quot;)}');




Done!!

Wednesday, March 29, 2017

How to convert DBCursor to JsonNode in Play

The code below only applicable when using mongoDB and Play framework together.


com.mongodb.util.JSON json =new JSON();
String serializedCursor = json.serialize(cursor);

com.fasterxml.jackson.databind.JsonNode jsonData = play.libs.Json.parse(serializedCursor);




Done!!

Monday, March 20, 2017

New line in Oracle Report

to pass a new line as a parameter from java to Oracle report,
we need the follow syxtax instead of "\n".

system.line_separator


Done!!

Sunday, March 19, 2017

How to configure Liferay Language portlet as Select Box

 Image above shown the default Liferay Language portlet.

to change the default display option, please follow the steps below.
1. Login to Liferay as Administrator

2. navigate to the portlet setting to open the Language configuration.

Friday, March 17, 2017

How to post json to Liferay OSGI restful service


To post a json to a Liferay OSGI restful service,
the service method itself must be able to accept String as the input parameter.
the service method is then parse the json string to a json object
follow by the required function process
and lastly return the response to the service consumer


@POST
@Path("/addPerson")
@Consumes(MediaType.APPLICATION_JSON) 
@Produces(MediaType.APPLICATION_JSON)
public Response addPerson(final String personJsonString) {

    ObjectMapper mapper = new ObjectMapper();
    JsonNode personJson = mapper.readTree(personJsonString);

    /**
     * Process person json 
     * 
     */
    
    return Response.status(Response.Status.OK).build();
}



Done!!

Wednesday, February 22, 2017

How to setup Eclipse for Play framework

1. open <play-project-home>\project\plugins.sbt (c:\play-java\project\plugins.sbt)
    add the following line.


addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")


2. Open <play-project-home>\build.sbt
    add the following lines

EclipseKeys.preTasks := Seq(compile in Compile)

EclipseKeys.projectFlavor := EclipseProjectFlavor.Java

EclipseKeys.createSrc := EclipseCreateSrc.ValueSet(EclipseCreateSrc.ManagedClasses, EclipseCreateSrc.ManagedResources) 


3. restart the play sbt console, so that sbt performs update for the new plugins.

4. in sbt console, type "eclipse"

5. import the new project into eclipse workspace
    File > Import > Existing Projects into Workspace > Next > Select root directory > browse <play-project-home>, Finish.

source: https://www.playframework.com/documentation/2.5.x/IDE



Done!!

Thursday, January 12, 2017

Tuesday, January 10, 2017

How to export Database connections from Oracle SQL Developer to XML

This article shows how to export the configured database connections in Oracle SQL Developer so that it is easily share the connections with other team members. 

1. R-click on Connections root, a small context menu appears.

2. click on "Export Connections".

LinkWithin

Related Posts Plugin for WordPress, Blogger...