This discussion is archived
11 Replies Latest reply: Oct 16, 2012 10:50 PM by Cvele_new_account RSS

How to select one row in a table with radio button

Baduel Newbie
Currently Being Moderated
Hi all.

I have a VO where there is an attribute (isDefault [String]) that identifies the default record in the view. The possible values are 'Y' for yes and 'N' for no. Obviously only one record can have the 'Y' value.

In my page I have created an ADF Table (with the usual data control drag & drop). I would to transform the default inputText of "isDefault" field with a selectOneRadio component in order to permit the user to select (and save contextually in the DB) the default row of this table.

Can you explain me how? I'm using JDeveloper 11.1.1.4.

Thanks in advance.

Baduel
  • 1. Re: How to select one row in a table with radio button
    KT Journeyer
    Currently Being Moderated
    Hi ,

    can you try this

    1)add transient attribute in vo of type Boolean

    2)make transient attribute value based on your default attribute value meaning that true if value 'Y' false if the value is 'N'

    3)Create ViewCriteria on VO where transient attribute value is true make sure that VC execute property to inmemory

    4)now drop the vo

    5)select table rows and in commandbutton action execute VC.

    make sure that in jspx select Booleanauto submit true



    Thanks,

    KT
  • 2. Re: How to select one row in a table with radio button
    Baduel Newbie
    Currently Being Moderated
    KT,

    thanks for your response. In which way can I perform step n. 2? In particular which value I have to fill in the transient attribute?

    Thanks again.

    Baduel
  • 3. Re: How to select one row in a table with radio button
    Frank Nimphius Employee ACE
    Currently Being Moderated
    Hi,

    Same principle as in here https://blogs.oracle.com/smuenchadf/resource/examples#117 applies

    Frank
  • 4. Re: How to select one row in a table with radio button
    Baduel Newbie
    Currently Being Moderated
    Frank,

    thanks for your response. I've downloaded the sample #117 from your link. In the SettingsViewRowImpl I read:

    private static Number ONE = new Number(1);
    private static Number ZERO = new Number(0);

    public Boolean getStatusAsBoolean() {
    return ONE.equals(getStatus());
    }

    public void setStatusAsBoolean(Boolean value) {
    setStatus(ONE.equals(value) ? ONE : ZERO);
    }

    but in the setter method the condition "ONE.equals(value)" will return always false (or better, a number cannot be equal to a boolean type). The correct methos should be:

    public void setStatusAsBoolean(Boolean value) {
    setStatus(value ? ONE : ZERO);
    }

    Am I wrong?

    Baduel

    P.s. How can I format code in this forum?
  • 5. Re: How to select one row in a table with radio button
    Baduel Newbie
    Currently Being Moderated
    Anyway, after the creation of the new transient attribute in which way I have to insert the radio button? Which is the correct component to use? And how?

    Please note that I would to insert a single radio button per row (in a column) and permit the user to select only one row.

    Thanks again.

    Baduel
  • 6. Re: How to select one row in a table with radio button
    Cvele_new_account Expert
    Currently Being Moderated
    - This is correct one:
       public void setStatusAsBoolean(Boolean value) {
         setStatus(value.booleanValue() ? ONE : ZERO);
       }
    >
    but in the setter method the condition "ONE.equals(value)" will return always false (or better, a number cannot be equal to a boolean type). The correct methos should be:

    public void setStatusAsBoolean(Boolean value) {
    setStatus(value ? ONE : ZERO);
    }
    Edited by: Cvele_new_account on Oct 13, 2012 9:17 AM
  • 7. Re: How to select one row in a table with radio button
    Cvele_new_account Expert
    Currently Being Moderated
    Would not it be easier to use af:selectBooleanCheckbox ?
    Just drop Boolean attribute on the form, and choose Single selection --> ADF Select Boolean Checkbox ...
    In the same dialog, you also have option to choose ADF Select One Radio...
  • 8. Re: How to select one row in a table with radio button
    Baduel Newbie
    Currently Being Moderated
    Cvele,

    thanks for your responses. Yes, it's easier to use af:selectBooleanCheckbox but I need that the selection is mutually exclusive (only one row can be selected). If this is possible also with the boolean checkbox please tell me how.

    If I drag & drop the Select One Radio component I will visualize two radio buttons per row (true or false) that are exclusive each other, but not with all the rows.

    Thanks,

    Baduel
  • 9. Re: How to select one row in a table with radio button
    Cvele_new_account Expert
    Currently Being Moderated
    Baduel wrote:
    Cvele,

    thanks for your responses. Yes, it's easier to use af:selectBooleanCheckbox but I need that the selection is mutually exclusive (only one row can be selected). >If this is possible also with the boolean checkbox please tell me how.
    - Let's try with CheckBox :

    1. At the ViewObjectImpl level (for example, YourViewObjectImpl), add the following code:
      private oracle.jbo.Key currSelectedRowKey = null;
    
      public void doRowSelection(Key newKey) {
          // de-select old one
          if (currSelectedRowKey != null) {
              Row[] rows = findByKey(currSelectedRowKey,  1);
              if (rows != null && rows.length > 0)
                   rows[0].setStatusAsBoolean(Boolean.FALSE); // cast to the appropriate row Impl class if need !
          }
         // remember a new selected row key:
        currSelectedRowKey = newKey;
      }
    In the ViewRowImpl, in the transient attr settter, do as follows:
      public void setStatusAsBoolean(Boolean value) {
         setStatus(value.booleanValue() ? ONE : ZERO);
         if (value.booleanValue()) {
             YourViewObjectImpl vo = (YourViewObjectImpl)getViewObject();
             vo.doRowSelection(getKey());
         }
       }   
    P.S. The above was not tested at all, but should give you an idea
  • 10. Re: How to select one row in a table with radio button
    Baduel Newbie
    Currently Being Moderated
    Cvele,

    with the boolean checkbox your solution doesn't work (user can check more than one box). Anyway with the boolean radio using the attribute group I'm able to perform this feature. Only one problem. If the attribute editing mode in the af:table is "clickToEdit" I don't see the radio button for the unselected rows. With "editAll", instead, I see correctly all the buttons but no one is selected (also if in the DB I have one record set to default). Notice that with "clickToEdit" I see correctly the checked value.

    Here my code:

    jspx:

    <af:table [...] editingMode="clickToEdit">
    [many columns]

    <af:column [...]>
    <af:selectBooleanRadio label="label" id="sbr1"
    group="default"
    value="#{row.bindings.IsDefault.inputValue}"/>

    </af:column>
    </af:table>

    pageDef:

    <button IterBinding="MyIterator"
    id="IsDefault" DTSupportsMRU="false" StaticList="true">
    <AttrNames>
    <Item Value="IsDefault"/>
    </AttrNames>
    <ValueList>
    <Item Value="Y"/>
    <Item Value="N"/>
    </ValueList>
    </button>

    P.s. How can I format code in this forum?

    Thanks.

    Baduel

    Edit: Resolved with "editAll" inserting a partial trigger on the af:component (is a detail table, while the query refers to the master table). With the "clickToEdit" the problem persists.

    Edited by: Baduel on Oct 16, 2012 3:18 AM
  • 11. Re: How to select one row in a table with radio button
    Cvele_new_account Expert
    Currently Being Moderated
    Cvele, with the boolean checkbox your solution doesn't work (user can check more than one box).

    - So, it should work. Make check box autoSubmit, and, in the valueChangeListener for that check box, refresh (addPartialTarget()) whole af:table.
    Also, in the pageDef, you should have something like that:
        <tree IterBinding=...>
          <nodeDefinition DefName= ...>
            <AttrNames>
                 .....
              <Item Value="Boolean...whatever" Binds="Boolean...whatever"/>
                ....
            </AttrNames>
          </nodeDefinition>
        </tree>
    
        <button id="Boolean...whatever">
          <AttrNames>
            <Item Value="Boolean...whatever"/>
          </AttrNames>
          <ValueList>
            <Item Value="true"/> 
            <Item Value="false"/>
          </ValueList>
        </button>  

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points