Saturday, October 30, 2010

ADF UI - Executing the AMImpl method in UI project's java bean which is added as methodAction in pagedef file

Once we write the methods in AMImpl class and expose them in client's interface, they are available under data controls and can be included as 'methodAction' operation bindings in the pagedef files of JSF pages. Now, the question is how to execute this method binding in java bean. The method can be simple void method without any arguments, or it can have arguments with some return type. Below is the sample code to execute AMImpl's method(which is added as methodAction in pagedef file) in java beean.

public void saveSections(ActionEvent ae) { DCBindingContainer bindings = (DCBindingContainer)ADFUtil.evaluateEL("#{bindings}"); //method without parameters OperationBinding opBinding = bindings.getOperationBinding("saveClassSections"); opBinding.execute(); if (opBinding.getErrors().size() == 0) { PopupUtil.invokePopup(confirmationPopup.getClientId(FacesContext.getCurrentInstance())); } } public void classChanged(ValueChangeEvent valueChangeEvent) { DCBindingContainer bindings = (DCBindingContainer)ADFUtil.evaluateEL("#{bindings}"); //method that takes one parameter OperationBinding opBinding = bindings.getOperationBinding("setNoOfPeriods"); opBinding.getParamsMap().put("classCode",valueChangeEvent.getNewValue()); opBinding.execute(); noOfPeriodsDisabled = false; sectionsTableRendered = false; }

Please not that the OperationBinding that we need to import for the above method code is:
import oracle.binding.OperationBinding;

The above two AM methods "saveClassSections" and "setNoOfPeriods" are be included in pagedef as methodAction bindings as below:
<methodAction id="saveClassSections" InstanceName="GreatSchoolsAMDataControl.dataProvider" DataControl="GreatSchoolsAMDataControl" RequiresUpdateModel="true" Action="invokeMethod" MethodName="saveClassSections" IsViewObjectMethod="false"/> <methodAction id="setNoOfPeriods" InstanceName="GreatSchoolsAMDataControl.dataProvider" DataControl="GreatSchoolsAMDataControl" RequiresUpdateModel="true" Action="invokeMethod" MethodName="setNoOfPeriods" IsViewObjectMethod="false"> <NamedData NDName="classCode" NDType="java.lang.String"/> </methodAction>

The actual definitions for these methods in AMImpl are as below and these are exposed in client's interface.

public void saveClassSections() { ViewObjectImpl tVO = getClassSubjectTeacherTVO(); String classCode = (String)tVO.getCurrentRow().getAttribute("ClassCode"); ViewObjectImpl csVO = getClassSectionVO(); ViewObjectImpl lookupsPVO = getLookupsPVO(); Row[] sections = lookupsPVO.getAllRowsInRange(); for (int i = 0; i < sections.length; i++) { Row section = sections[i]; if ((Boolean)section.getAttribute("selected")) { Row csRow = csVO.createRow(); csRow.setAttribute("ClassCode", classCode); csRow.setAttribute("SectionCode", section.getAttribute("LookupCode")); csVO.insertRow(csRow); } } this.getDBTransaction().commit(); } public void setNoOfPeriods(String classCode) { ViewObjectImpl tVO = getClassSubjectTeacherTVO(); ViewObjectImpl csVO = getClassSectionVO(); csVO.setApplyViewCriteriaName("findByClassCode"); csVO.setNamedWhereClauseParam("Bind_ClassCode", classCode); csVO.executeQuery(); csVO.setRangeSize(-1); if (csVO.getAllRowsInRange().length > 0) { tVO.getCurrentRow().setAttribute("NoOfPeriods", csVO.first().getAttribute("NoOfPeriods")); } else{ tVO.getCurrentRow().setAttribute("NoOfPeriods",null); } }

There is another way of invoking AMImpl's methods from Java bean using EL expressions using the util methods in ADFUtil class. ADFUtil class and using the util methods in it has been explained in this post.


  1. Hi,

    I'm trying to execute your sample code with my model. Although, myVO.getCurrentRow() always returns null.

    When you execute tVO.getCurrentRow() is this happening to you?

    Thanks, Paulo Pausão

  2. I, also, am a little worried about this problem. You should do a forcing in the method so it stops returning null.


  3. very excellent and enjoy full post. This is really interesting. I will share this with my friends and other members. Thanks for sharing with us. Kindly keep posting more amazing posts.

  4. Your writing has been surprised me. You blog is looking like a very great and awesome
    Thanks for sharing this very nice article here.


Related Posts with Thumbnails