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.
Hi,
ReplyDeleteI'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
I, also, am a little worried about this problem. You should do a forcing in the method so it stops returning null.
ReplyDeleteP.
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.
ReplyDeleteYour writing has been surprised me. You blog is looking like a very great and awesome
ReplyDeleteThanks for sharing this very nice article here.