Skip to main content

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

Suresh Babu said…
Thanq It helped a lot.

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…