Oracle ADF Basic: Partial Page Rendering with input and outputText
In one of our screens in our application (ADF BC + JSF) we had to make it possible to quickly enter data (to insert new records) without having to select a dropdown or List of Values, but with validation against the database. To implement this, we make use of PPR (Partial Page Rendering, a great feature of ADF Faces) and a ValueChangeListener. The page has the following layout:
[input text: item code] [output text: item description] [input text: quantity] [button: create orderline]
In the first input field the user will enter an ItemCode. When the user leaves that field, the ItemCode is checked against the database and only if one item is found for the entered code, the output field is updated to reflect the ItemDescription. Next the user can enter a quantity and tab to the button and give enter to create the orderline.
The first issue we have to deal with, is to trigger when the value of the ItemCode has changed, so we can check the value against the database when the field is left. To do this, we register a ValueChangeListener at the ItemCode field, like this:

Next thing we must be able to do, is to update the output text of the ItemDescription. To prepare this, we bind the field itself (not just its value) to the backing bean. We can do this like this:

To check if the entered Item Code is valid and to get the ItemDescription, I use a method which I created in the Application Module (to see how you can bind a method of the Application Module to the page and execute it in the backing bean, see my earlier post here).
The implementation of the valueChangeListener looks like this:
-
public void newItemCodeChanged(ValueChangeEvent valueChangeEvent)
-
{
-
// Select the itemRecord
-
// and returns the item_code & item_desc
-
OperationBinding operationBinding =
-
getBindings().getOperationBinding("getRequestedItem");
-
operationBinding.getParamsMap().put("itemCode",
-
valueChangeEvent.getNewValue());
-
-
// Set the returned fields in the corresponding fields
-
// If no values returned,
-
// fill item_desc with "No Item found" and set it's color to "red"
-
if (!operationBinding.getErrors().isEmpty() || result == null)
-
{
-
getNewItemDesc().setValue("No item found ! (or item already inserted)");
-
getNewItemDesc().setInlineStyle("color:red;");
-
}
-
else
-
{
-
setNewItemCodeValue(itemValues[1]);
-
getNewItemDesc().setValue(itemValues[2]);
-
getNewItemDesc().setInlineStyle("color:black;");
-
}
-
}
As you can see, I check if values are returned. If so, I set the ItemDescriptionField value to the returned value and make sure it is printed in black. If no Item Description is returned, I give the item Description field red colored fonts and state that an invalid item code was entered.
Now it is time for a very nice feature of ADF Faces. Although the value of the ItemDescription field may have changed by the backing bean, it won't show it in the screen, since it has not been rendered again. To make the ItemDescription field show it's new value when the ItemCode field has changed, you have to adjust the following properties to make PPR work:
- give the ItemCode field an Id
- set the autosubmit value for the ItemCode field to 'true'
- set the partialTrigger of the ItemDescription field to the Id of the ItemCode field, so the framework knows it has to rerender this field when something with the ItemCode field has happened.
That's it. If you now change the itemCode and tab out of the field the ItemDecription will change too without having the complete page refreshed!
When the button is clicked, the fields are sent to a method in our ApplicationModule which creates a record in the orderline table. After a succesful creation the fields in the screen are cleared so the user can enter the next record.
Tags: JSF, Oracle ADF










Could this principle be used to interrogate the value entered in the Item Code field? We are trying to intercept when a user enters the quantity in the item field. Generally, the user enters a quantity of "1" in the item field and sends the system on an extended search trying to bring up all of the qualifying entries.
Yes Jim, if I understand your question correctly, it is very well possible. It is similar to the example I describe here, right?
Thanks! We'll see if we can implement a solution using this technique.