Wednesday, October 7, 2009

Accessing parameter from QueryString in IBM WebSphere Portal V6.0

You can access the parameter from QueryString in Portlet. Consider QueryString is like this
http://localhost:60035/wps/portal/checkout?PhoneId=35102


Portlet Code as below :

public class TestPortlet com.ibm.faces.portlet.FacesPortlet {

public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {

String phoneId = getparamter("PhoneId" request);
super.doView(request, response);

}

private String getparamter(String key,RenderRequest request){
String value = null ;
try{
if(request instanceof org.apache.pluto.core.impl.RenderRequestImpl ){
RenderRequestImpl renderRequestImpl = (RenderRequestImpl)request;

if(renderRequestImpl!=null){
String QueryString = renderRequestImpl.getQueryString();
if(QueryString!=null && QueryString.length() > 0){
StringTokenizer tokenizer = new StringTokenizer(renderRequestImpl.getQueryString(),"&");
while (tokenizer.hasMoreElements()) {
String token = (String) tokenizer.nextElement();
if(token.indexOf(key)!=-1){
value = token.substring(token.indexOf("=")+1);
break;
}
}
System.out.println("key value in getparamter :"+value);
}
}

}
}catch(Exception e){
System.out.println("error occured while accessing QueryString "+e.getMessage());
}

return value;
}

No comments:

Post a Comment

Followers