Sunday, October 14, 2012

AJAX error handling in DOJO



In Order to return an Ajax error from the server, you need to set the response status to 500, For example if you are working with Java Servlets, your Java Servlet will return the error as follows:

public class AjaxServlet extends HttpServlet {
protected void doPost (HttpServletRequest request, HttpServletResponse response)                               throws ServletException, IOException {
            try {
                        // Do whatever you want to do
                        } catch (Exception exception) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            response.getWriter().write(exception.getMessage());
            response.flushBuffer();                               
            } finally {
// Clean up ...
            }
}
}

In the client side, you can get the server error message (after checking that the readyState of the XML HTTP Request (XHR) is 4, and the status of the XHR object is 500) from the responseText of the XHR object.
If you are using Dojo framework then in the Dojo xhrPost API, in order to get the error message, you can get it from the ioArgs parameter of the error callback as follows:
dojo.xhrPost( {
            url: 'service URL',
            content: {},
            handleAs: 'text',
            load: function(response, ioArgs) {
                        // Do something
            },
            error: function(response, ioArgs) {
                        alert("Failed while doing the operation: " + ioArgs.xhr.response);
            }
});

Using the ioArgs.xhr.response, you can get the full error message from the server response, you can also get the status code from the ioArgs.xhr.status.

Saturday, October 13, 2012

How to prevent Caching in AJAX requests


Below steps you can perform to prevent caching in AJAX calls.
              To prevent the response from being cached you can set preventCache flag to true while making dojo request.
            var getContentCallback = function (contentAliases) {
            var contentUrl = servletPath + "/content";
            var xhrArgs = {
                        url:contentUrl,
                        handleAs:"json",
                        preventCache: true,
            content:{
                contentType:"Content",
                contentAliases:dojo.toJson(contentAliases)
            }
        };
        var deferred = dojo.xhrGet(xhrArgs);
        return deferred;
    }

When the preventCache will be set to true it will append dojo.preventCache query parameter to the url before making request so in that case it will take the <portlet:resourceURL/> and append the dojo.preventCache query parameter and the value of dojo.preventCache parameter will change every time the xhr call will be made so server will always return the full response.

Assigning unique name to themes and skins in WebSphere Portal


Assigning unique name to themes and skins in WebSphere Portal
This article will explain how we can assign unique names to themes and skin in WebSphere Portal 7.x.

Assigning unique name to themes:

Below steps will explain how we can assign unique name to the themes.
1.      Install themes on WebSphere Portal through admin console using Theme and Skins portlet
2.      Export full  WebSphere Portal using xmlaccess. For this you can see my below blog.
3.      Then find the theme to which you want to assign unique name and copied into a different xml like this.
<request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" build="wp7002CF16_001_14" type="update" version="7.0.0.2" xsi:noNamespaceSchemaLocation="PortalConfig_7.0.0_2.xsd">
  <portal action="locate">
            <theme action="update" active="true" default="false" defaultskinref="K_BFAV34331OJJC0IGDRU9JM2051" domain="rel" objectid="J_BFAV34331OJJC0IGDRU9JM2053" resourceroot="MyThemeName"
uniquename="com.companyname.theme.MyThemeName">
           <localedata locale="en">
           <title>MyBrocadeTheme</title>
           </localedata>
      <allowed-skin skin="K_NO2UF4I1186E1026H4BLVI00E5" update="set"/>
      <allowed-skin skin="K_KJ2SLD231GJG10IKG6K6NM2000" update="set"/>
      <allowed-skin skin="K_KJ2SLD231OJH60ISR6CS3O3000" update="set"/>
      <allowed-skin skin="K_BFAV34331OJJC0IGDRU9JM2051" update="set"/>
      <allowed-skin skin="K_BFAV34331OJJC0IGDRU9JM2055" update="set"/>
       </theme>
    </portal>
</request>
 
4.      Like this you can add unique names to all themes in this single file itself.
 5.      Import this xmlaccess script into the portal.

For Windows
            ./xmlaccess.bat  -in  Theme.xml -user wpsportalUserName -password password –url  http://hostName:portName/wps/config -out ThemeExportOut.xml

For Linux

./xmlaccess.sh  -in  Theme.xml -user wpsportalUserName -password password –url  http://hostName:portName/wps/config -out ThemeExportOut.xml

Assigning unique name to Skins:

 Below steps will explain how we can assign unique name to the skins.
1.      Install skins on WebSphere Portal through admin console using Theme and Skins portlet
2.      Export full  WebSphere Portal using xmlaccess. For this you can see my below blog.
3.      Then find the theme to which you want to assign unique name and copied into a different xml like this.
<request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" build="wp7002CF16_001_14" type="update" version="7.0.0.2" xsi:noNamespaceSchemaLocation="PortalConfig_7.0.0_2.xsd">
  <portal action="locate">
            <skin action="update" active="true" default="false" domain="rel" objectid="K_BFAV34331OJJC0IGDRU9JM2051" resourceroot=" MySkinName" type="default" uniquename="brocade.webportal.skin.MySkinName">
            <localedata locale="en">
                <title> MySkinName </title>
            </localedata>
        </skin>
      </theme>
    </portal>
</reques
4.      Like this you can add unique names to all skins in this single file itself. 
5.       Import this xmlaccess script into the portal.

For Windows
            ./xmlaccess.bat  -in  Skin.xml -user wpsportalUserName -password password –url  http://hostName:portName/wps/config -out SkinExportOut.xml

For Linux

./xmlaccess.sh  -in  Skin.xml -user wpsportalUserName -password password –url  http://hostName:portName/wps/config -out SkinExportOut.xml