Monday, February 27, 2012

List Of Values always returning 1st Row

On version 11.1.1.4.0 (very possibly on later versions too).

Old issue that I recently encountered again, thought it worth listing for reference purposes.

Problem: No matter which row the user selects on the List of Values (LOV) component, the LOV always returns the 1st row of LOV collection to the input field associated to it.

Solution: Check LOV View Object's attributes, you will find that no attribute(s) have been identified as Key attributes.

Explanation: Once the row in the LOV is selected, ADF does a getKey on the row to determine the Key which uniquely identifies the row in the View Object (which returns null or Empty Key if no Key is specified).  After that it does a findByKey on the LOV View Object to get the values to be returned to the af:inputTextListOfValues field.  Because the key is null, the findByKey does not know which View Object row to retrieve and at this point it just returns the first row of the LOV View Object rowset.

Specify your Key attributes, even if you have to make up a composite unique key on the VO, and your problem will be resolved.

Uploading Files

Quick note regarding the use of af:inputFile component.  It's not something I use too often but when I do there is a step I always forget:

In the parent af:form component set the usesUpload property to true. This is nothing new and is in the documentation...but I always forget until I look at the docs again.

Note: You can only use 1 af:form on any given page, so set the property on the af:form component in your housing JSPX page if you are using fragments.

Wednesday, February 15, 2012

Validate whole numbers

Simple way to do this is to add an af:validateRegExp to your af:inputText field, e.g.:
<af:validateRegExp pattern="^[1-9]+[0-9]*$"
                               messageDetailNoMatch="Value must be specified in whole number format."/>


NOTE:  when you drag n drop a number field from your view object ont a page as an af:inputText component, it adds an af:convertNumber by default.  In this case your RegExp validator will not fire as the number conversion will happen first.  This is fine to catch Alphabetic characters, but fractions will simply be rounded as per the rules specified in the af:convertNumber and no message will be raised for the user.  So if you want to validate via RegExp, delete the af:convertNumber .

A further addition to this post.  If the number field is based on a database Number column, you might want to consider specifying a precision on the column in the database and then synchronize those changes to your Entity Object in ADF.  You will then see a new Database Constraint validation added for the attribute in your Entity Object (consider adding a user friendly error message to the validation at this point).

Alternatively, if the inputText component is bound to a View Object or Entity Object, and no precision is specified on the database, you could add a RegExp validation to the attribute on the model layer.