我有一个要求,我需要在doView方法中从请求中获取页面名称并将其重定向到page_name_SUFIX,但我找不到解码WebSphere URL的方法
当我请求'pageName'的视图时,我必须做这样的事情:
public void doView(RenderRequest req, RenderResponse res) {
String decodedURL = decodeURL(req); // This is the method that I need, decodedURL should be 'pageName'
(...)
}
我正在研究WebSphere 8.0,并且我尝试了以下但没有结果。
http://wpcertification.blogspot.com.ar/2010/05/getting-name-of-page-where-your-portlet.html(这里我有页面标题,但我不知道如何获得名称)
WebSphere Portal decode url(我已经解码了网址但我在XML中找不到网页名称)
有一些方法可以达到这个目的吗?
提前谢谢!
答案 0 :(得分:1)
所以问题是范围,从上面不清楚你是否在页面的uniqueName中表示pageName?如果是这样,一旦你在字符串或实际对象中有了objectid,就可以从该对象中获取uniqueName。
这里是获取当前页面的objectId的代码 public ObjectID getCurrentPage(PortletRequest请求, PortletResponse响应)抛出StateException,NamingException, IOException { ObjectID oId = null; 尝试{ NavigationSelectionModelProvider provider = getNavigationSelectionModelProvider();
NavigationSelectionModel model = provider
.getNavigationSelectionModel(request, response);
NavigationNode node = (NavigationNode) model.getSelectedNode();
oId = node.getObjectID();
} catch (ModelException e) {
System.err.println("The current page could not be located = " + e);
}
return oId;
}
现在,如果您的问题是关于名为pageName的portlet参数,那么它应该在已解码的URL中。它是您正在寻找的uniqueName吗?这不会出现在xml中,但你可以从objectid对象中获取
答案 1 :(得分:0)
您应该能够使用类似于此的doView方法获取页面ID / uniqueName:
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());
PortletServiceHome nsh = null;
javax.naming.Context ctx;
boolean serviceAvailable = false;
try {
ctx = new javax.naming.InitialContext();
nsh = (PortletServiceHome)ctx.lookup("portletservice/com.ibm.portal.portlet.service.model.NavigationSelectionModelProvider");
serviceAvailable = true;
} catch(NameNotFoundException nnfe) {
nnfe.printStackTrace();
} catch(NamingException ne) {
ne.printStackTrace();
}
// Check if portlet session exists
ShowPageLayoutPortletSessionBean sessionBean = getSessionBean(request);
if( sessionBean==null ) {
response.getWriter().println("<b>NO PORTLET SESSION YET</b>");
return;
} else if(!serviceAvailable) {
response.getWriter().println("<b>NO SERVICE AVAILABLE</b>");
return;
}
try {
NavigationSelectionModelProvider nsProvider = (NavigationSelectionModelProvider) nsh.getPortletService(NavigationSelectionModelProvider.class);
NavigationSelectionModel navmodel = nsProvider.getNavigationSelectionModel(request, response);
NavigationNode navNode = (NavigationNode)navmodel.getSelectedNode();
ContentPage contentPage = (ContentPage)navNode.getContentNode();
ObjectID pageId = contentPage.getObjectID();
// Invoke the JSP to render
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(getJspFilePath(request, VIEW_JSP));
rd.include(request,response);
} catch(Exception ex) {
ex.printStackTrace();
}
}