you might want to change your local JS code to be browser neutral :-) That code works in IE only. (But that's not the problem at hand). A XPage is a life-cycle managed server construct and isn't designed to process arbitrary data thrown at it.
The recommended way to deal with what you want to do is to use the REST control from the extension library. You can configure a URL part for it e.g. data
, so you would post to baseURL + "/echoxml.xsp/data"
. There you have the payload readily in a variable.
The Rest control also supports the use of an custom Java class if you prefer to do that.
The last option is to add a custom servlet. Here are the steps:
- Open the Navigator view and create /Code/Java/META-INF/services/com.ibm.xsp.adapter.servletFactory as text file (that exact name)
- add one line with the name of your servlet. eg.
com.acme.EchoFactory
Write the echo factory class:
public class EchoFactory implements IServletFactory{ private ComponentModule module; public ServletMatch getServletMatch(final String contextPath, final String path) throws ServletException { if (path.startsWith("/xsp/echo")) { return new ServletMatch(module.createServlet("com.acme.EchoServlet", "Can you hear it?", null),"",path); } return null; } public void init(final ComponentModule module) { this.module = module; } }
Implement the Echo Servlet
public class EchoServlet extends DesignerFacesServlet { @Override public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { HttpServletRequest req = (HttpServletRequest) servletRequest; HttpServletResponse res = (HttpServletResponse) servletResponse; FacesContext facesContext = this.getFacesContext(req, res); String method = req.getMethod(); // Your code goes here! }
Hope that helps