Sunday, March 12, 2017

Improved Display for Empty Field Values in ADF Form

I had a task in the project, to improve display for empty field in ADF form. By default, if there is no row data in the result - all input text entries in ADF form will be hidden, user will see only labels. This is not ideal, most of time users would prefer to see disabled input text boxes instead.

In this example below, on purpose I search for non existing value and this causing form below to become empty. First Name field shows example with disabled text box, the way we want it to be displayed. All other fields display only label - default way:


Let's see how First Name field is changed to be rendered as disabled, when there is no data. I have changed EL for value property. Instead of pointing directly to the binding inputValue (when expression points to standard inputValue and when there is no data - field is rendered as read-only), I point to proxy method in my custom bean. Method is generic and it accepts field name as variable:


Disabled property is changed to return true, when primary key value is empty - this would happen when there are no rows in the result:


No need to change any other properties.

Proxy method is implemented in the bean. This implementation allows to pass parameter to the getter. Parameter - attribute name. Using parameter we are reading value from the bindings. If value is empty - NULL is returned, this makes field empty, but not read-only. When user is changing value - we need to update binding - this is done in put method. Here we get two values from EL - attribute name and actual new value. Think about it as about HashMap element:


With this generic method, there is no need to define separate getters/setters for each UI field. You only need to provide attribute name in EL expression:


Now form is displayed with empty disabled boxes, when there is no result:


When results are available - from displays and allows to edit data:


Download sample application - ADFDataEntryUIApp.zip.

3 comments:

Yazan Mohammad said...

Thanks a lot for a valuable information!

Aldo InĂ¡cio da Silva said...

Nice article!!.

I think you don't need to override the put method, at least for this example.

Andrejus Baranovskis said...

You need to override put method, to be able to update binding value when value is changing.

Andrejus