Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Thursday, 17 April 2014

ADF - Convert inputText inputListOfValues to UpperCase

There are many articles about this topic.
Various techniques are proposed including: Javascript, converter, contentStyle etc..
I think that no solution is perfect.
For example:
Javascript: while typing the character changes.
Converter: the conversion happens only on the server side.
contentStyle: the conversion is only visual but the String submitted is not in uppercase.
For me, the best solution is to act in two places.
I consider excellent the use of the contentStyle to display uppercase letters:


In my case I use an inputText, but an inputListOfValues is equal to.
As I wrote before the contentStyle has an effect purely graphic but the value submitted is not converted.
We therefore need to combine the use of the contentStyle with the use of a Converter to convert the value also on server side.
So, we must implement a simple converter that implements the class: javax.faces.convert.Converter:


Very simple.
After that we must register this converter in faces-config.xml file:


Finaly in the converters list of our component we can choose the StringToUppercaseConverter:


In this way we not only see the uppercase letters when typing, but also the data will be submitted in uppercase.

But...Why this is not a perfect procedure?
In this way we remain uncovered on programmatic "setAttribute" calls.
For example if we call 
row.setAttribute("MyField","abc") 
for an attribute not in page, the converter (obviously not present) not will converts the value.

Attention:
I think that convert the data directly in the overridden setAttribute method  is not a good idea.
setAttribute should already be called with the right value.

Monday, 18 November 2013

POST-QUERY in ADF

The POST-QUERY in ADF is very simple to implement and it is much documented both in the official Oracle Documentation and in various ADF Blogs and Forums.
In my blog I discuss often about the relation between Form Builder and ADF, so I think that a post about POST-QUERY is very important to write.
So, here the implementation:

Open the Model Project and implement the ViewObjectImpl class of your ViewObject.xml (in my example called MyViewObject.xml) as shown:



Now override the method "createRowFromResultSet":


    protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet resultSet) {
      ViewRowImpl value = super.createRowFromResultSet(qc, resultSet);
      if(value != null){
        <<YOUR POST-QUERY CODE of the row "value">>
      }
      return value;
    }

That's all.
Easy and fast!