Create and set clientAttribute to ADF Faces component programmatically to pass value on client side JavaScript

Sharing is Caring
This post is next in series of “Working with ADF Faces Components programmatically“. So this post is about creating clientAttribute, applying it to component and setting its value programmatically.
this requirement comes in picture when the user is dealing with dynamic layout means components are created programmatically at runtime and it is not possible to apply clientAttribute and other properties declarativeIn this, I am extending my previous post –
Apply Client/Server listener to programmatically created components, apply JavaScript to ADF Faces components at runtime In the previous post I have described about applying client listener and server listener programmatically
here we will see how to pass a variable value to javascript function using client attribute
You can read more about af:clientAttribute hereFrom Oracle docs-
The clientAttribute tag specifies the name/value for an attribute which will both be made available both on the server-side (Faces) component as well on the client-side equivalent. This tag will be ignored for any server-rendered components, as it is only supported for the rich client. client attributes are not synchronized to the server since unknown attributes from the client are not synchronized to the server.

Lets’ see how we can do this, It’s simple just check this code –

//Code from previous post to create inputText programmatically 
        RichInputText ui = new RichInputText();
        ui.setValue("Programmatically Created Input Text");

Here i am not writing code to apply client/server listener again , refer previous post for that
See the code to add client attributes to component (inputText)

// A Set that contains all clientAttributes

java.util.Set<String> clientAttributes = new HashSet<String>();

// Add client attribute's name

//Add these attributes to a UI Compoenent

//here assign values to client attributes
ui.getAttributes().put("clientAttribute1", "Oracle ADF");
ui.getAttributes().put("clientAttribute2", 9999);
ui.getAttributes().put("clientAttribute3", "Ashish Awasthi");

So all done, now check it
For that, I have used this javascript method

function demoJsFunction(evt) {
  var comp = evt.getSource();

this method is called using client listener on input text and see the alert messages
First client attribute value-


Second client attribute value-

set clientAttribute

Third client attribute value-

So this is working 🙂
Cheers 🙂 Happy Learning

Related Posts

0 thoughts on “Create and set clientAttribute to ADF Faces component programmatically to pass value on client side JavaScript”

  1. Hello, Ashish!

    Is it possible to set javax.el.ValueExpression as attribute value through java code? I need it for programmatically created table with command components column where attribute value depends on row values.

  2. Found "solution":
    1. Programmatically create something like this:
    <af:button text="Button" actionListener="#{myBean.actionListener}" id="id1"/>
    <af:outputText text="#{myExpression}" id="id2" visible="false"/>

    2. ActionListener in java:
    public void actionListener(ActionEvent event){
    Integer rowIndex = null;
    for (UIComponent child : event.getComponent().getParent().getChildren()) {
    if (child instanceof RichOutputText) {
    rowIndex = (Integer)((RichOutputText) child).getValue();


    Still interested in more adequate solution.

Leave a Reply

Your email address will not be published. Required fields are marked *