i have class
@ManagedBean
public class PPRBean implements Serializable {
public void doThis() {
String url = "/NewServlet";
FacesContext context = FacesContext.getCurrentInstance();
try {
context.getExternalContext().dispatch(url);
} catch (Exception e) {
e.printStackTrace();
} finally {
context.responseComplete();
}
}
}
servlet:
public class NewServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet NewServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>first name: " + request.getParameter("name") +" last name: "+ request.getParameter("last")+"</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
}
and xhtml
<h:form id="myForm">
<h:commandButton value="Do" actionListener="#{pPRBean.doThis2}" styleClass="button">
<f:attribute name="name" value="Hello"/>
</h:commandButton>
</h:form>
it all works fine, but when i using p:commandButton instead for h:commandButton, servlet doesn't calling.
how to call servlet from p:commandButton?
anyone can help me?
calling servlet from primefaces
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
Do a redirect or set ajax to false on p:commandButton.