Search This Blog

Tuesday 17 December 2013

Creating & Using a language.properties for your custom portlet





STEP:1 Create a Package named-'content' under the.. '/docroot/WEB-INF/src'
Note: Create a Package and not a folder. [i did that mistake for the first time ;-)]

STEP:2 now create a file named - '/content/language.properties' under the content folder created above..

STEP:3 now to recognize this file @ portlet-level you need to make an entry in the 'portlet.xml' file present under the -'/docroot/WEB-INF/portlet.xml'
Add the properties file entry in this file using the resource-bundle tag as following :-
--------------------------------------------------------------------
<resource-bundle>content.language</resource-bundle>

--------------------------------------------------------------------

Note: add this Tag @ following location for each portlet (that intends to use this language.properties file) in the portlet.xml:-
--------------------------------------------------------------------
<portlet>
    <portlet-name>portfolio</portlet-name>
    ...
   <resource-bundle>content.language</resource-bundle>
    <portlet-info>...</portlet-info>
    ...
</portlet>
--------------------------------------------------------------------
Note: Also , the correct entry format is : <resource-bundle>content.language</resource-bundle>
often mistaken with --
<resource-bundle>language</resource-bundle>  OR
<resource-bundle>language.properties</resource-bundle>  OR
<resource-bundle>content.language.properties</resource-bundle>

To populate a jQuery-DataTable by passing JSON Response(JSonArray) as parameter.

Recently, i came across a Reqirement where i need to populate datatable(i used jQuery-DataTable) by passing JSON array as input parameter.
For example , i had a JSON ajax call which returns me a JSON array data,i would like to populate datatable with this JSON array,
 i know i can do AJAX call from datatable itself, but i would like to explore this option of getting data first 
and then building table using this data..

[download link -- http://datatables.net/download/]
use the following link to download the all the required JS libs/files (probably you will get a complete JQuery Datatable project ..
and you need to extract the following files from the /js folder in there..)
- dataTables.js
- dataTables.min.js
Alongwith these you will be needing -
- jquery.js
- jquery-1.10.2.min.js    as well(download and include ,incase you haven't uptill now..)

Ok, so here the input Text in my 'jsp' which will invoke the ajax-call onKeyUp -
<input id="organizationName" name="organizationName" onkeyup="doSearchAjaxCall();" type="text" value="" />

here's the JavaScript function which is responsible for making the ajax call.....
----------------------------------------------------------------------------------------------
Also, before jumping to script keep note of the Portlet-URL(required for the ajax call) ,
i created a resourceURL (given below) which will hit the serveResource in my PortletClass ..(you may create as per your requirement)
-- -- -- -- -- -- -- -- -- -- -- -- -- --
<portlet:resourceURL var="searchRequestURL">
</portlet:resourceURL>
-- -- -- -- -- -- -- -- -- -- -- -- -- --
<script>
function doSearchAjaxCall() {
 // fetching various field params from the jsp..
var acbno = jQuery("#acbno").val();    
var orgName = jQuery("#organizationName").val();
var field = jQuery("#field").val();          

//dataType:'json',
Note: mentioning dataType in the ajax-call is note required ...only 'setContentType("application/json")' is enough [set in portlet class --see complete code below]
jQuery.ajax({
type: "POST",
url: "<%= searchRequestURL.toString() %>",
data:"acbno="+acbno+"&orgName="+orgName+"&field="+field,
error: function(data) {
alert(" inside error >>> "+data);
},
success: function(data) {
//var stringResponse = JSON.stringify(data);
Note: Dont make the Mistake of converting the data-array into string before passing into datatable - as it requires data-array in json form only..
//alert("data stringify = >>>> "+stringResponse);
// console.log("success data>>  "+data);
// pass the data-array obtained in success-fn to another js fn created -'loadDataTable()' which will futher //populate the Datatable..
loadDataTable(data);          // custom -function Call

}
});
 }

  function loadDataTable(data){

  // console.log("loadDataTable >>  "+data);
   $("#tableId1").dataTable().fnDestroy();
var oTable = $('#tableId1').dataTable({
"aaData" : data,
"aoColumns" : [
{"sTitle" : "SammNo" },
{ "sTitle" : "OrganizationName" },
{ "sTitle" : "Field" },
{"sTitle" : "Scope" }
]
});
}
// Also, you may add the ajax call on jQuery ready as well here...see explanation below >>>
</script>

Note: aaData - 
Note: aoColumns -
Note :    $("#tableId1").dataTable().fnDestroy();   ---bcz Datatables cannot be reinitialised hence, need to destroy the existing datatable before poputaing again for consecutive ajax call for same datatable..

----------------------------------------------------------------------------------------------
 Also, you may add the ajax call on jQuery ready as well Incase you want the datatable to be populated on page load as well...
 bcz above code will populate the datatable as & when the 'onkeyup()' function is called for the input-text -'organizationName'.
 ----------------------------------------------------------------------------------------------------
jQuery().ready(function(){

var acbno = jQuery("#acbno").val();
var orgName = jQuery("#organizationName").val();
var field = jQuery("#field").val();

    jQuery.ajax({
type: "POST",
url: "<%= searchRequestURL.toString() %>",
data:"acbno="+acbno+"&orgName="+orgName+"&field="+field,
error: function(data) {
alert(" inside error >>> "+data);

},
success: function(data) {

//console.log(" jQuery-ready >> success data>>  "+data);

loadDataTable(data);

}
});
});
------------------------------------------------------------------------------------------------------------


NOTE : STRICTLY AVOID USING 'console.log();' - This gives an error saying 'console is unDefined' in most of the IE version browsers. This error often breaks the complete JavaScript used ..In my case i wasn't able to display jQuery DataTables in IE whereas it was working  F9 in FF && Chrome..!!!
Though could use the same for debugging purpose OR incase the target browser for your application duznt includes IE (which is often not the case ) ;-)






Dynamically Creating a URL for a DLFileEntry or a File stored in Document & Media

Recently, i came across a requirement where i need to provide a view link to the various files stored in Liferay Document & Media.ie on click of these links the File(.pdf stored in our case) needs to open in a new Tab in Browser.
Hence, a url is required for that file :
I came to know that the complete URL formed is composed of the following components:
host+documents+groupId+folderId+fileTitle
where,
host - you can obtain as following- 'PortalUtil.getPortalURL(portletRequest)'
-will return something like this (http://localhost:8080/) incase of local machine..
documents - you can hardcode as this is hardly going to change in the D&M path..
groupId - you better fetch from the dlFileEntry Obj as - 'dlFileEntry.getGroupId()'
folderId - you better fetch from the dlFileEntry Obj as - 'dlFileEntry.getFolderId()'
fileTitle - you better fetch from the dlFileEntry Obj as - 'dlFileEntry.getTitle()'
- Note: Don't fetch 'dlFileEntry.getName()' instead of 'dlFileEntry.getTitle()'

Hence,
The complete url will look something like this:
 'http://localhost:8080/documents/10179/0/Flipkart-Induct-meet'

Here's how i formed this URl in my PortletClass:
------------------------------------------------------------------------------------------------------------
final String filePath_fromDM = "documents/"+dlFileEntry.getGroupId()+"/"+dlFileEntry.getFolderId()+"/"+dlFileEntry.getTitle();
System.out.println(">>>>>>  filePath_fromDM >>> = "+filePath_fromDM);
-will return something like this (documents/10179/0/Flipkart-Induct-meet) incase of local machine..

String completeFilePathUrl = StringPool.BLANK;
completeFilePathUrl = PortalUtil.getPortalURL(resourceRequest)+"/"+filePath_fromDM;
System.out.println(" >>> completeFilePathUrl () = "+completeFilePathUrl );
-will return something like this (http://localhost:8080/documents/10179/0/Flipkart-Induct-meet) incase of local machine..
------------------------------------------------------------------------------------------------------------

And, finally here how i formed a Link for this URL on click of which it will open the doc in a New-Tab..
String linkFormed = "<a href='"+scopeUrl+"' target='_blank'>View</a>" ;
Note: target="_Blank" is required only if you want to open the link in a new Browser Tab.
which you can pass in a response , use in a jsp , etc as per your requirement..


Tuesday 10 December 2013

Custom queries in Liferay

Sometimes it is needed to perform joined queries with the Service Builder. It is not possible to do it with dynamic queries - custom queries are necessary.
This article explains how to create custom queries , i faced lot of issues when working on the same for the first time, unware for various minor concepts which were hard to be found at one-place . Thus ,decided to document my understanding of the same along withe the issues faced during implementation alongwith their fixes. Plz don't ignore the various -'Note' throughout the blog.


STEP:1 First of all create a folder with the name - "custom-sql"  under the src folder...
Note: create a folder & NOT a package .(see image below.)



STEP:2 Now create a file- "default.xml" in this custom-sql folder...(Though you can write your sql-querries over here as well , but its always a good practice to write your qurries in
a diff .xml file & map that file int this default.xml)
Add something like this to your default.xml:
---------------------------------------------------------------------------------
 <?xml version="1.0"?>
<custom-sql>
    <sql file="/custom-sql/myProject-portal.xml" />
</custom-sql>
---------------------------------------------------------------------------------

STEP:3 Now open your 'myProject-portal.xml' , and put  all you querries here as below... each identified by a id.
Something like this :
---------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<custom-sql>
 
    <sql id="">
        <![CDATA[
Select * from user_ where firstName ="Test"
        ]]>
    </sql>
</custom-sql>

---------------------------------------------------------------------------------
STEP:4 Add the following in ur portal-ext.properties

custom.sql.configs=\
custom-sql/default.xml, \
custom-sql/default-ext.xml

---------------------------------------------------------------------------------

Step:5 Create a FinderImpl class bearing your Entity name that must extends BasePersistenceImpl.
public class CABDisplayFinderImpl extends BasePersistenceImpl<CABDisplay>{ }

Step:6 Now run the 'build-service' task.You will observe that the service-builder has generated two more files for you in '../service/persistence' under the 'docroot/WEB-INF'-namely
-CABDisplayFinder AND
-CABDisplayFinderUtil
  Now go back to your FinderImpl class and add 'implements 'CABDisplayFinder' as below and run the Build-Service task again..
---------------------------------------------------------------------------------
  public class CABDisplayFinderImpl extends BasePersistenceImpl<CABDisplay> implements CABDisplayFinder{

}
---------------------------------------------------------------------------------
Note:
Do Keep Note of these two configuration related points -
[1] Next ,you need to create a finderImpl under the "service/persistence" under the "/docroot/WEB-INF/src" && Not in 'service/persistence' under "/docroot/WEB-INF"
[2] Also , the FinderImpl must start with the name of any defined Entity in your service.xml (say - for entity-'ABC' it would be 'ABCFinderImpl' & not 'MyABCFinderImpl',etc)
This is very imp to mention as i wasted a reasonably good amount of time breaking my head on this issue, being unaware of this concept that your FinderImpl class must bear & start with the name of a defined Entity.
I did the Mistake of creating a FinderImpl with the name 'ABCDisplayFinderImpl' for an entity -'ABCDisplay_Metadata' , whereas it should be 'ABCDisplay_MetadataFinderImpl' which solved the Issue.




Monday 9 December 2013

How to expose Liferay Service as a Soap Web Service

Having spend myself a reasonably good amount of time in various issues ,hereby , i have shared my understanding of -'How to expose Liferay Service as a Soap Web Service'

I used Liferay6.1.1 source and Plugin-SDK(liferay-plugins-sdk-6.1.1-xx) along with eclipse juno The base platform was Java1.7.x and MySQL5.1..x.
The deployment server was Liferay-bundled-JBoss GA3. (liferay-portal-jboss-6.1.30-ee-ga3-xx)

Assuming that you are already thru the following steps mentioned below :
Step 1: Setup liferay source project and tomcat/JBoss/etc
Step 2: Setup plugin SDK.
Step 3: Create the service project (say i gave the project-name as 'cab_portletname')
Step:4 Create a new liferay-service builder file (service.xml)

Now, you can expose the liferay-service to any of the available Entities (Entities you mentioned in the service.xml).
Lets say you created an entity named- 'CABDisplay' && namespace as -'CAB' as below:-
---------------------------------------------------------------------------
<namespace>CAB</namespace>
<entity name="CABDisplay" local-service="true"
remote-service="true">

<!-- Primary Key -->
<column name="SammNo" type="long" primary="true" />
<!-- Audit fields -->
<column name="OrganizationName" type="String" />
<column name="Field" type="String" />
</entity>
---------------------------------------------------------------------------
Step:5 Save this service.xml && run the 'CABDisplay-Portlet/build-service' task.(say 'ant clean build-service' from command-prompt ,etc)
If the build fails, please check if your service.xml for any syntax-error (also, check the console & act accordingly). On successful build, the ant task creates the files related to CABDisplay entity.
You can now refresh your project (F5) to see the generated files.

Step:6 Incase you wanna expose any of the default liferay-services generated for you entity(you can check the same in the your serviceImpl -say 'CABDisplayServiceImpl' in our case)
Now Add the CRUD and finder methods into your com.liferay.test.service.impl.CABDisplayServiceImpl as listed below:
---------------------------------------------------------------------------------------
public CABDisplay fetchMetadataBySammNo(long sammno){

return cabDisplayLocalService.fetchCABDisplay(sammno);
}
---------------------------------------------------------------------------------------
public CABDisplay createCabDisplay(long sammno){

return cabDisplayLocalService.createCABDisplay(SammNo);
}
---------------------------------------------------------------------------------------

Step:7 Now you need to run the 'CABDisplay-Portlet/build-wsdd' task to generate the webservices..(say 'ant build-wsdd' from command-prompt ,etc)
Now you can simply deploy the portlet

Step:8 Now, type the following composed url in the browser && check the respective web-services exposed along with thier wsdl - "http://host/portletname-portlet/api/axis"

In our case the url will be  - " http://localhost:8080/cab_portletname-portlet/api/axis " ,which will show you all the services exposed for this respective Portlet..

where, you can check the value of 'cab_portletname-portlet' from the following locations in case of JBoss App Server "jboss-7.1.1\standalone\deployments\" &&
 "tomcat-7.x.x\webapps\" folder in case of TOMCAT App Server.

Step:9 hence, you have successfully exposed your custom liferay-services avaliable as a web service. Now in case you wanna consuming the same-- you can simply build a client using the above wsdl and consume the same...!!! ;-)

Monday 25 November 2013

How to check the INTERNET & GPS connection in Android


----------------------------------------------------------------------------------------------------
ConnectivityManager only give information of the connection (WiFi, mobile, WiMax, etc) and if it is connected or not.

public boolean isGPSEnabled(){

LocationManager lm;
boolean GPS_Status =false;
boolean gps_enabled = false;
String title,message="";
try{
lm = (LocationManager)this.getSystemService(LOCATION_SERVICE);
gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
}catch(Exception e){
e.printStackTrace();
}

if(gps_enabled){
GPS_Status = true;
title="GPS ENABLED";
message ="GPS is  enabled.";
GPSChecker.showAlertDialog(this, title, message);
}else{
title="GPS Disabled";
message ="GPS is not enabled.Please TurnOn the GPS";
GPSChecker.showAlertDialog(this, title, message);
}
return GPS_Status;
}

----------------------------------------------------------------------------------------------------


/*
* This method does check-  ARE WE CONNECTED TO THE NET
*/
public final boolean isInternetOn()
{
String title,message="";
boolean connected = false;
ConnectivityManager connec = (ConnectivityManager)
   getSystemService(Context.CONNECTIVITY_SERVICE);

 if (connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||
 connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED ){

 // MESSAGE TO SCREEN FOR TESTING (IF REQ)
 title="Internet ENABLED";
 message ="Internet is  enabled.";
 GPSChecker.showAlertDialog(this, title, message);
 connected = true;

 }else if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED
 ||  connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED  ){

 connected =  false;
 title="Internet DISABLED";
 message ="Internet is  disabled.";
 GPSChecker.showAlertDialog(this, title, message);
 }
 return connected;
}


----------------------------------------------------------------------------------------------------

Tuesday 19 November 2013

Configuring Liferay 6.1 CE GA3 on JBoss-7.1.1 -ee-ga3

Incase you are going to setup -" liferay-portal-jboss-6.1.30-ee-ga3" , probably this blog can be of some help..as hereby i put aal my findings & steps i followed to successfully configure the same..



Few of the LINKS Followed ::


1>> Starting Server :
 Start the extracted server >> now goto  the following path -”D:\PROJECTS\Scali\liferay-JBOSS_HOME-ga3\jboss-7.1.1\bin” and double click the standalone.bat [for Windows] or you can start the same .bat file from cmd as well by going to the respective path .It will start the Server @ localhost:8080 by default.
If Its Not Started --check for the respective Error @console.
Note: Check your jdk version .Incase you are using Jboss 7.x.x its advised to use jdk7 and like wise.


2>>Incase of EE :
now you can see the deploy folder @ following path - “D:\myWorkspace\liferay-JBOSS_HOME-ga3\”  ,wch wasnt thr untill you’ll start the server atleast once. Since using an EE , need to attach a  license key [wch you can register @ liferay.com and get your trial/etc license key] , now Paste your Licence- xml file here---it will be auto deployed.Refresh the portal (default localhost:8080) --you’ll see the Basic Config page. Config ur Database here and proceed.


3>> Configuring MYSQL:
Incase you wanna configure -’MySQL’ …. copy the “mysql-connector-java-3.0.9.jar” @ following location of ur Jboss_Home-
D:\PROJECTS\Scali\liferay-JBOSS_HOME-ga3\jboss-7.1.1\modules\com\liferay\portal\main
also you need to update the module.xml present @ same loc --communicating to jboss tht u’re interested in using this resource [mysql jar ]. RESTART your Server now..


Issues Faced :
  • 08:56:20,986 INFO  [stdout] (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1) 08:56:20,982 WARN  [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolTh
read-#1][BasicResourcePool:1841] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@285dec -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying
to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (3). Last acquisition attempt exception:
08:56:21,015 INFO  [stdout] (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1) java.sql.SQLException: Unable to connect to any hosts due to exception: java
.lang.ArrayIndexOutOfBoundsException: 40
i was using mysql jar -- ’mysql-connector-java-3.0.9.jar’ ...later used a higher version jar as this one was to Old ..so i used mysql-connector-java-3.0.17-ga-bin.jar  [Advised to use any jar of versdion >=3.0.15 ]


Issues Faced :   Another Mistake i did while Configuring mysql was to replace the hsql.jar entry with the mysql-connector-java..jar  in the module.xml.  Dont Do that as the hsql.jar is still required while deploying the ROOT.war portlet (default portlet). See below extract from module.xml for better understanding..



Don’t replace the resource-root entry of - hsql.jar with that of ‘mysql-connector-java.x.x.jar ...Instead Add a new resource-root entry ….
<resources>
<resource-root path="mysql-connector-java-3.0.17-ga-bin.jar" />      [NEW ENTRY]
      <resource-root path="hsql.jar" />
       <resource-root path="jtds.jar" />
       
       <resource-root path="portal-service.jar" />
       <resource-root path="portlet.jar" />
       <resource-root path="postgresql.jar" />
   </resources>


4>> Deploying a Portlet :::
InCase of DIRECT- DEPLOYMENT ::
You can drop your portlet war file directly @ following loc --
“D:\PROJECTS\Scali\liferay_JBoss_Home-ce-ga3\deploy“..If the server is started it’ll Autodeploy.  


[Also to Mention ,Many a blogs advocate creating a blank file along with your war file at this location say: your war file is ABC.war the create a file named ABC.war.dodeploy and drop @
{D:\Workspace\liferay-JBOSS_HOME-ga3\jboss-7.1.1\standalone\deployments} loc ,BUT incase you try … Its will give the following exceptions @ console..


:26:13,888 WARN  [org.jboss.as.ee] (MSC service thread 1-1) JBAS011006: Not installing optional component com.liferay.taglib.ui.AssetCategoriesSummaryTag due to exception : java.lang.ClassNotFoundException: com.liferay.taglib.ui.AssetCategoriesSummaryTag from [Module "deployment.ABC-portlet-6.1.1.1.war:main" from Service Module Loader]
     at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
     at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
     at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
     at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0]
     at java.lang.Class.forName(Class.java:264) [rt.jar:1.7.0]
     at org.jboss.as.server.deployment.reflect.DeploymentClassIndex.classIndex(DeploymentClassIndex.java:54) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
     at org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:79)
     at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
     at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
     at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0]
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0]
     at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0]


:26:13,958 INFO  [org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /ABC-portlet-6.1.1.1
:26:14,025 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "ABC-portlet-6.1.1.1.war"



InCase of ANT- DEPLOYMENT ::
Also, if you try to deploy using ANT (if configured properly) , you may get the same series of exceptions .
To Overcome the same -- add the following to your build.{username}.properties
--------------------------------------------------------------------------------------------------------
#
# Specify the paths to an unzipped JBoss bundle.
#


app.server.type=jboss
app.server.parent.dir=D:/PROJECTS/my_Project_name/liferay_JBoss_Home-ce-ga3
app.server.jboss.dir=${app.server.parent.dir}/jboss-7.1.1
app.server.jboss.deploy.dir=${app.server.parent.dir}/deploy
app.server.jboss.lib.global.dir=${app.server.jboss.dir}/modules/com/liferay/portal/main
app.server.jboss.portal.dir=${app.server.jboss.dir}/standalone/deployments/ROOT.war
javac.compiler = modern


auto.deploy.dir=${app.server.jboss.deploy.dir}
--------------------------------------------------------------------------------------------------------
5>> Configuring Plugins sdk :::  Here's very nice link you can refer for configuring Plugins-Sdk (In case you haven't done it uptill now)
Refer : http://techconf.wordpress.com/2012/12/30/develop-liferay-portlet-plugin-project-without-liferay-ide-support-in-eclipse-on-jboss-server/

Monday 11 November 2013

Erros in building service - Error occurred during initialization of VM , Could not reserve enough space for object heap


#### ERROR --

[Console output redirected to file:D:\MTSTravel\.metadata\.plugins\com.liferay.ide.eclipse.sdk\sdk.log]
Buildfile: D:\xxxxxx\plugins-sdk-6.1.1\portlets\mts-portlet\build.xml
build-service:
     [java] Java Result: 1
     [echo] Error occurred during initialization of VM
     [echo] Could not reserve enough space for object heap
     [echo] Error: Could not create the Java Virtual Machine.
     [echo] Error: A fatal exception has occurred. Program will exit.

BUILD FAILED
D:\xxxxxx\plugins-sdk-6.1.1\build-common-plugin.xml:207: Service Builder generated exceptions.
Total time: 6 seconds




#### SOLUTION --

I faced this ExceptionThis is what resolved the issue for me , thus sharing hereby expecting it could be of some help to you as well...

SDK ,change the file build-common-plugin.xml from
<jvmarg value="-Xms512m" />
<jvmarg value="-Xmx1024m" />
to
<jvmarg value="-Xms128m" />
<jvmarg value="-Xmx512m" />

Wednesday 23 October 2013

Popular Aui:Validators - validating your form with Aui:Validations

Hereby i have Listed the Default-Form Validators provided by AUI ,alongwith a few examples showing their implementation in our Application:

DEFAULT AUI : FORM VALIDATORS :

DEFAULT: Liferay.Language.get(‘please-fix-this-field’),
acceptFiles: Liferay.Language.get(‘please-enter-a-file-with-a-valid-extension-x’),
alpha: Liferay.Language.get(‘please-enter-only-alpha-characters’),
alphanum: Liferay.Language.get(‘please-enter-only-alphanumeric-characters’),
date: Liferay.Language.get(‘please-enter-a-valid-date’),
digits: Liferay.Language.get(‘please-enter-only-digits’),
email: Liferay.Language.get(‘please-enter-a-valid-email-address’),
equalTo: Liferay.Language.get(‘please-enter-the-same-value-again’),
max: Liferay.Language.get(‘please-enter-a-value-less-than-or-equal-to-x’),
maxLength: Liferay.Language.get(‘please-enter-no-more-than-x-characters’),
min: Liferay.Language.get(‘please-enter-a-value-greater-than-or-equal-to-x’),
minLength: Liferay.Language.get(‘please-enter-at-list-x-characters’),
number: Liferay.Language.get(‘please-enter-a-valid-number’),
range: Liferay.Language.get(‘please-enter-a-value-between-x-and-x’),
rangeLength: Liferay.Language.get(‘please-enter-a-value-between-x-and-x-characters-long’),
required: Liferay.Language.get(‘this-field-is-required’),
url: Liferay.Language.get(‘please-enter-a-valid-url’)
---------------------------------------------------------------------------------------------------------------------

Please find the implementation examples of few of the Deafult Aui Validators listed above:

## alpha :
<aui:input name="firstName" label="first-name" id="firstName" maxLength="20" >
<aui:validator name="alpha" errorMessage="please-enter-only-alpha-characters" />
</aui:input>

## digits && rangeLength :

<aui:input name="primaryMobileNo" label="primary-mobile-no"
id="primaryMobileNo" maxLength="15">
      <aui:validator name="digits" errorMessage="please-enter-valid-mobile-number" />
     <aui:validator name="rangeLength"
errorMessage="please-enter-valid-mobile-number">[8,15]</aui:validator>
</aui:input>

## email :
<aui:input name="primaryEmail" label="primary-email" id="primaryEmail">
<aui:validator name="email" errorMessage="please-enter-valid-email" />
</aui:input>

## alphanum :
<aui:input name="crmNumber" label="crm-no" id="customerCRMNo">
<aui:validator name="alphanum"
errorMessage="please-enter-valid-customer-CRMNo" />
</aui:input>

## minLength :
 <aui:validator name="minLength" errorMessage="Phone number format as (xxx) xxx-xxxx" >10</aui:validator>


## maxLength : 
<aui:validator name="maxLength" errorMessage="Phone number format as (xxx) xxx-xxxx">10</aui:validator>



Note: AUI doesn't provide as such any default Validators for Dropdowns , in such a case you need to implement you custom form validations for dropdowns,etc  using AUI or jQuery,etc
reference:  

IMPORT A DUMP INTO MYSQL


IMPORT A DUMP INTO MYSQL

Incase you wanna import a mysql database dump follow the following steps:

Open command-promt in your system (Windows + cmd)...
Now, goto the file location and then run this command

G:\data\>mysql -u root -proot myNewDB< mydump.sql


where,
  • say my file was in G:Drive so G:\data\  & mysql- (username = root & password=root)
  • myNewDB is the DB(newly created/existing) where you wanna import the mysql dump.
  • mydump.sql is name of the mysql-dump file.


--
Plz : Do post your valuable comments in case this doesn't work for you. Thanks In Advance...!!! 

Tuesday 22 October 2013

Creating an Intent In Android , Starting activities Using Intents & Passing/Receiving data through Intent


-----------------------------------------------------------------------------------------------
Starting activities Using Intents :-
To start an activity use the method startActivity(intent). This method is defined on the Context object which Activity extends.
The following code demonstrates how you can start another activity via an intent.

say:   Activity1 (Sender Activity)

Button btn = (Button)findViewById(R.id.goBackBtn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

//write an Intent to redirect to Activity2--
Intent gotoActivity2= new Intent();
gotoActivity2.setComponent(new ComponentName(Activity2_pkg_nameActivity2_class_name));
MainActivity.this.startActivity(gotoActivity2);  //the Current Activity(ie MainActivity) will start the Intent -'gotoActivity2'

      }
});

say:  Activity2 (Sub-Activity/ Target Activity/)
 Activities which are started by other Android activities are called sub-activities. 

public void onClick(View v){
//write an Intent to redirect to Activity1--
  Intent gotoActivity1= new Intent();
  gotoActivity1.setComponent(new ComponentName(Activity1_pkg_nameActivity1_class_name));
  this.startActivity(gotoActivity1);      //the Current Activity will start the Intent -'gotoActivity1'
}
So, as soon as the control comes to this onClick() method the current activity will start an Intent named-'gotoActivity1' which will take the control back to activity1.

Note: the text highlighted with green should be replaced by you in application. Something like this:
Activity1_pkg_name could be replaced by a package name of activity1 say: [com.blogs.prabhakar.activity1]
-----------------------------------------------------------------------------------------------

Passing/Receiving data through Intent ...

I am trying to pass data through my Intent into the next activity so I can receive it 

say: Sender Activity
Hereby , im sending the following three params [isLocationAvailable , latitude, longitude] alongwith the Intent & receiving the same in the Receiver Activity(Target Activity)...
Intent gotoActivity2= new Intent();
gotoActivity2 .setComponent(new ComponentName(Activity2_package_name, Activity2_class_name));
gotoActivity2 .putExtra(isLocationAvailable,true);
gotoActivity2 .putExtra(latitude ,dest_Coordinates.latitude);
gotoActivity2 .putExtra(longitude, dest_Coordinates.longitude);
this.startActivity(gotoActivity2 );

say: Receiver Activity
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    boolean isLocationAvailable = getIntent().getExtras().getBoolean("isLocationAvailable");
if(isLocationAvailable){
double dest_lat = getIntent().getExtras().getDouble("latitude");
double dest_lng = getIntent().getExtras().getDouble("longitude");
toPosition = new LatLng(dest_lat, dest_lng);
}
}
---------------------------------------------------------------------------------------------------