Search This Blog

Thursday, 26 September 2013

Creating Render & Action URLs in Liferay

    
Creating A RENDER URL :

Using tags:    (preferred in JSP's)
<portlet:renderURL var="assignAgentTargetURL">
        <portlet:param name="agentId" value="<%= String.valueOf(AgentListBean.get_agentId())%>" />
        <portlet:param name="jspPage" value="/html/crm/team/assignAgentTarget.jsp" />
 </portlet:renderURL> 

Otherwise: (often used in case you wanna redirect to outside of current Portlet)
ie this type of URL creation is often helpful in case you are in (Portlet A) and wanna redirect to some jsp in(Portlet B).
Note: in such a case you must specify the portletId.portlet-name (refer below : plid) of the target Portlet.

long plid1 = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), com.prabhakar.portal.product.util.Constants.PRODUCT_PORTLET_NAME);

 LiferayPortletURL url = PortletURLFactoryUtil.create(actionRequest, com.prabhakar.portal.product.util.Constants.PRODUCT_PORTLET_NAME,  plid1, PortletRequest.RENDER_PHASE);

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

Creating A ACTION URL:

Using tags: (preferred in JSP's)

    <portlet:renderURL name="assignAgentTarget" var="assignAgentTargetURL">
        <portlet:param name="agentId" value="<%= String.valueOf(AgentListBean.get_agentId())%>" />
    </portlet:renderURL> 

Otherwise: (often used in case you wanna redirect to outside of current Portlet)
ie this type of URL creation is often helpful in case you are in (Portlet A) and wanna redirect to some jsp in(Portlet B).
Note: in such a case you must specify the portletId.portlet-name (refer below : plid) of the target Portlet.

long plid1 = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), com.prabhakar.portal.product.util.Constants.PRODUCT_PORTLET_NAME);

 LiferayPortletURL url = PortletURLFactoryUtil.create(actionRequest, com.prabhakar.portal.product.util.Constants.PRODUCT_PORTLET_NAME,  plid1, PortletRequest.ACTION_PHASE);

Monday, 26 August 2013

ANDROID: Connection to http://localhost:8080 refused

I wanted to make an Http Connection to my own WebServices(REST) exposed on another apache- tomcat server , but was getting this error :-
Connection to http://localhost:8080 refused
here's my code:
try{
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://localhost:8080/RestProject/rest/hello/Details");
HttpResponse httpResponse = httpClient.execute(httpGet);
InputStream content = httpResponse.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;

}
}

i checked the exposed webservices url it was working fine from the browser , but was surprised to see that my android app was unable to access the same ,being on the same machine..

hereby im sharing the solution that resolved my problem ,hoping it would help you too,

Actually, If you are referring to a localhost from your device(emulator) than use the http://10.0.2.2/ instead of the http://127.0.0.1/ or http://localhost/.
Because your Android emulator is running on a Virtual Machine(QEMU) and you can not connect to a server directly running on your PC.

So your code snippet should be like this:
try{
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://10.0.2.2:8080/RestProject/rest/hello/Details");
HttpResponse httpResponse = httpClient.execute(httpGet);
InputStream content = httpResponse.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;

}
}

ie use 10.0.2.2 instead of localhost or 127.0.0.1.



Sunday, 25 August 2013

How to create an war file in Eclipse without ant or maven?


Assuming that you created  a Dynamic Web project in Eclipse, here's a solution for you , 
 just right-click on the
project name > Export > WAR file

In case , you didn't created a Dynamic Web Project , you can convert your Static Project into one ..and then Proceed as above.

Tuesday, 20 August 2013

Unable to compile class for JSP

----------------------------------------------------------------------------------------------------------------------------------------
Aug 20, 2013 9:08:55 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 2,062 in the generated java file
The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit

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

TRY USING : 
<jsp:include page="/html/crm/customer/child.jsp"/>       
INSTEAD OF
<%@ include file="/html/crm/customer/child.jsp"%> 


Actually, if you think about it there is an extra performance hit with every action tag (@include file) .
For eg: say there are two files Child.jsp & Parent.jsp
where, Parent.jsp needs to include Child.jsp

--------------------( /html/.../Parent.jsp )----------------------------------------------------------------------------------
Try 
<jsp:include page="/html/.../Child.jsp"/>  
rather 
<%@include file="/html/.../Child.jsp"%> 
----------------------------------------------------------------------------------------------------------------------------------------
In case facing this Exception(above mentioned). But the only problem is that u need to remove all the dependencies of Parent from Child.
say,  boolean isAdmin= true;  is defined in Parent.jsp but Child.jsp is also being using this value.Otherwise ,in that case you might again get an exception saying : variable isAdmin in Child.jsp cannot be resolved . 

Because , the include directive(<%@include file=""%>) inserts the source of Child.jsp at translation time but the action tag(<jsp:include page=""/>) inserts the response of Child.jsp at runtime.

ANDROID: An established connection was aborted by the software in your host machine

----------------------------------------------------------------------------------------------
[2013-08-20 22:52:31 - ddmlib]An established connection was aborted by the software in your host machine
java.io.IOException: An established connection was aborted by the software in your host machine
    at sun.nio.ch.SocketDispatcher.write0(Native Method)
    at sun.nio.ch.SocketDispatcher.write(Unknown Source)
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source)
    at sun.nio.ch.IOUtil.write(Unknown Source)
    at sun.nio.ch.SocketChannelImpl.write(Unknown Source)
    at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213)
    at com.android.ddmlib.Client.sendAndConsume(Client.java:573)
    at com.android.ddmlib.HandleHeap.sendREAQ(HandleHeap.java:349)
    at com.android.ddmlib.Client.requestAllocationStatus(Client.java:419)
    at com.android.ddmlib.DeviceMonitor.createClient(DeviceMonitor.java:840)
    at com.android.ddmlib.DeviceMonitor.openClient(DeviceMonitor.java:808)
    at com.android.ddmlib.DeviceMonitor.processIncomingJdwpData(DeviceMonitor.java:767)
    at com.android.ddmlib.DeviceMonitor.deviceClientMonitorLoop(DeviceMonitor.java:635)
    at com.android.ddmlib.DeviceMonitor.access$100(DeviceMonitor.java:42)
    at com.android.ddmlib.DeviceMonitor$3.run(DeviceMonitor.java:563)

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

These problem can be simply solved by closing Eclipse and restarting it again. Eclipse sometimes fails to establish a connection with the Emulator, so this can happen in some cases.

for eg:
This problem may occur if you have two devices connected to the computer at the same time. Adb does not support reaching both devices via command/console. So, if you debug your app after connecting and disconnecting the second device you will most probably have this problem. One solution might be restarting adb and/or eclipse if necessary. It can be quite annoying sometimes and I am afraid there is no other solution to that.

Also, If you develop in multiple IDE's or other programs that connect to AVD you should try closing them too.




Monday, 29 July 2013

For getting AVD or Android SDK Manager tool options in Eclipse Juno 4.2.1

Not able to see sdk manager tool in Eclipse (If Already Installed)

For getting sdk manager tool options in Eclipse Juno 4.2.1 Simple steps.

Window---->Customize Perspective--->Command Groups Availability

And then Simply check Android SDK and AVD Manager.


----------------------------------------------------------------------------------------
Install the ADT Plugin (In case not Installed)

 check the following link  [Install ADT Plugin] to install the ADT plugin into your Eclipse.

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

Updating the ADT Plugin (In case not Updated)
To update the ADT plugin to the latest version, follow these steps:
  1. Select Help > Check for Update ...
  2. If any update for ADT or Android tools is available, select and install.
----------------------------------------------------------------------------------------

Sunday, 19 May 2013

How to change SVN-credentials in Eclipse

For Windows Users :-

Goto C:\Users\%User_Name%\AppData\Roaming\Subversion and remove the auth directory.
 Just be aware if you are connected to more than 1 SVN server that this will remove the authentication for all of the SVN servers you have configured.

 If you want to reset just a single server:
Inside the auth directory you should see a folder called svn.simple.
Open each of those files with a text editor to determine which one to remove and then remove just that single file.

say: Goto the following location in ur system --

 C:\Users\%User_Name%\AppData\Roaming\Subversion\auth\svn.simple            (On Windows 7)
--OR--
 C:\Documents and Settings[username]\Application Data\subversion\auth\svn.simple   (On versions previous to Windows 7)

 Delete the Hexadecimal file present over there (under the 'svn.simple' directory).
Now the next time you will hit any svn operations it will again ask for your svn credentials..you can reset over here again.

 NOTE: 
Incase you cannot find the APPDATA directory/folder ---do check for the hidden folders option / if some of the folders under C:\Users\'#UserName#'\ are not Hidden.

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


For Mac OS X ,i guess this would work :-

Goto folder /$HOME (/Users/{user home}/). You will see file '.eclipse_keyring'. Remove it. All saved credentials will be lost.
Now the next time you Restart Eclipse or Hit any svn-operations(Team-update/commit/etc) it will again ask for your svn credentials.
Now,you can reset over here once again.




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

This may Interest You :

Subclipse does not collect or store username and password credentials when defining a repository.
This is because the JavaHL and SVNKit client adapters are intelligent enough to prompt you for this information when they need to -- including when your password has changed.

    You can also allow the adapter to cache this information and a common question is how do you delete this cached information so that you can be prompted again?
We have an open request to have an API added to JavaHL so that we could provide a UI to do this. Currently, you have to manually delete the cache.The location of the cache varies based on the client adapter used.

    JavaHL caches the information in the same location as the command line client -- in the Subversion runtime configuration area.
On Windows this is located in %APPDATA%\Subversion\auth. On Linux and OSX it is located in ~/.subversion/auth.
Just find and delete the file with the cached information.

    SVNKit caches information in the Eclipse keyring. By default this is a file named .keyring that is stored in the root of the Eclipse configuration folder.
Both of these values can be overriden with command line options. To clear the cache, you have to delete the file.Eclipse will create a new empty keyring when you restart

Just Like, in my case I've been using JavaHL, which cashes credential data in the Subversion runtime configuration area. 
On Windows this was in "C:\Users\%User_Name%\AppData\Roaming\Subversion\auth\svn.simple" in one of the files with a long HEX name.