⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rowactionselect.java

📁 IBM RSA下的JSF开发示例
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	protected HtmlOutputText getText24() {
		if (text24 == null) {
			text24 = (HtmlOutputText) findComponentInRoot("text24");
		}
		return text24;
	}

	protected UIColumn getColumn14() {
		if (column14 == null) {
			column14 = (UIColumn) findComponentInRoot("column14");
		}
		return column14;
	}

	protected HtmlOutputText getText26() {
		if (text26 == null) {
			text26 = (HtmlOutputText) findComponentInRoot("text26");
		}
		return text26;
	}

	protected UIColumn getColumn16() {
		if (column16 == null) {
			column16 = (UIColumn) findComponentInRoot("column16");
		}
		return column16;
	}

	protected HtmlOutputText getText28() {
		if (text28 == null) {
			text28 = (HtmlOutputText) findComponentInRoot("text28");
		}
		return text28;
	}

	protected UIColumn getColumn17() {
		if (column17 == null) {
			column17 = (UIColumn) findComponentInRoot("column17");
		}
		return column17;
	}

	protected HtmlOutputText getText30() {
		if (text30 == null) {
			text30 = (HtmlOutputText) findComponentInRoot("text30");
		}
		return text30;
	}

	protected UIColumn getColumn18() {
		if (column18 == null) {
			column18 = (UIColumn) findComponentInRoot("column18");
		}
		return column18;
	}

	protected HtmlOutputText getText32() {
		if (text32 == null) {
			text32 = (HtmlOutputText) findComponentInRoot("text32");
		}
		return text32;
	}

	protected UIColumn getColumn19() {
		if (column19 == null) {
			column19 = (UIColumn) findComponentInRoot("column19");
		}
		return column19;
	}

	protected HtmlOutputText getText34() {
		if (text34 == null) {
			text34 = (HtmlOutputText) findComponentInRoot("text34");
		}
		return text34;
	}

	protected UIColumn getColumn20() {
		if (column20 == null) {
			column20 = (UIColumn) findComponentInRoot("column20");
		}
		return column20;
	}

	protected HtmlOutputText getText36() {
		if (text36 == null) {
			text36 = (HtmlOutputText) findComponentInRoot("text36");
		}
		return text36;
	}

	protected ConnectionWrapper getSDOConnectionWrapper() {
		if (SDOConnectionWrapper == null) {
			try {
				Connection con = ConnectionManager
						.createJDBCConnection(SDOConnection_name);
				SDOConnectionWrapper = ConnectionWrapperFactory.soleInstance
						.createConnectionWrapper(con);
			} catch (Throwable e) {
				logException(e);
			}
		}
		return SDOConnectionWrapper;
	}

	/** 
	 * @action id=customers
	 */
	public String doCustomersUpdateAction() {
		try {
			getCustomersMediator().applyChanges(
					getRootDataObject(getCustomers()));
		} catch (Throwable e) {
			logException(e);
		} finally {
			try {
				if (SDOConnectionWrapper != null) {
					SDOConnectionWrapper.getConnection().close();
					SDOConnectionWrapper = null;
				}
			} catch (Throwable e1) {
				logException(e1);
			}
			if (customersMediator != null) {
				customersMediator.setConnectionWrapper(null);
			}
		}
		return "";
	}

	/** 
	 * @paramBean id=customers
	 */
	public DataObject getCustomersParameters() {
		if (customersParameters == null) {
			try {
				customersParameters = getCustomersMediator()
						.getParameterDataObject();
			} catch (MediatorException e) {
				logException(e);
			}
		}
		return customersParameters;
	}

	protected JDBCMediator getCustomersMediator() {
		if (customersMediator == null) {
			try {
				customersMediator = JDBCMediatorFactory.soleInstance
						.createMediator(
								getResourceInputStream(customers_metadataFileName),
								getSDOConnectionWrapper());
				initSchema(getRealPath(customers_metadataFileName),
						customersMediator.getSchema());
			} catch (Throwable e) {
				logException(e);
			}
		} else {
			customersMediator.setConnectionWrapper(getSDOConnectionWrapper());
		}
		return customersMediator;
	}

	/** 
	 * @action id=customers
	 */
	public String doCustomersFetchAction() {
		try {
			resolveParams(getCustomersParameters(), customersArgNames,
					customersArgValues, "customers_params_cache");
			DataObject graph = getCustomersMediator().getGraph(
					getCustomersParameters());
			customers = graph.getList(0);
		} catch (Throwable e) {
			logException(e);
		} finally {
			try {
				if (SDOConnectionWrapper != null) {
					SDOConnectionWrapper.getConnection().close();
					SDOConnectionWrapper = null;
				}
			} catch (Throwable e1) {
				logException(e1);
			}
			if (customersMediator != null) {
				customersMediator.setConnectionWrapper(null);
			}
		}
		return "";
	}

	/** 
	 * @mediatorFactory com.ibm.etools.sdo.rdb.datahandlers.RelationalDataFactory
	 * @mediatorProperties metadataFileName=/WEB-INF/wdo/customers.xml
	 * @methodEntry id=customers/paramBean=customers/action=customers
	 * @action FILL
	 */
	public List getCustomers() {
		if (customers == null) {
			doCustomersFetchAction();
		}
		return customers;
	}

	/** 
	 * @action id=orders
	 */
	public String doOrdersUpdateAction() {
		try {
			getOrdersMediator().applyChanges(getRootDataObject(getOrders()));
		} catch (Throwable e) {
			logException(e);
		} finally {
			try {
				if (SDOConnectionWrapper != null) {
					SDOConnectionWrapper.getConnection().close();
					SDOConnectionWrapper = null;
				}
			} catch (Throwable e1) {
				logException(e1);
			}
			if (ordersMediator != null) {
				ordersMediator.setConnectionWrapper(null);
			}
		}
		return "";
	}

	/** 
	 * @paramBean id=orders
	 */
	public DataObject getOrdersParameters() {
		if (ordersParameters == null) {
			try {
				ordersParameters = getOrdersMediator().getParameterDataObject();
			} catch (MediatorException e) {
				logException(e);
			}
		}
		return ordersParameters;
	}

	protected JDBCMediator getOrdersMediator() {
		if (ordersMediator == null) {
			try {
				ordersMediator = JDBCMediatorFactory.soleInstance
						.createMediator(
								getResourceInputStream(orders_metadataFileName),
								getSDOConnectionWrapper());
				initSchema(getRealPath(orders_metadataFileName), ordersMediator
						.getSchema());
			} catch (Throwable e) {
				logException(e);
			}
		} else {
			ordersMediator.setConnectionWrapper(getSDOConnectionWrapper());
		}
		return ordersMediator;
	}

	/** 
	 * @action id=orders
	 */
	public String doOrdersFetchAction() {
		try {
			resolveParams(getOrdersParameters(), ordersArgNames,
					ordersArgValues, "orders_params_cache");
			DataObject graph = getOrdersMediator().getGraph(
					getOrdersParameters());
			orders = graph.getList(0);
		} catch (Throwable e) {
			logException(e);
		} finally {
			try {
				if (SDOConnectionWrapper != null) {
					SDOConnectionWrapper.getConnection().close();
					SDOConnectionWrapper = null;
				}
			} catch (Throwable e1) {
				logException(e1);
			}
			if (ordersMediator != null) {
				ordersMediator.setConnectionWrapper(null);
			}
		}
		return "";
	}

	/** 
	 * @mediatorFactory com.ibm.etools.sdo.rdb.datahandlers.RelationalDataFactory
	 * @mediatorProperties metadataFileName=/WEB-INF/wdo/orders.xml
	 * @methodEntry id=orders/paramBean=orders/action=orders
	 * @action FILL
	 */
	public List getOrders() {
		if (orders == null) {
			doOrdersFetchAction();
		}
		return orders;
	}

	/** 
	 * @action id=selectRecords
	 */
	public String doSelectRecordsUpdateAction() {
		try {
			getSelectRecordsMediator().applyChanges(
					getRootDataObject(getSelectRecords()));
		} catch (Throwable e) {
			logException(e);
		} finally {
			try {
				if (SDOConnectionWrapper != null) {
					SDOConnectionWrapper.getConnection().close();
					SDOConnectionWrapper = null;
				}
			} catch (Throwable e1) {
				logException(e1);
			}
			if (selectRecordsMediator != null) {
				selectRecordsMediator.setConnectionWrapper(null);
			}
		}
		return "";
	}

	/** 
	 * @paramBean id=selectRecords
	 */
	public DataObject getSelectRecordsParameters() {
		if (selectRecordsParameters == null) {
			try {
				selectRecordsParameters = getSelectRecordsMediator()
						.getParameterDataObject();
			} catch (MediatorException e) {
				logException(e);
			}
		}
		return selectRecordsParameters;
	}

	protected JDBCMediator getSelectRecordsMediator() {
		if (selectRecordsMediator == null) {
			try {
				selectRecordsMediator = JDBCMediatorFactory.soleInstance
						.createMediator(
								getResourceInputStream(selectRecords_metadataFileName),
								getSDOConnectionWrapper());
				initSchema(getRealPath(selectRecords_metadataFileName),
						selectRecordsMediator.getSchema());
			} catch (Throwable e) {
				logException(e);
			}
		} else {
			selectRecordsMediator
					.setConnectionWrapper(getSDOConnectionWrapper());
		}
		return selectRecordsMediator;
	}

	/** 
	 * @action id=selectRecords
	 */
	public String doSelectRecordsFetchAction() {
		try {
			resolveParams(getSelectRecordsParameters(), selectRecordsArgNames,
					selectRecordsArgValues, "selectRecords_params_cache");
			DataObject graph = getSelectRecordsMediator().getGraph(
					getSelectRecordsParameters());
			selectRecords = graph.getList(0);
		} catch (Throwable e) {
			logException(e);
		} finally {
			try {
				if (SDOConnectionWrapper != null) {
					SDOConnectionWrapper.getConnection().close();
					SDOConnectionWrapper = null;
				}
			} catch (Throwable e1) {
				logException(e1);
			}
			if (selectRecordsMediator != null) {
				selectRecordsMediator.setConnectionWrapper(null);
			}
		}
		return "";
	}

	/** 
	 * @mediatorFactory com.ibm.etools.sdo.rdb.datahandlers.RelationalDataFactory
	 * @mediatorProperties metadataFileName=/WEB-INF/wdo/selectRecords.xml
	 * @methodEntry id=selectRecords/paramBean=selectRecords/action=selectRecords
	 * @action FILL
	 */
	public List getSelectRecords() {
		if (selectRecords == null) {
			doSelectRecordsFetchAction();
		}
		return selectRecords;
	}
	
	
	/** 
	 * @managed-bean true
	 */
	public RowSelectBean getSelectedRow() {
		if (selectedRow == null) {
			selectedRow = (RowSelectBean) getFacesContext().getApplication()
					.createValueBinding("#{selectedRow}").getValue(
							getFacesContext());
		}
		return selectedRow;
	}
	/** 
	 * @managed-bean true
	 */
	public void setSelectedRow(RowSelectBean selectedRow) {
		this.selectedRow = selectedRow;
	}
	
	/**
	 * Method to delete rows from Backing Bean - Exercise 1
	 * @return
	 */
	public String doButtonDelete1Action() {
		// Type Java code that runs when the component is clicked
		
		// calls the method in the Backing Bean to delete selected rows.
		selectedRow.deleteEmployee();
		
		return "";
	}
	
	/**
	 * Method to delete rows from a database using SDO - Exercise 2
	 * 
	 */
	public String doButtonDelete2Action() {
		// Type Java code that runs when the component is clicked
		
		// pull the array of int's out of the "selectRow" object which represent the selected rows.
		int[] rows = getSelectedRow().getIntRows();
		try {
			// move through the array and delete selected rows - each index of the array contains an
			// index of a Data Table selected row.
			for(int i = 0; i < rows.length; i++) {
				int row = rows[i];
					// pull out the DataObject at the selected index from the List of DataObjects
					// in the Table
					DataObject record = (DataObject)getSelectRecords().get(row - i);
				
					// get the root of the DataObject to be deleted
					DataObject root = record.getDataGraph().getRootObject();
				
					// delete the object
					record.delete();
					
					// apply the changes to the selectRecordsMediator
					getSelectRecordsMediator().applyChanges(root);
					getSelectedRow().setIntRows(new int[0]);	
			} 
		}catch (Throwable e) {
			logException(e);
		} finally {
			SDOConnectionWrapper = null;
		}
		return "";
	}
	

	
	/**
	 * Exercise 3 - Method to delete row from a database using SDO object
	 * @return
	 */
	public String doButtonDelete3Action() {
		// Type Java code that runs when the component is clicked
		
		// we pull the array of booleans out of the backing bean "selectedRow" - the array is the same length
		// as the data table and each selected row is marked as true
		boolean[] bRows = getSelectedRow().getBoolRows();
		int counter = 0;
		// go through the array and determine which booleans are set to true.
		for(int i = 0; i < bRows.length; i++) {
			if(bRows[i] == true) {
				// get the row index
				int row = i;
				try {
					// pull out the DataObject at the selected index from the List of DataObjects
					// in the Table
					DataObject record = (DataObject)getCustomers().get(row - counter);
					
					// find the root of that DataObject
					DataObject root = record.getDataGraph().getRootObject();
					
					// delete the DataObject
					record.delete();
					
					// apply the changes to the DataMediator
					getCustomersMediator().applyChanges(root);
					counter++;
				} catch (Throwable e) {
					logException(e);
				} finally {
					SDOConnectionWrapper = null;
				}
			}
		}
		getSelectedRow().setBoolRows(new boolean[50]);
		return "";
	}
	
	
	/**
	 * Exercise 4 - Method to delete row from a database using SDO object
	 * @return
	 */
	public String doButtonDelete4Action() {
		// Type Java code that runs when the component is clicked
		
		// pull the ArrayList out of the "selectedRow" object.
		ArrayList lRows = (ArrayList)getSelectedRow().getListRows();
		for(int i = 0; i < lRows.size(); i++) {
			
			// go through the ArrayList and pull out each Map object
			HashMap map = (HashMap)lRows.get(i);
			try{
				
			// pull out the first record and use that to find the root of the DataObjects
			DataObject record = (DataObject)getOrders().get(0);
			DataObject root = record.getDataGraph().getRootObject();
			
			// select the DataObject and delete it based on the parameter passed from the JSP
			// and stored in the map...map.get("ID")
			root.getDataObject("ORDERS[ID=" + map.get("ID") + "]").delete();
			
			// apply the changes to the dataMediator
			getOrdersMediator().applyChanges(root);
			} catch (Throwable e) {
				logException(e);
			} finally {
				SDOConnectionWrapper = null;
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -