Reset Binding Value from InputText in Oracle ADF

Use Case – We have one jsff page and contains some inputtext .On same page there is one Save button and one Cancel button.When user came to the page and try to enter some value in input text field and user click on Cancel button, its not resetting InputText value.When user come on same page again then he can able to see my previously entered value in Input Text though user clicked on cancel.

Normal developer will wrote Action Listener on Cancel Button and wrote below code

input.resetValue() ;
adfFacesContext.addPartialTarget(input);

But its will work (reset values).Setting value in input will not work like

input.setValue(null);
or
input.setValue("");

Few developers will think, why cant we use resetActionListener. It will work for sure,but if you make autoSubmit of inputText to true, it will not work.
Reason- InputText has autoSubmit set to true, which submit the values to model immediately after updating it, resetActionListener resets values only if changes are not populated to model.

For this case use below code.Get current row and do REFRESH_FORGET_NEW_ROWS

    Row r1=vo.getCurrentRow(); 
    r1.refresh(oracle.jbo.Row.REFRESH_UNDO_CHANGES |  Row.REFRESH_FORGET_NEW_ROWS);  
or 
    r1.refresh(r1.REFRESH_UNDO_CHANGES | r1.REFRESH_WITH_DB_FORGET_CHANGES);   

Note : If you don’t need autoSubmit, you can just remove it and use resetActionListener without any bean method to undo current row changes

It will reset binding value of input text.

Happy learning with Vinay Kumar in techartifact..

Get value of the outputtext in javascript and access to backing bean in Oracle ADF

Requirement -Get value of the outputtext in javascript and send it to backing bean in Oracle ADF
Solution – We will use clientListener to call java script function and Serverlistener for calling java function

Below is the code for accomplish this

– page code

    <af:outputText value="value outputText" id="ot32" clientComponent="true"
                    shortDesc="shortDesc">
        <af:clientListener type="mouseOver"
                method="customJsFunction"/>
        <af:serverListener type="mycustomserverEvent" method="#{OutputTextCase11.handleServerEvent}"/>                
    </af:outputText>
    <br></br>
    <af:outputText value="Init" shortDesc="shortDesc" id="ot1" clientComponent="true"/>
 

– find javascript function code

   var customJsFunction = function(event)
   {
      var exceptiondata = event.getSource().findComponent("ot32").getValue();
      AdfCustomEvent.queue(event.getSource(),
                       "mycustomserverEvent",
                       {param1:exceptiondata},
                       true);
      return true;
   }
 

– method in bean

  public void handleServerEvent(ClientEvent ce)
  {
    String param = (String)ce.getParameters().get("param1");
    RichOutputText outputText=(RichOutputText)ce.getComponent().findComponent("ot1");
    outputText.setShortDesc(param);
    outputText.setValue(param);
    AdfFacesContext.getCurrentInstance().addPartialTarget(outputText);
  }
 

happy coding with Vinay in techartifact….