Using the Form Tree Component
Steps to use the tree form component:
Create an SQL Map as a source of data for the tree form component. Refer Writing the SQLMap File and Instruction Class for reference. The following is a sample SQL Map that fetches details of a bank account from the ACCOUNT_SUMMARY_DATA table.
<resultMap id="GET_ACC_DETAILS" class="java.util.HashMap"> <result property="ACCOUNT_NO" nullValue="" column="ACCOUNT_NO" javaType="java.lang.String" jdbcType="VARCHAR2"/> <result property="ACCOUNT_TYPE" nullValue="" column="ACCOUNT_TYPE" javaType="java.lang.String" jdbcType="VARCHAR2"/> <result property="AVAI_BALANCE" nullValue="" column="AVAI_BALANCE" javaType="java.lang.Float" jdbcType="NUMBER"/> <result property="STATUS" nullValue="" column="STATUS" javaType="java.lang.String" jdbcType="VARCHAR2"/> <result property="UNCLEARED_FUND" nullValue="" column="UNCLEARED_FUND" javaType="java.lang.Float" jdbcType="NUMBER"/> <result property="OVER_DRAFT_LMT" nullValue="" column="OVER_DRAFT_LMT" javaType="java.lang.Float" jdbcType="NUMBER"/> <result property="CURRENCY" nullValue="" column="CURRENCY" javaType="java.lang.String" jdbcType="VARCHAR2"/> <result property="ACCOUNT_NAME" nullValue="" column="ACCOUNT_NAME" javaType="java.lang.String" jdbcType="VARCHAR2"/> </resultMap> <select id="GET_ACC_DETAILS_SELECT_LEVELONE_QRY" resultMap="GET_ACC_DETAILS"> SELECT DISTINCT ACCOUNT_NO, ACCOUNT_TYPE, AVAI_BALANCE, STATUS, UNCLEARED_FUND, OVER_DRAFT_LMT, CURRENCY, ACCOUNT_NAME FROM ACCOUNT_SUMMARY_DATA </select> <select id="GET_ACC_DETAILS_SELECT_LEVELTWO_QRY" resultMap="GET_ACC_DETAILS"> SELECT DISTINCT ACCOUNT_NO, ACCOUNT_TYPE, AVAI_BALANCE, STATUS, UNCLEARED_FUND, OVER_DRAFT_LMT, CURRENCY, ACCOUNT_NAME FROM ACCOUNT_SUMMARY_DATA WHERE ACCOUNT_NO = #ACCOUNT_NO# ORDER BY ACCOUNT_TYPE </select> <select id="GET_ACC_DETAILS_SELECT_LEVELTHREE_QRY" resultMap="GET_ACC_DETAILS"> SELECT ACCOUNT_NO, ACCOUNT_TYPE, AVAI_BALANCE, STATUS, UNCLEARED_FUND, OVER_DRAFT_LMT, CURRENCY, ACCOUNT_NAME FROM ACCOUNT_SUMMARY_DATA WHERE ACCOUNT_NO = #ACCOUNT_NO# and ACCOUNT_TYPE = #ACCOUNT_TYPE# </select>
- In Form Designer, in the left pane under Containers & More, click the tree form component ().
- Change the component name as per requirement.
Specify the data support class to point to the Java class to fetch data for the tree form component.
Place your data support class file in the application project folder.
For example, D:\Canvas\apache-tomcat-8.5.9\webapps\ctmodelhouse\WEB-INF\lib\CTModelHouseLib.jar\com\intellectdesign\modelhouse\dataSupportThe following is a sample data support class that fetches values from SQL Map and stores in tree form component.
package com.intellectdesign.modelhouse.dataSupport; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.intellectdesign.canvas.database.DatabaseConstants; import com.intellectdesign.canvas.database.DatabaseException; import com.intellectdesign.canvas.database.DatabaseRequest; import com.intellectdesign.canvas.database.DatabaseResult; import com.intellectdesign.canvas.formdefinition.FormDefinitionException; import com.intellectdesign.canvas.formdefinition.FormItemDefinition; import com.intellectdesign.canvas.formdefinition.addinfo.AdditionalDataCodeValue; import com.intellectdesign.canvas.formdefinition.addinfo.IAdditionalDataSupport; import com.intellectdesign.canvas.value.IUserValue; public class TreeComponentDataSupport implements IAdditionalDataSupport { @Override public List<AdditionalDataCodeValue> getAdditionalDataFor(FormItemDefinition itemDefn, IUserValue userValue, Map inputParams) throws FormDefinitionException { ArrayList<AdditionalDataCodeValue> resultList = null; DatabaseRequest dbRequest = null; DatabaseResult dbResult = null; List accountType = null; List accountList = new ArrayList(); try { dbRequest = new DatabaseRequest(); dbResult = new DatabaseResult(); dbRequest.setDataAccessMapKey("GET_ACC_DETAILS"); dbRequest.setOperation(DatabaseConstants.SELECT); dbRequest.setOperationExtension("LEVELONE_QRY"); dbResult = dbRequest.execute(); accountType = dbResult.getReturnedList(); java.util.Iterator iter = accountType.iterator(); while(iter.hasNext()) { Map prdMap = new HashMap<>(); HashMap resultMap = (HashMap) iter.next(); String accountNo = (String) resultMap.get("ACCOUNT_NO"); System.out.println(accountNo); prdMap.put("text", accountNo); prdMap.put("id", accountNo); prdMap.put("level", 0); prdMap.put("parent", true); prdMap.put("nodes", getAccountTyeList(accountNo)); accountList.add(prdMap); } } catch (DatabaseException dbExcep) { throw new FormDefinitionException(dbExcep); } return accountList; } public List getAccountTyeList(String accountNo) { List accTypeRsltList = null; DatabaseRequest dbRequest = null; DatabaseResult dbResult = null; List accTypeList = new ArrayList(); List accTypeDescList = new ArrayList(); HashMap subprodMap = new HashMap(); try { dbRequest = new DatabaseRequest(); dbRequest.setDataAccessMapKey("GET_ACC_DETAILS"); //TODO Level 2 dbRequest.setOperation(DatabaseConstants.SELECT); dbRequest.setOperationExtension("LEVELTWO_QRY"); dbRequest.addFilter("ACCOUNT_NO", accountNo); dbResult = dbRequest.execute(); accTypeRsltList = dbResult.getReturnedList(); java.util.Iterator iter = accTypeRsltList.iterator(); while (iter.hasNext()) { Map accTypeMap = new HashMap<>(); HashMap resultMap = (HashMap) iter.next(); String accountType = (String) resultMap.get("ACCOUNT_TYPE"); accTypeMap.put("text", accountType); accTypeMap.put("id", accountType); List nodes = getAccountStatus(accountNo, accountType); if(nodes.size() > 0) accTypeMap.put("nodes", nodes); accTypeList.add(accTypeMap); } }catch (DatabaseException dbExp) { System.out.println(dbExp); } catch (Exception ex) { System.out.println(ex); } return accTypeList; } public List getAccountStatus(String accountNo, String accountType) { List functionRsltList = null; DatabaseRequest dbRequest = null; DatabaseResult dbResult = null; List functionList = new ArrayList(); List functionDescList = new ArrayList(); HashMap functionMap = new HashMap(); try { dbRequest = new DatabaseRequest(); dbRequest.setDataAccessMapKey("GET_ACC_DETAILS"); dbRequest.setOperation(DatabaseConstants.SELECT); dbRequest.setOperationExtension("LEVELTHREE_QRY"); dbRequest.addFilter("ACCOUNT_NO", accountNo); dbRequest.addFilter("ACCOUNT_TYPE", accountType); dbResult = dbRequest.execute(); functionRsltList = dbResult.getReturnedList(); java.util.Iterator iter = functionRsltList.iterator(); while (iter.hasNext()) { Map funcMap = new HashMap<>(); HashMap resultMap = (HashMap) iter.next(); String accStatus = (String) resultMap.get("STATUS"); funcMap.put("text", accStatus); funcMap.put("id", accStatus); functionList.add(funcMap); } } catch (DatabaseException dbExp) { System.out.println(dbExp); } catch (Exception ex) { System.out.println(ex); } return functionList; } }