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

📄 addrecord.java

📁 IBM RSA下的JSF开发示例
💻 JAVA
字号:
/**
 * 
 */
package pagecode.addRecord;

import pagecode.PageCodeBase;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlInputText;
import javax.faces.component.UIColumn;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlDataTable;
import java.util.List;
import com.ibm.websphere.sdo.access.connections.ConnectionManager;
import com.ibm.websphere.sdo.mediator.jdbc.ConnectionWrapperFactory;
import com.ibm.websphere.sdo.mediator.jdbc.ConnectionWrapper;
import com.ibm.websphere.sdo.mediator.JDBCMediator;
import com.ibm.websphere.sdo.mediator.exception.MediatorException;
import com.ibm.websphere.sdo.mediator.jdbc.JDBCMediatorFactory;
import commonj.sdo.DataObject;
import java.sql.Connection;
import com.ibm.faces.component.html.HtmlScriptCollector;
import com.ibm.faces.component.html.HtmlCommandExButton;

/**
 * @author nan
 *
 */
public class AddRecord extends PageCodeBase {

	protected HtmlForm form1;
	protected HtmlInputText nameInput;
	protected HtmlInputText mathInput;
	protected HtmlInputText scienceInput;
	protected HtmlInputText historyInput;
	protected HtmlInputText writingInput;
	protected HtmlInputText artInput;
	protected UIColumn column1;
	protected HtmlOutputText text8;
	protected HtmlOutputText text10;
	protected HtmlOutputText text12;
	protected HtmlOutputText text14;
	protected HtmlOutputText text16;
	protected HtmlOutputText text18;
	protected HtmlOutputText text20;
	protected HtmlDataTable table1;
	protected HtmlOutputText text9;
	protected UIColumn column2;
	protected HtmlOutputText text11;
	protected UIColumn column3;
	protected HtmlOutputText text13;
	protected UIColumn column4;
	protected HtmlOutputText text15;
	protected UIColumn column5;
	protected HtmlOutputText text17;
	protected UIColumn column6;
	protected HtmlOutputText text19;
	protected UIColumn column7;
	protected HtmlOutputText text21;
	private static final String SDOConnection_name = "JSFandSDO_Con";
	private ConnectionWrapper SDOConnectionWrapper;
	protected DataObject viewRecordsParameters;
	protected JDBCMediator viewRecordsMediator;
	private static final String viewRecords_metadataFileName = "/WEB-INF/wdo/viewRecords.xml";
	private static final int viewRecordsTargetPageSize = -1;
	protected List viewRecords;
	protected static final String[] viewRecordsArgNames = {};
	protected static final String[] viewRecordsArgValues = {};
	protected DataObject addRecordParameters;
	protected JDBCMediator addRecordMediator;
	private static final String addRecord_metadataFileName = "/WEB-INF/wdo/addRecord.xml";
	protected DataObject addRecord;
	protected static final String[] addRecordArgNames = {};
	protected static final String[] addRecordArgValues = {};
	protected HtmlScriptCollector scriptCollector1;
	protected HtmlCommandExButton button1;

	protected HtmlForm getForm1() {
		if (form1 == null) {
			form1 = (HtmlForm) findComponentInRoot("form1");
		}
		return form1;
	}

	protected HtmlInputText getNameInput() {
		if (nameInput == null) {
			nameInput = (HtmlInputText) findComponentInRoot("nameInput");
		}
		return nameInput;
	}

	protected HtmlInputText getMathInput() {
		if (mathInput == null) {
			mathInput = (HtmlInputText) findComponentInRoot("mathInput");
		}
		return mathInput;
	}

	protected HtmlInputText getScienceInput() {
		if (scienceInput == null) {
			scienceInput = (HtmlInputText) findComponentInRoot("scienceInput");
		}
		return scienceInput;
	}

	protected HtmlInputText getHistoryInput() {
		if (historyInput == null) {
			historyInput = (HtmlInputText) findComponentInRoot("historyInput");
		}
		return historyInput;
	}

	protected HtmlInputText getWritingInput() {
		if (writingInput == null) {
			writingInput = (HtmlInputText) findComponentInRoot("writingInput");
		}
		return writingInput;
	}

	protected HtmlInputText getArtInput() {
		if (artInput == null) {
			artInput = (HtmlInputText) findComponentInRoot("artInput");
		}
		return artInput;
	}

	protected UIColumn getColumn1() {
		if (column1 == null) {
			column1 = (UIColumn) findComponentInRoot("column1");
		}
		return column1;
	}

	protected HtmlOutputText getText8() {
		if (text8 == null) {
			text8 = (HtmlOutputText) findComponentInRoot("text8");
		}
		return text8;
	}

	protected HtmlOutputText getText10() {
		if (text10 == null) {
			text10 = (HtmlOutputText) findComponentInRoot("text10");
		}
		return text10;
	}

	protected HtmlOutputText getText12() {
		if (text12 == null) {
			text12 = (HtmlOutputText) findComponentInRoot("text12");
		}
		return text12;
	}

	protected HtmlOutputText getText14() {
		if (text14 == null) {
			text14 = (HtmlOutputText) findComponentInRoot("text14");
		}
		return text14;
	}

	protected HtmlOutputText getText16() {
		if (text16 == null) {
			text16 = (HtmlOutputText) findComponentInRoot("text16");
		}
		return text16;
	}

	protected HtmlOutputText getText18() {
		if (text18 == null) {
			text18 = (HtmlOutputText) findComponentInRoot("text18");
		}
		return text18;
	}

	protected HtmlOutputText getText20() {
		if (text20 == null) {
			text20 = (HtmlOutputText) findComponentInRoot("text20");
		}
		return text20;
	}

	protected HtmlDataTable getTable1() {
		if (table1 == null) {
			table1 = (HtmlDataTable) findComponentInRoot("table1");
		}
		return table1;
	}

	protected HtmlOutputText getText9() {
		if (text9 == null) {
			text9 = (HtmlOutputText) findComponentInRoot("text9");
		}
		return text9;
	}

	protected UIColumn getColumn2() {
		if (column2 == null) {
			column2 = (UIColumn) findComponentInRoot("column2");
		}
		return column2;
	}

	protected HtmlOutputText getText11() {
		if (text11 == null) {
			text11 = (HtmlOutputText) findComponentInRoot("text11");
		}
		return text11;
	}

	protected UIColumn getColumn3() {
		if (column3 == null) {
			column3 = (UIColumn) findComponentInRoot("column3");
		}
		return column3;
	}

	protected HtmlOutputText getText13() {
		if (text13 == null) {
			text13 = (HtmlOutputText) findComponentInRoot("text13");
		}
		return text13;
	}

	protected UIColumn getColumn4() {
		if (column4 == null) {
			column4 = (UIColumn) findComponentInRoot("column4");
		}
		return column4;
	}

	protected HtmlOutputText getText15() {
		if (text15 == null) {
			text15 = (HtmlOutputText) findComponentInRoot("text15");
		}
		return text15;
	}

	protected UIColumn getColumn5() {
		if (column5 == null) {
			column5 = (UIColumn) findComponentInRoot("column5");
		}
		return column5;
	}

	protected HtmlOutputText getText17() {
		if (text17 == null) {
			text17 = (HtmlOutputText) findComponentInRoot("text17");
		}
		return text17;
	}

	protected UIColumn getColumn6() {
		if (column6 == null) {
			column6 = (UIColumn) findComponentInRoot("column6");
		}
		return column6;
	}

	protected HtmlOutputText getText19() {
		if (text19 == null) {
			text19 = (HtmlOutputText) findComponentInRoot("text19");
		}
		return text19;
	}

	protected UIColumn getColumn7() {
		if (column7 == null) {
			column7 = (UIColumn) findComponentInRoot("column7");
		}
		return column7;
	}

	protected HtmlOutputText getText21() {
		if (text21 == null) {
			text21 = (HtmlOutputText) findComponentInRoot("text21");
		}
		return text21;
	}

	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=viewRecords
	 */
	public String doViewRecordsUpdateAction() {
		try {
			getViewRecordsMediator().applyChanges(
					getRootDataObject(getViewRecords()));
		} catch (Throwable e) {
			logException(e);
		} finally {
			try {
				if (SDOConnectionWrapper != null) {
					SDOConnectionWrapper.getConnection().close();
					SDOConnectionWrapper = null;
				}
			} catch (Throwable e1) {
				logException(e1);
			}
			if (viewRecordsMediator != null) {
				viewRecordsMediator.setConnectionWrapper(null);
			}
		}
		return "";
	}

	/** 
	 * @paramBean id=viewRecords
	 */
	public DataObject getViewRecordsParameters() {
		if (viewRecordsParameters == null) {
			try {
				viewRecordsParameters = getViewRecordsMediator()
						.getParameterDataObject();
			} catch (MediatorException e) {
				logException(e);
			}
		}
		return viewRecordsParameters;
	}

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

	/** 
	 * @action id=viewRecords
	 */
	public String doViewRecordsFetchAction() {
		try {
			resolveParams(getViewRecordsParameters(), viewRecordsArgNames,
					viewRecordsArgValues, "viewRecords_params_cache");
			DataObject graph = getViewRecordsMediator().getGraph(
					getViewRecordsParameters());
			viewRecords = graph.getList(0);
		} catch (Throwable e) {
			logException(e);
		} finally {
			try {
				if (SDOConnectionWrapper != null) {
					SDOConnectionWrapper.getConnection().close();
					SDOConnectionWrapper = null;
				}
			} catch (Throwable e1) {
				logException(e1);
			}
			if (viewRecordsMediator != null) {
				viewRecordsMediator.setConnectionWrapper(null);
			}
		}
		return "";
	}

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

	/** 
	 * @action id=addRecord
	 */
	public String doAddRecordUpdateAction() {
		try {
			getAddRecordMediator().applyChanges(
					getRootDataObject(getAddRecord()));
		} catch (Throwable e) {
			logException(e);
		} finally {
			try {
				if (SDOConnectionWrapper != null) {
					SDOConnectionWrapper.getConnection().close();
					SDOConnectionWrapper = null;
				}
			} catch (Throwable e1) {
				logException(e1);
			}
			if (addRecordMediator != null) {
				addRecordMediator.setConnectionWrapper(null);
			}
		}
		//// update the view records
		doViewRecordsFetchAction();
		return "";
	}

	/** 
	 * @paramBean id=addRecord
	 */
	public DataObject getAddRecordParameters() {
		if (addRecordParameters == null) {
			try {
				addRecordParameters = getAddRecordMediator()
						.getParameterDataObject();
			} catch (MediatorException e) {
				logException(e);
			}
		}
		return addRecordParameters;
	}

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

	/** 
	 * @mediatorFactory com.ibm.etools.sdo.rdb.datahandlers.RelationalDataFactory
	 * @mediatorProperties metadataFileName=/WEB-INF/wdo/addRecord.xml
	 * @methodEntry id=addRecord/paramBean=addRecord/action=addRecord
	 * @action CREATE
	 */
	public DataObject getAddRecord() {
		if (addRecord == null) {
			doAddRecordCreateAction();
		}
		return addRecord;
	}

	/** 
	 * This method was created in order to create new data.  To retrieve existing data:
	 *   DataObject graph = getAddRecordMediator().getGraph( getAddRecordParameters() );
	 *   addRecord = (DataObject)graph.getList(0).get(0);  
	 *
	 * @action id=addRecord
	 */
	public String doAddRecordCreateAction() {
		try {
			resolveParams(getAddRecordParameters(), addRecordArgNames,
					addRecordArgValues, "addRecord_params_cache");
			DataObject graph = getAddRecordMediator().getEmptyGraph();
			addRecord = graph.createDataObject(0);
			autoGenerateKey(addRecord, getAddRecordMediator(),
					getRealPath(addRecord_metadataFileName));
		} catch (Throwable e) {
			logException(e);
		} finally {
			try {
				if (SDOConnectionWrapper != null) {
					SDOConnectionWrapper.getConnection().close();
					SDOConnectionWrapper = null;
				}
			} catch (Throwable e1) {
				logException(e1);
			}
			if (addRecordMediator != null) {
				addRecordMediator.setConnectionWrapper(null);
			}
		}
		return "";
	}

	protected HtmlScriptCollector getScriptCollector1() {
		if (scriptCollector1 == null) {
			scriptCollector1 = (HtmlScriptCollector) findComponentInRoot("scriptCollector1");
		}
		return scriptCollector1;
	}

	protected HtmlCommandExButton getButton1() {
		if (button1 == null) {
			button1 = (HtmlCommandExButton) findComponentInRoot("button1");
		}
		return button1;
	}

}

⌨️ 快捷键说明

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