📄 datatablesort.java
字号:
/**
*
*/
package pagecode.datatablesort;
import pagecode.PageCodeBase;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.component.UIColumn;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlInputHidden;
import javax.faces.context.FacesContext;
import java.util.Collections;
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 com.ibm.websphere.sdo.mediator.jdbc.metadata.Metadata;
import com.ibm.websphere.sdo.mediator.jdbc.metadata.MetadataFactory;
import com.ibm.websphere.sdo.mediator.jdbc.metadata.OrderBy;
import com.ibm.websphere.sdo.mediator.jdbc.metadata.impl.MetadataFactoryImpl;
import com.ibm.ws.sdo.mediator.jdbc.JDBCMediatorFactoryImpl;
import com.ibm.ws.sdo.mediator.jdbc.JDBCMediatorResourceImpl;
import commonj.sdo.DataObject;
import java.sql.Connection;
/**
* @author nan
*
*/
public class Datatablesort extends PageCodeBase {
protected HtmlForm form1;
protected HtmlDataTable table1;
protected UIColumn column1;
protected HtmlCommandLink link5;
protected HtmlOutputText text1;
protected HtmlCommandLink link4;
protected HtmlOutputText text3;
protected HtmlCommandLink link3;
protected HtmlOutputText text5;
protected HtmlOutputText text7;
protected HtmlCommandLink link2;
protected HtmlOutputText text9;
protected HtmlCommandLink link1;
protected HtmlOutputText text11;
protected HtmlOutputText text2;
protected UIColumn column2;
protected HtmlOutputText text4;
protected UIColumn column3;
protected HtmlOutputText text6;
protected UIColumn column4;
protected HtmlOutputText text8;
protected UIColumn column5;
protected HtmlOutputText text10;
protected UIColumn column6;
protected HtmlOutputText text12;
protected HtmlInputHidden text13;
private static final String SDOConnection_name = "JSFandSDO_Con";
private ConnectionWrapper SDOConnectionWrapper;
protected DataObject datatablesortParameters;
protected JDBCMediator datatablesortMediator;
private static final String datatablesort_metadataFileName = "/WEB-INF/wdo/datatablesort.xml";
private static final int datatablesortTargetPageSize = -1;
protected List datatablesort;
protected static final String[] datatablesortArgNames = {};
protected static final String[] datatablesortArgValues = {};
protected HtmlForm getForm1() {
if (form1 == null) {
form1 = (HtmlForm) findComponentInRoot("form1");
}
return form1;
}
protected HtmlDataTable getTable1() {
if (table1 == null) {
table1 = (HtmlDataTable) findComponentInRoot("table1");
}
return table1;
}
protected UIColumn getColumn1() {
if (column1 == null) {
column1 = (UIColumn) findComponentInRoot("column1");
}
return column1;
}
protected HtmlCommandLink getLink5() {
if (link5 == null) {
link5 = (HtmlCommandLink) findComponentInRoot("link5");
}
return link5;
}
protected HtmlOutputText getText1() {
if (text1 == null) {
text1 = (HtmlOutputText) findComponentInRoot("text1");
}
return text1;
}
protected HtmlCommandLink getLink4() {
if (link4 == null) {
link4 = (HtmlCommandLink) findComponentInRoot("link4");
}
return link4;
}
protected HtmlOutputText getText3() {
if (text3 == null) {
text3 = (HtmlOutputText) findComponentInRoot("text3");
}
return text3;
}
protected HtmlCommandLink getLink3() {
if (link3 == null) {
link3 = (HtmlCommandLink) findComponentInRoot("link3");
}
return link3;
}
protected HtmlOutputText getText5() {
if (text5 == null) {
text5 = (HtmlOutputText) findComponentInRoot("text5");
}
return text5;
}
protected HtmlOutputText getText7() {
if (text7 == null) {
text7 = (HtmlOutputText) findComponentInRoot("text7");
}
return text7;
}
protected HtmlCommandLink getLink2() {
if (link2 == null) {
link2 = (HtmlCommandLink) findComponentInRoot("link2");
}
return link2;
}
protected HtmlOutputText getText9() {
if (text9 == null) {
text9 = (HtmlOutputText) findComponentInRoot("text9");
}
return text9;
}
protected HtmlCommandLink getLink1() {
if (link1 == null) {
link1 = (HtmlCommandLink) findComponentInRoot("link1");
}
return link1;
}
protected HtmlOutputText getText11() {
if (text11 == null) {
text11 = (HtmlOutputText) findComponentInRoot("text11");
}
return text11;
}
protected HtmlOutputText getText2() {
if (text2 == null) {
text2 = (HtmlOutputText) findComponentInRoot("text2");
}
return text2;
}
protected UIColumn getColumn2() {
if (column2 == null) {
column2 = (UIColumn) findComponentInRoot("column2");
}
return column2;
}
protected HtmlOutputText getText4() {
if (text4 == null) {
text4 = (HtmlOutputText) findComponentInRoot("text4");
}
return text4;
}
protected UIColumn getColumn3() {
if (column3 == null) {
column3 = (UIColumn) findComponentInRoot("column3");
}
return column3;
}
protected HtmlOutputText getText6() {
if (text6 == null) {
text6 = (HtmlOutputText) findComponentInRoot("text6");
}
return text6;
}
protected UIColumn getColumn4() {
if (column4 == null) {
column4 = (UIColumn) findComponentInRoot("column4");
}
return column4;
}
protected HtmlOutputText getText8() {
if (text8 == null) {
text8 = (HtmlOutputText) findComponentInRoot("text8");
}
return text8;
}
protected UIColumn getColumn5() {
if (column5 == null) {
column5 = (UIColumn) findComponentInRoot("column5");
}
return column5;
}
protected HtmlOutputText getText10() {
if (text10 == null) {
text10 = (HtmlOutputText) findComponentInRoot("text10");
}
return text10;
}
protected UIColumn getColumn6() {
if (column6 == null) {
column6 = (UIColumn) findComponentInRoot("column6");
}
return column6;
}
protected HtmlOutputText getText12() {
if (text12 == null) {
text12 = (HtmlOutputText) findComponentInRoot("text12");
}
return text12;
}
protected HtmlInputHidden getText13() {
if (text13 == null) {
text13 = (HtmlInputHidden) findComponentInRoot("text13");
}
return text13;
}
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=datatablesort
*/
public String doDatatablesortUpdateAction() {
try {
getDatatablesortMediator().applyChanges(
getRootDataObject(getDatatablesort()));
} catch (Throwable e) {
logException(e);
} finally {
try {
if (SDOConnectionWrapper != null) {
SDOConnectionWrapper.getConnection().close();
SDOConnectionWrapper = null;
}
} catch (Throwable e1) {
logException(e1);
}
if (datatablesortMediator != null) {
datatablesortMediator.setConnectionWrapper(null);
}
}
return "";
}
/**
* @paramBean id=datatablesort
*/
public DataObject getDatatablesortParameters() {
if (datatablesortParameters == null) {
try {
datatablesortParameters = getDatatablesortMediator()
.getParameterDataObject();
} catch (MediatorException e) {
logException(e);
}
}
return datatablesortParameters;
}
protected JDBCMediator getDatatablesortMediator() {
if (datatablesortMediator == null) {
try {
datatablesortMediator = JDBCMediatorFactory.soleInstance
.createMediator(
getResourceInputStream(datatablesort_metadataFileName),
getSDOConnectionWrapper());
initSchema(getRealPath(datatablesort_metadataFileName),
datatablesortMediator.getSchema());
} catch (Throwable e) {
logException(e);
}
} else {
datatablesortMediator
.setConnectionWrapper(getSDOConnectionWrapper());
}
return datatablesortMediator;
}
/**
* @action id=datatablesort
*/
public String doDatatablesortFetchAction() {
try {
resolveParams(getDatatablesortParameters(), datatablesortArgNames,
datatablesortArgValues, "datatablesort_params_cache");
DataObject graph = getDatatablesortMediator().getGraph(
getDatatablesortParameters());
datatablesort = graph.getList(0);
} catch (Throwable e) {
logException(e);
} finally {
try {
if (SDOConnectionWrapper != null) {
SDOConnectionWrapper.getConnection().close();
SDOConnectionWrapper = null;
}
} catch (Throwable e1) {
logException(e1);
}
if (datatablesortMediator != null) {
datatablesortMediator.setConnectionWrapper(null);
}
}
return "";
}
/**
* @mediatorFactory com.ibm.etools.sdo.rdb.datahandlers.RelationalDataFactory
* @mediatorProperties metadataFileName=/WEB-INF/wdo/datatablesort.xml
* @methodEntry id=datatablesort/paramBean=datatablesort/action=datatablesort
* @action FILL
*/
public List getDatatablesort() {
if (datatablesort == null) {
doDatatablesortFetchAction();
}
return datatablesort;
}
/*
* A method to perform the sorting operation.
*/
public String doLink1Action() {
// retrieve the param which was passed by the Command-Link - It is the name of the column clicked
String type = (String)getRequestParam().get("CAT");
boolean order = true;
// retrieve the string which tells to sort in ascending or descending order
String dir = (String)getRequestScope().get("direction");
if( dir.equals("Descending")) {
order = false;
// reverse the order for next click
getRequestScope().put("direction", "Ascending");
} else {
order = true;
// reverse the order for next click
getRequestScope().put("direction", "Descending");
}
try {
// create a new JDBCMediatorResourceImpl
JDBCMediatorResourceImpl resource = new JDBCMediatorResourceImpl();
// load the metadata into the new JDBCMeditaorResourceImpl resourse just created
resource.load(getResourceInputStream(datatablesort_metadataFileName), Collections.EMPTY_MAP);
// pull the metadata out of that resource
Metadata metadata = (Metadata)resource.getContents().get(0);
// create a Metadata factory to help create new query information
MetadataFactory factory = MetadataFactoryImpl.eINSTANCE;
// Pull the SQL orderbys out of the metadata
List ordersbys = metadata.getOrderBys();
// Create a new orderby on the proper column in your table
OrderBy ob = factory.createOrderBy();
ob.setColumn(metadata.getTable("INVENTORYSORT").getColumn(type));
ob.setAscending(order);
// add the new order by the list of orderbys
ordersbys.add(0, ob);
// create a new data mediator to perform the query
datatablesortMediator = JDBCMediatorFactoryImpl.soleInstance.createMediator(metadata,
getSDOConnectionWrapper());
// perfrom the new query
doDatatablesortFetchAction();
} catch (Throwable e) {
e.printStackTrace();
}
return "";
}
/*
* A script collector event to initialize the Ascending/Descending order
*/
public void onPageLoadBegin(FacesContext facescontext) {
// Type Java code to handle page load begin event here
if( getRequestScope().get("direction") == null ) {
getRequestScope().put("direction", "Ascending");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -