Forum Stats

  • 3,838,105 Users
  • 2,262,332 Discussions
  • 7,900,506 Comments

Discussions

Trigger a backing bean method after selection on select one choice

MiguelPerez
MiguelPerez Member Posts: 35
edited Jan 10, 2010 9:09AM in JDeveloper and ADF
Hi all,

I'm new to Jdeveloper 11g, and I'm trying to trigger a method after the user makes a selection on a "select one choice" (JSF page).

I have a method (backing bean) that reads the selection and executes a procedure that retrieves some data and fills that on Input Text A and B, unfortunately this is implemented using an af: button and I would like this method to trigger automatically after the user makes the selection without clicking the button. Can you help me?

Thanks,

Mike.

Best Answer

  • Puthanampatti
    Puthanampatti Member Posts: 2,892 Silver Trophy
    edited Jan 9, 2010 11:51PM Answer ✓
    use valueChangeEvent and set selectOneChoice autoSubmit="true"
        public void selectOneChoice1_valueChangeListener(ValueChangeEvent valueChangeEvent) {
            if(valueChangeEvent.getNewValue() != null)
    	......          
            }	        
        }
    <af:selectOneChoice .............
     autoSubmit="true" 
     valueChangeListener="#{backingBeanScope.backing_TestPage.selectOneChoice1_valueChangeListener}"
    </af:selectOneChoice>

Answers

  • Puthanampatti
    Puthanampatti Member Posts: 2,892 Silver Trophy
    edited Jan 9, 2010 11:51PM Answer ✓
    use valueChangeEvent and set selectOneChoice autoSubmit="true"
        public void selectOneChoice1_valueChangeListener(ValueChangeEvent valueChangeEvent) {
            if(valueChangeEvent.getNewValue() != null)
    	......          
            }	        
        }
    <af:selectOneChoice .............
     autoSubmit="true" 
     valueChangeListener="#{backingBeanScope.backing_TestPage.selectOneChoice1_valueChangeListener}"
    </af:selectOneChoice>
  • Thanks for your response, your suggestion does what I asked, it fires the procedure but now the code does not work, for some reason the variable "clientListIndex" is null, but if I place the code in a method associated with a button it works. Any suggestion?

    public void onChangeCliente(ValueChangeEvent valueChangeEvent) throws SQLException {
    if(valueChangeEvent.getNewValue() != null){
    DCBindingContainer dcBinding =
    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCControlBinding listControlBinding =
    dcBinding.findCtrlBinding("NameSourceList");
    FacesCtrlListBinding listBinding = (FacesCtrlListBinding)listControlBinding;
    if (clientListIndex != null){
    Row row = listBinding.getRowAtRangeIndex(Integer.valueOf(clienteListIndex));
    String enquiryListCode = row.getAttribute("Cvecliente").toString();
    }
    else{
    System.out.println("null value");
    }
    }
  • Puthanampatti
    Puthanampatti Member Posts: 2,892 Silver Trophy
    edited Jan 10, 2010 12:38AM
    are you trying to fetch the selected value from selectOneChoice or you are trying to retrieve an attribute value from the iterator?

    if you only need selected value "valueChangeEvent.getNewValue()" would get it.

    Set selectOneChoice valuePassThru="true".

    Edited by: Puthanampatti on Jan 9, 2010 9:37 PM
  • MiguelPerez
    MiguelPerez Member Posts: 35
    Hey thanks so much, "valueChangeEvent.getNewValue()" gets the Index of selected item on select one choice, so I replaced the variable clientListIndex for "valueChangeEvent.getNewValue()" and the code works perfectly, unfortunately there's another issue, inside that Listener there's a line like:

    InputTextA.setNewValue(NewValue);

    Where new value has the value retrieved by reading the value from the select one choice and then executing a query that uses it to retrieve a value from another table.


    "NewValue" has the correct value, but the "setNewValue" is not working like if the inputText is not been refreshed, what's missing? I need to indicate that the inputTextA must be refreshed after making a selection on the select one choice?

    Thanks so much.
  • MiguelPerez
    MiguelPerez Member Posts: 35
    Got it,

    I had to set the partialTriggers on inputTextA to point to the selectOneChoice.

    Thanks so much.
This discussion has been closed.