Friday, December 16, 2011

opening PDF as popup in jsr 168 portlet,popup in jsr 168

Since JSR 168 has only support for html so we need a servlet to be called from the jsp.

Step1- Create a servlet and in doGet use this code

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

HttpSession httpsession =request.getSession();
Map map = (Map)httpsession.getAttribute("resultMap");
if(map != null)
{
GeneratePDF.generatePDFReciept(map, response);
}
httpsession.removeAttribute("resultMap");
}


Here I am passing map to GeneratePDF method and in this method i am using itext API to generate PDF from the map values.

step2:-  use the following code in the process action and set attribute in the HttpSession.

                  HttpServletRequest httpServletRequest = (HttpServletRequest)request;
   while(httpServletRequest instanceof HttpServletRequestWrapper){
     HttpServletRequestWrapper httpServletRequestWrapper =
  (HttpServletRequestWrapper)httpServletRequest;
     System.out.println("HttpServletRequestWrapper " + httpServletRequestWrapper);
     httpServletRequest =  (HttpServletRequest)httpServletRequestWrapper.getRequest();
   }
 
    HttpSession httpsession = httpServletRequest.getSession();
 
    httpsession.setAttribute("resultMap", receiptmap);


3:-Now invoke the servlet as popup from the portlet jsp by simply  calling javascript on clicking the button or link, as follows:-

function servletCall()
{

 window.open("http://<%=renderRequest.getServerName()%>:<%=renderRequest.getServerPort()%><%=renderRequest.getContextPath()%>/PDFPopup","PrintWindow","toolbar=0 scrollbars=yes");

}

Now you can view your data in popup  :)

Tuesday, November 1, 2011

calling body onload javascript in portlet jsr 168.

Since we are not calling body tag in jsp in jsr 168 portlet so simply create a script tag and call function as :-

<script>
function checkEnter()
{
document.body.onkeypress = enterKey
}
checkEnter();

</script>

Simply add this in your jsp and in check enter function you can call your own functions as I am calling enterKey Functions,
Here I am checking for the enter key press :
<script>
function enterKey(evt) {  
  var evt = (evt) ? evt : event;
  var charCode = (evt.which) ? evt.which : evt.keyCode;
  if (charCode == 13) {
    setOperationName('POST','RECEIPT');
    return false;
  }
  return true;
}
</script>

Tuesday, October 18, 2011

personalization of theme ,showing group related links in a theme

Below code personalizes the theme , and you can show only the related links for groups, in this code i have created a url mapping for change password portlet and personalised it by fetching group name by PUMA api, u have to use this code in the banner_toolbar.jspf in ur theme.

Monday, June 27, 2011

PUMA Api code to reset password, Verify old password in websphere portal

When you are not using LDAP and you have to change user password with verifying old password the only option left is by using WAS Programatic Login.you can reset new password by Puma API and verify the old password by WAS Authentication, the below code is working fine for me.

PortletServiceHome psh = null;

try {
if (psh == null) {
javax.naming.Context ctx = new javax.naming.InitialContext();
psh = (PortletServiceHome) ctx.lookup("portletservice/com.ibm.portal.um.portletservice.PumaHome");
}
} catch (NamingException e) {


e.printStackTrace();

}
HashMap userAttrs = new HashMap();

String oldPwd = request.getParameter("OLD_PASSWORD");
String pwd1 = request.getParameter("PASSWORD");
String pwd2 = request.getParameter("PASSWORD_CONFIRM");

try
{

PumaHome service=(PumaHome) psh.getPortletService(PumaHome.class);
PumaLocator pLocator=service.getLocator();
PumaController pc = service.getController();
com.ibm.wps.puma.User vuser = (com.ibm.wps.puma.User)request.getAttribute("com.ibm.portal.puma.request-user");
String userid = vuser.getUserID();

if( pwd1 != null && oldPwd != null )
{

//verify password

LoginContext lc = null;
Subject subject = null;
System.out.println("old pwd::"+oldPwd);
try {
lc = new LoginContext("WSLogin",
new WSCallbackHandlerImpl(userid, oldPwd));

} catch (LoginException le) {
System.out.println("Cannot create LoginContext. " + le.getMessage());

} catch(SecurityException se) {

System.out.println("Security Exception. " + se.getMessage());
}

try {
lc.login();
subject = lc.getSubject();
System.out.println("loged in");
passwordVerification = true;
com.ibm.websphere.security.auth.WSSubject.setRunAsSubject(subject);
} catch(LoginException le) {
passwordVerification = false;
System.out.println("Fails to create Subject. " + le.getMessage());

}



if(passwordVerification)
{
userAttrs.put("uid", userid);
userAttrs.put("password", pwd1);

List userList = pLocator.findUsersByAttribute("uid", userid);
User editUser = (User)userList.get(0);
pc.setAttributes(editUser, userAttrs);

passwordChanged = true;

}

Thursday, June 9, 2011

WebSphere Portal Project Architecture,Portal Project Flow Diagram

This Diagram Shows a Portal project flow Diagram, Project flow can vary according to requirements.


Tuesday, June 7, 2011

Inter Portlet Communication in JSR -168 by RAD 7.5,Portlet Wiring.

1.First create a new portlet project or use existing one,The source and target portlet should be in same workspace.
2.Create Portlet IPC1 & IPC2.
3.Create Source and Target Portlets as shown below.


 Select The Data Type For Source Portlet, as shown below.




Similarly make a cooperative target portlet, as shown.



As for source portlet, select Data Type for target portlet.

Then in the source portlet JSP use the Cooperative Source Trigger to create an event on click,





After setting the event use
  if(actionValue != null && "TargetAction".equals(actionValue)) {
           
          String input = request.getParameter("inputProperty");
           
            session.setAttribute("input", input,session.PORTLET_SCOPE);
         }
in target portlet process action to fetch the value that you have set in the scope.

After that you can use bean or session to render the value from process action  to targer portlet jsp.

Then deploy the portlet, and add them on a page, Then edit page layout and do the WIRING between source and target portlets. as shown below.
 Now your Inter Portlet communication is done.you can put the value in the source portlet and after clicking submit value will be shown on target portlet.



On submitting the output will be:-



For any help or issue please contact me at sanjeetsinghmerhal@gmail.com.
Please follow me if material is useful for you.
Thanks



Friday, May 27, 2011

giving signer certificates and trust stores in WAS to run services from Portal.

1.First import the certificates by running  ikeyman.sh utility from the /bin, use xmanger for running this utility the UI will not appear in Putty.you can refer
http://publib.boulder.ibm.com/infocenter/adiehelp/v5r1m1/index.jsp?topic=/com.ibm.wasee.doc/info/ee/ae/tsec_importsigner.html for importing keys.

2.put the imported keys in WAS server by winscp.
3.Open WAS administration console  and  go to signer certificates ,
put entry for client as shown below.


4. Similarly put entries for trust stores for default and Client as shown below by clicking on trust stores.
5. Restart WAS , and start hitting services from portal, your EJB will run on WAS properly.



Steps for Adding custom Attribute in profile WebSphere Portal 6.1.

First install the attribute installer.
1.Restart Portal Server
2.Edit wkplc.properties with the following info:
la.propertyName=userCompanyId
la.entityTypes=PersonAccount
la.dataType=String
la.multiValued=false
Run ConfigEngine.bat wp-add-property -DWasPassword=secret

After running the above command, a file wimxmlextension.xml will be created in \config\cells\\wim\model folder.
Put an entry for your attribute by directly editing the file wimxmlextension.xml




Restart Portal Server

Run ConfigEngine.bat wp-query-attribute-config -DWasPassword=secret



This will create availableAttributes.html report in /ConfigEngine/log & now you can check your newly created
attribute from the Administration.