Thursday, June 14, 2012

calling ajax in jsr 286

I have created a sample portlet to show the suggestion by calling ajax:-









The sample jsp for calling the ajax as above is:


<%@page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1" session="false"%>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects />
<script type="text/javascript">
  function createXMLHttpRequestObject() {
    var xmlHttp;
    try {
      xmlHttp = new XMLHttpRequest();
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
      } catch (e) {
      }
    }
    if (!xmlHttp)
      alert("Error creating the XMLHttpRequest object.");
    else
      return xmlHttp;
  }
  var xmlHttp = createXMLHttpRequestObject();
 
 
  function makeResourceCall(str){
 
 
  if (str.length==0)
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
 
    if (xmlHttp){
    var newvalue ="Harish"+str;
 
      try{
      var url ="<portlet:resourceURL></portlet:resourceURL>?txtValue="+str;
   
        xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = handleRequestStateChange;
       
        xmlHttp.send(null);
      }catch (e){
        alert("Can't connect to server:\n" + e.toString());
      }
    }
  }

  function handleRequestStateChange(){
    if (xmlHttp.readyState == 4){
      if (xmlHttp.status == 200){
     
      if(xmlHttp.responseText == "")
      {
      document.getElementById("txtHint").style.display="none";
      }
      else
      {
       document.getElementById("txtHint").style.display="block";
       document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
       }
      }
    }
  }
</script>

Enter Name<input type="text" name="txtValue" onkeyup="JavaScript:makeResourceCall(this.value)" >


 <!-- <p>Suggestions: <span id="txtHint"></span></p>  -->

<TEXTAREA name="annotationTxt" rows="10" cols="30" style="overflow:hidden;" id="txtHint" maxlength="235"></TEXTAREA>

<script>
function onload()
{
 document.getElementById("txtHint").style.display="none";
}
onload();
</script>


Onkeyup I am calling makeResourceCall and from makeResourceCall function calling <portlet:resourceURL>
From this the control will go the portlet class and will call the serverResource method:

 public void serveResource(ResourceRequest request, ResourceResponse response)
     throws PortletException, IOException {
     System.out.println("Entering ValidationCacheSamplePortlet.serveResource()");
     response.setContentType("text/html");
     System.out.println("String input value"+request.getParameter("txtValue"));
     inserRec rec = new inserRec();
     List list = rec.getData(request.getParameter("txtValue"));
    
    for (Iterator iterator = list.iterator(); iterator.hasNext();) 
    {
    HibernateprjPojo pojo = (HibernateprjPojo) iterator.next();
response.getWriter().println(pojo.getName());
In the serve resource method I am making a hibernate call and fetching the related values for txtValue.
From the getwritter the result will be shown in the drop down box.


Hidden portal page

To create a hidden portal page , first create a page and give it a proper unique name .
Export the portal page and save the xml.
Edit the xml and add the parameter


<parameter name="com.ibm.portal.Hidden" type="string" update="set"><![CDATA[true]]></parameter>
As shown below:-





<?xml version="1.0" encoding="UTF-8"?>
<request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" build="wp6101_115_01" type="update" version="6.1.0.1" xsi:noNamespaceSchemaLocation="PortalConfig_6.1.0.xsd">
    <portal action="locate">
      
       
        <content-node action="locate" domain="rel" objectid="6_20DO18N3Q4IL40ITIA32AM2085"/>
        <content-node action="update" active="true" allportletsallowed="true" content-parentref="6_20DO18N3Q4IL40ITIA32AM2085" create-type="explicit" domain="rel" objectid="6_20DO18N3QCKQ40ITNC79MH00O6" ordinal="200" type="page" uniquename="ibm.home.test">
            <supported-markup markup="html" update="set"/>
            <localedata locale="en">
                <title>test2</title>
            </localedata>
<parameter name="com.ibm.portal.Hidden" type="string" update="set"><![CDATA[true]]></parameter>
            <parameter name="com.ibm.portal.IgnoreAccessControlInCaches" type="string" update="set"><![CDATA[false]]></parameter>
            <parameter name="com.ibm.portal.bookmarkable" type="string" update="set"><![CDATA[Yes]]></parameter>
            <parameter name="com.ibm.portal.remote-cache-expiry" type="string" update="set"><![CDATA[0]]></parameter>
            <parameter name="com.ibm.portal.remote-cache-scope" type="string" update="set"><![CDATA[NON-SHARED]]></parameter>
            <access-control externalized="false" owner="uid=wpsadmin,o=defaultWIMFileBasedRealm" private="false"/>
            <component action="update" active="true" deletable="undefined" domain="rel" modifiable="undefined" objectid="7_20DO18N3QCKQ40ITNC79MH00O1" ordinal="100" orientation="H" skinref="undefined" type="container" width="undefined">
                <component action="update" active="true" deletable="undefined" domain="rel" modifiable="undefined" objectid="7_20DO18N3QCKQ40ITNC79MH00O5" ordinal="100" orientation="V" skinref="undefined" type="container" width="undefined"/>
                <component action="update" active="true" deletable="undefined" domain="rel" modifiable="undefined" objectid="7_20DO18N3QCKQ40ITNC79MH00O3" ordinal="200" orientation="V" skinref="undefined" type="container" width="undefined"/>
            </component>
        </content-node>
    </portal>
    <status element="all" result="ok"/>
</request>







Tuesday, June 12, 2012

Shared Libraries for portal project

For creating a shared library open the WAS console and create a shared variable:


















After giving the path of your shared library go to

ApplicationServer> WebSphere_Portal> and select java and process Management and select the class loader

and chhose the shared library reference.












and in the shared reference select your shared library reference:












Restart your server and deploy your war file , it will automatically take references of your jars .


Monday, June 11, 2012

PUMA API for anonymous users

For creating portlets like signUp or forget Password we need the puma api to access the user information .But before accessing attributes you have to give following  access rights others wise you won't be able to access the values.
1.From the admin console go to resource permission.

2.Select the User Groups.
3.For All Portal User Groups give the anonymous access  for USER,Editor ,Manager,Security administrator.

After that your code will work fine.