Skip to main content

ADF 11g : Query Component with ‘dynamic’ view criteria

In my current project use a lot of re usable taskflows. In one particular situation I needed exactly the same taskflow to be re-used with one tiny small difference: The displayed query component needed to have different fields compared to page in the base taskflow. Now there are lots of possible solutions (two query components and a switcher, or two query components using the rendered property). I choose a different solution using ternary operator and EL in the page definition.

Use case

I need to display a different query component when the taskflow is started in a specific mode. For instance I can startup the taskflow a being a HR manager, or I can startup the taskflow as being an employee. In the first case I need to be able to search on items like salary and commission and hiredate. In the second case I need to be able to search on firstname. lastname and more stuff like that, and I can only see employees in my own department.

Setup:

Lets start with the creation of default business components for the Employee table. Next step is the creation of view criteria. I need two view criteria. The first one is called ManagerVC, the second on EmployeeVC.




With this in place I create a simple taskflow with a pagefragment. The taskflow has an inputParameter called 'startupMode'. The pagefragment contains a table with a query component. This is easy to create by dragging the Employees collection from the datacontrol onto the pagefragment and pick "query panel with table".



Make sure to have single row selection enabled.



I also create a testpage in order to run my taskflow. The testpage is a rather simple page containing two buttons, and a bean to hold the value of the button that is pushed.
 <af:toolbar id="t1">  
<af:commandToolbarButton text="Start as Manager" partialSubmit="true" id="ctb1">
<af:setPropertyListener from="mgr" to="#{TesterBean.buttonPushed}" type="action"/>
</af:commandToolbarButton>
<af:commandToolbarButton text="Start as Employee" id="ctb2"partialSubmit="true">
<af:setPropertyListener from="emp" to="#{TesterBean.buttonPushed}" type="action"/>
</af:commandToolbarButton>
</af:toolbar>

I drop my taskflow on the page as a region. I link the inputparameter of the taskflow to the buttonPushed property. Don't forget to set the refresh option to 'ifNeeded', so the region will refresh whenever the input paramaters change.



When I run the page you will see the querycomponent as expected.



The trick:
Now take a look what happened when the query component was created. The page definition states contains an executable binding for the search region.
 <searchRegion Criteria="CriteriaForManager"  
Customizer="oracle.jbo.uicli.binding.JUSearchBindingCustomizer"
Binds="EmployeesView1Iterator"
id="CriteriaForManagerQuery"/>

This is exactly the place where I will use an EL expression (yes you can do that) to dynamically set the viewcriteria to be used by the query component. Lets change the "criteria" attribute. Whenever the taskflow is started by a manager I want the CriteriaForManager viewcriteria to be used by the querycomponent, and in other cases the CriteriaForEmployee.
 <searchRegion Criteria="#{pageFlowScope.startupMode eq 'mgr' ? 'CriteriaForManager' : 'CriteriaForEmployee'}"  
Customizer="oracle.jbo.uicli.binding.JUSearchBindingCustomizer"
Binds="EmployeesView1Iterator"
id="CriteriaForManagerQuery"/>

Now this is really all I changed. No changes to the page whatsoever. When I run the page after this minor change, depending on the startupmode, a different querycomponent is rendered. Or actually, the querycomponent stays the same, only the viewcriteria used are different.



Resources:
This post was initially posted by me on the AMIS technology blog.
The workspace can be downloaded here.

Comments

Maiko Rocha said…
Great post!!
Maiko Rocha said…
Great post!!
Frank Nimphius said…
Very Nice !
karthick said…
Nice Post!

In the Search Query , We have ADD Fields button, Which lists all the columns available in the particular table. Can you pls explain how to customize them?

Say if there are 24 columns in a table and i want in the ADD Field column only 9 to be shown and the rest should not be visible.


KR
karthick said…
Nice Post!

In the Search Query , We have ADD Fields button, Which lists all the columns available in the particular table. Can you pls explain how to customize them?

Say if there are 24 columns in a table and i want in the ADD Field column only 9 to be shown and the rest should not be visible.


KR

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

How to: Adding Speech to Oracle Digital Assistant; Talk to me Goose

At Oracle Code One in October, and also on DOAG in Nurnberg Germany in November I presented on how to go beyond your regular chatbot. This presentation contained a part on exposing your Oracle Digital Assistant over Alexa and also a part on face recognition. I finally found the time to blog about it. In this blogpost I will share details of the Alexa implementation in this solution. Typically there are 3 area's of interest which I will explain. Webhook Code to enable communication between Alexa and Oracle Digital Assistant Alexa Digital Assistant (DA) Explaining the Webhook Code The overall setup contains of Alexa, a NodeJS webhook and an Oracle Digital Assistant. The webhook code will be responsible for receiving and transforming the JSON payload from the Alexa request. The transformed will be sent to a webhook configured on Oracle DA. The DA will send its response back to the webhook, which will transform into a format that can be used by an Alexa device. To code

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 but