calling servlet from primefaces

UI Components for JSF
Post Reply
prime_irakli
Posts: 5
Joined: 09 Sep 2011, 13:55

09 Sep 2011, 14:06

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?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

09 Sep 2011, 16:11

Do a redirect or set ajax to false on p:commandButton.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: arsen325 and 22 guests