Skip to main content

ADF 12.x: Changing the List Of Values "No rows to display" text

In this post I describe how I implemented an interesting Use Case where the customer wanted to have an alternate message in the LOV when there is no data found. We all know how this can be changed in an af:table component by simply changing the emptyText property. In a List of Values, this works 'slightly' different.

Lets start with the basics

By default you will see the following List Of Values, telling you that no data was found:

However in the case of my customer, they were not happy with the text. So I had to come up with something else. That is interesting, because the ListOfValues is an ADF component in itself and the individual components inside the LOV cannot be manipulated by means of properties. I had to find a way to get access to the table component inside the List Of Values.
The way to do this has been described by Frank Nimphius, a long while ago, in his Forum Harvest posts. To be more specific, it is the harvest of November 2010, section "How-to define access keys to buttons displayed in an LOV dialog"

This really helped me to solve the issue and exactly describes what should happen at runtime.

  1. A user clicks the LOV button next to an Input List of Values component. In response to this, the LOV component launch event is fired, which we listen to in a managed bean.
  2. The launch event however is handled during the JSF Invoke Application phase, whereas the LOV displays during Render Response. Because of this, it is not possible to use a dialog launch listener to set the access keys for the buttons. Instead, the launch listener is used to invoke client side JavaScript.
  3. The client side JavaScript addresses an af:serverListener component to queue a custom event in ADF Faces. The custom event invokes a managed bean method that accesses the list of value component to eventually find the table component.

I started with the code sample as was provided in Franks post and was able to extend it for my needs. The trick is in lines 32-39:

1:    //method called from the server listener  
2:    public void changeLovInternals(ClientEvent ce) {  
3:      //get the LOV component binding reference  
4:      RichInputListOfValues lov = getListOfValues();  
5:      String id = lov.getClientId(fctx);  
6:      RichPopup popup = null;  
7:      String facetName = null;  
8:      UIComponent componentFacet = null;  
9:      Iterator facetNames = lov.getFacetNames();  
10:      while (facetNames.hasNext()) {  
11:        facetName = (String);  
12:        if (facetName != null) {  
13:          componentFacet = lov.getFacet(facetName);  
14:          if (componentFacet != null && componentFacet instanceof RichPopup) {  
15:            popup = (RichPopup) componentFacet;  
16:            break;  
17:          }  
18:        }  
19:      }  
20:      RichDialog lovDialog = (RichDialog) popup.getChildren().get(0);  
21:      lovDialog.setCancelTextAndAccessKey("&Take me back");  
22:      lovDialog.setAffirmativeTextAndAccessKey("&Make my choice");  
23:      //refresh the LOV to show the buttons  
24:      AdfFacesContext.getCurrentInstance().addPartialTarget(lovDialog);  
25:      // I found that the dialog consists of a panelGridLayout with 2 gridrows  
26:      if (lovDialog.getChildCount() == 1 && lovDialog.getChildren().get(0) != null &&  
27:        lovDialog.getChildren().get(0) instanceof RichPanelGridLayout) {  
28:        RichPanelGridLayout panelGridLayout =  
29:          (RichPanelGridLayout) lovDialog.getChildren().get(0);  
30:        List uiCompList = panelGridLayout.getChildren();  
31:        // always gridrows and always two.  
32:        if (uiCompList.size() > 0) {  
33:          // the first one is the search panel  
34:          // the second contains the table  
35:          RichGridRow richGridRow = (RichGridRow) uiCompList.get(1);  
36:          RichGridCell richCell = (RichGridCell) richGridRow.getChildren().get(0);  
37:          RichTable theTable = (RichTable) richCell.getChildren().get(0);  
38:          theTable.setEmptyText("Really, this is something, but it works");  
39:          AdfFacesContext.getCurrentInstance().addPartialTarget(theTable);  
40:        }  
41:      }  
42:    }  

When you run the application now, the LOV will display the alternate text

If you know how to get into the internal structure of an inputListOfValues, or any other component, you will be able to manipulate these components. Note that there is no guarantee that these manipulation will work after a upgrade. Oracle can change the implementation. This is for instance what happened with the inputListOfValues when the panelGridComponent became available. The internal structure of the ListOfValues component switched from using PanelGroupLayout and PanelHeader to using the PanelGridLayout component.
The solution in this post is implemented in 12.1.3. I did not check if Oracle changed the inputListOfValues in 12.2.

The code for this post can be found here on GitHub.

Most credits go to Frank Nimphius for his Forum Harvest post


Popular posts from this blog

ADF 12.1.3 : Implementing Default Table Filter Values

In one of my projects I ran into a requirement where the end user needs to be presented with default values in the table filters. This sounds like it is a common requirement, which is easy to implement. However it proved to be not so common, as it is not in the documentation nor are there any Blogpost to be found that talk about this feature. In this blogpost I describe how to implement this.

The Use Case Explained
Users of the application would typically enter today's date in a table filter in order to get all data that is valid for today. They do this each and every time. In order to facilitate them I want to have the table filter pre-filled with today's date (at the moment of writing July 31st 2015).

So whenever the page is displayed, it should display 'today' in the table filter and execute the query accordingly. The problem is to get the value in the filter without the user typing it. Lets first take a look at how the ADF Search and Filters are implemented by the f…

ADF 12.2.x : Conditional Showing Message Instead of List of Values Popup

Today I had to fix an issue in one of our ADF applications. For those of you working with ADF (as I do too occasionally) this might be valuable, so I decided to share this. The application is based on an old Oracle Forms applications and I had to implement the following functionality:

FRM-41830 : List of Values contains no entries.

In other words (more ADF like) : If you are about to render a List of Values and that List of Values contains no rows, just show a message instead of showing the List of Values.

In this post I will describe how I was able to implement this although it turned out to be a challenge.
Below are the steps that I took. Note that the Application can be downloaded from GIT.

1) I use a UI pattern where we use readonly table and do edits in a popup. That means that any List of Values will add an additional popup to the UI.

2) The List of Values that I use in this sample only shows entries where the minimum salary is less then the employees current salary. Not that …

ADF 11g Quicky 3 : Adding Error, Info and Warning messages

How can we add a message programatically ? Last week I got this question for the second time in a months time. I decided to write a short blogpost on how this works.

Adding messages is very easy, you just need to know how it works.
You can add a message to your faces context by creating a new FacesMessage. Set the severity (ERROR, WARNING, INFO or FATAL ), set the message text, and if nessecary a message detail. The fragment below shows the code for an ERROR message.

1: public void setMessagesErr(ActionEvent actionEvent) {
2: String msg = "This is a message";
3: AdfFacesContext adfFacesContext = null;
4: adfFacesContext = AdfFacesContext.getCurrentInstance();
5: FacesContext ctx = FacesContext.getCurrentInstance();
6: FacesMessage fm =
7: new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, "");
8: ctx.addMessage(null, fm);
9: }

I created a simple page with a couple of buttons to show the result of setting the message. When the butto…