Posting a JSF page to Servlet

There are some use cases which requires posting data to a (legacy) Servlet for further processing and on success, redirect to a JSF page. This example illustrates a possible solution for similar scenarios - posting a JSF page to a Servlet. Basic idea is to invoke a custom javascript method on click of the button and submit the form to a customized 'action' target(Servlet).
<af:commandButton text="Post Me" id="cb1">
  <af:clientListener type="action" method="customPostHandler"/>
</af:commandButton>

<af:resource type="javascript">
  function customPostHandler(event) {
      var form = document.forms[0];
      form.action = '/some-context-root/sampleservlet';
      form.submit();
      event.cancel();
  }
</af:resource>
You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS2]

How to run this sample?

Run the login.jspx page. This page is pre-populated with values for user name and password fields, leave the default values as is. Click on 'Post Me' button. This in turn posts data to 'SampleServlet' which processes the posted data, and on success, request is getting redirected to welcome.jspx

Comments

  1. Replies
    1. Great Article. Thank you for sharing! Really an awesome post for every one.

      IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      Delete

Post a Comment

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.