Forum Stats

  • 3,782,325 Users
  • 2,254,637 Discussions
  • 7,880,045 Comments

Discussions

How to access UIComponents in backing bean using a table row.

Francisco Castanho
Francisco Castanho Member Posts: 30
edited Oct 18, 2016 11:08AM in JDeveloper and ADF

Hello everybody,

Since I've started using Oracle ADF, I'm having trouble accessing UIComponents from a RichTable.

I want to be able to access a specific UIComponent in a RichTable, my attempts to do this resulted in accessing all the components for that specific RichColumn instead.

This is a problem for me because I want to change, for example, the style for a specific component given a specific row and column.

Is it possible to do this?

I can access a specific component in a table using a change listener, but this does not suffice, as it only allows me to access the component where the event was generated.

Perhaps the solution to solve this problem is to use Javascript with the function findComponentByAbsoluteLocator.

Having the computed client id for that component provides info where it really resides in the page.

Using a javascript function, maybe it is possible to get the component using this computed id and then call a function from the backing bean that receives the component as a parameter.

Does anybody have a solution to this? It should be simple, and yet I cannot get a proper solution.

Thank you for your patience.

This is my jdev version: Studio Edition Version 11.1.2.4.0

Francisco Castanho

Best Answer

«1

Answers

  • Shemeer
    Shemeer Member Posts: 119 Bronze Badge
    edited Oct 6, 2016 8:28AM

    You can apply style the child components of RichTable through skinning or style class.

  • Francisco Castanho
    Francisco Castanho Member Posts: 30
    edited Oct 6, 2016 9:05AM

    I want to dynamically manipulate a specific component in my table. It does not have to be the style.

    Plus, does your answer really answer my question? What would be the result if I were to do what you have written?

    Hint: I know what would happen, so do not bother explaining it to me.

  • Francisco Castanho
    Francisco Castanho Member Posts: 30
    edited Oct 6, 2016 9:06AM

    Thanks for your effort anyway.

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,780 Red Diamond
    edited Oct 6, 2016 10:29AM

    The problem I see is that table components are stamped out. So the component position might change and you can't predict it's id as a refresh might change it.

    Can you elaborate on the use case a bit more?

    What would you like to change under which condition?

    May be a af:forEach or af:iterate can be used as it gives you more control, via the status variable, of whihc row or cell gets rendered.

    Timo

    Francisco Castanho
  • Francisco Castanho
    Francisco Castanho Member Posts: 30
    edited Oct 6, 2016 10:47AM

    Yes sir, indeed they are stamped.

    It is possible to obtain its cliendId, I will show you:

    An example for a richcommandbutton.

    Create it and create a binding. Don't forget to set clientComponent="true".

    Then create a function in your backing bean to obtain the client id:

    public String getButtonClientId(){

        FacesContext ctx = FacesContext.getCurrentInstance();

        return this.getClientButton().getClientId(ctx);

      }

    Inside your button add the following tags:

      <af:clientListener method="yourJavaScriptFunction" type="action"/>

      <af:clientAttribute name="myClientId"  value="#{backingBeanScope.examplePage.getButtonClientId}"/>

    Then add the following javascript function in your page as an af:resource:

    function yourJavaScriptFunction(actionEvent){

      var source = actionEvent.getSource();

      var dynamicClientId = actionComp.getProperty("myClientId");

      var obtainedComponent= AdfPage.PAGE.findComponentByAbsoluteId(dynamicClientId);

      //MAYBE THE SOLUTION TO MY PROBLEM IS TO OBTAIN ALL THE COMPONENTS USING THE CLIENTIDs FOR THE ROW AND SEND THEM AS PARAMETERS TO A BACKING BEAN FUNCTION.

    }

  • Francisco Castanho
    Francisco Castanho Member Posts: 30
    edited Oct 6, 2016 10:48AM

    Perhaps the solution is to send all the compoents using the client ids from the current row using the technique I have described in the last comment.

    And instead of using findComponentByAbsoluteId use findComponentByAbsoluteLocator.

    Remember that this button, as any other component, would reside inside a table and I want to access in my backing bean all the other components that are in the same row.

    Using the changelistener allows me to access the button itself only.

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,780 Red Diamond
    edited Oct 6, 2016 10:47AM

    I know that is possible, but that's not my point. The point is it's changing when you scroll, or better the cell you have to alter changes when you scroll.

    I still don't get what you try to do in the end. There might be a better way to archive your use case.

    Timo

  • Francisco Castanho
    Francisco Castanho Member Posts: 30
    edited Oct 6, 2016 10:55AM

    My use case is simple.

    I have multiple data in my table. Plus a check box and some editable components which eventually persist their data in the database.

    When I click this check box. I enable/disable the editable components.

    I want in this case to:

    When I check to enable all components, I want to add, lets say, a blue border in all the editable components for that row.

    When I click the "OK" button at the bottom of the page. I want, without using ADF error messages which result in showing ADF popups, to show a custom orange border in all invalid components for each specific row and to clear them.

    Thank your for your patience.

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,780 Red Diamond
    edited Oct 6, 2016 11:54AM

    I do have an idea how to solve this, but I cant find all pieces needed to implement it right now. Anyway, to give you some pointers

    My idea is that it's easier to let the framework handle all the hard part finding out which cell to style. You can style each cell of a table differently using an EL which either returns the color (or frame color) depending on a condition. IF you add transient attributes to the underlying data model (EO)  which you set by the button action (in the data model). This you check in the EL (or a bean method the EL is pointing to). You return the style you calculate like blue for cells which are editable, orange for cells which are invalid. A EL which address the row salary can look like

    50000"?'Aqua':'')}background-color:#{(row.salary eq "

    you can even add some custom properties to the EO attributes which you then use in the EL e.g. to find out if the attribute is editable

    this EL can be used to get access to such a property (the image above doesn't match the property created in the EO of the image above!)

    pastedImage_4.png

    So by setting the right flags into the underlying data it should be possible to implement your use case. This is just a rough script, but it should work.

    Timo

    Francisco CastanhoFrancisco Castanho
  • Francisco Castanho
    Francisco Castanho Member Posts: 30
    edited Oct 6, 2016 12:01PM

    You are telling me to do all the necessary validations using EL, and according to the EL result to do the proper modifications.

    It might work.

    My question is are EL validations done in the server or the client?

    What if I have complex validations which require a through analysis of what the table already has, for example: how do I do a primary key validation using EL?

    Cheers. You are being helpful.

This discussion has been closed.