Java 在Fusion Web应用程序中单击按钮后重新加载ADF表
我最近开始使用jdeveloper12c开发我的第一个ADF项目 因此,我有一个连接到Oracle数据库的Fusion Web应用程序。在其中一个jsf页面上有两个ADF表,它们显示来自数据库的数据。下面是一个按钮,它向数据库发送一个“DELETE”语句来删除所选条目。出于某些原因,在此之后必须刷新这两个表(删除操作会影响两个表中显示的条目) 当我对表显示了正确的数据感到非常高兴,并且按钮做得太好之后,我很快意识到,如果数据库发生变化,jsf页面中的表将不会自动刷新。我在网上搜索了一些关于如何在ADF Fusion应用程序中刷新jsf页面元素的入门教程。遗憾的是,到目前为止,我还没有找到任何能给我钥匙的东西 我在OracleHQ页面上找到了它,但它也有使用许多专有名称的习惯,并且是用流动文本编写的,因此没有代码示例、代码片段或类似内容,这使得新手很难理解 这是我的托管java bean中的一个片段,我在其中存储了我的按钮功能:Java 在Fusion Web应用程序中单击按钮后重新加载ADF表,java,sql,oracle,oracle-adf,jdeveloper,Java,Sql,Oracle,Oracle Adf,Jdeveloper,我最近开始使用jdeveloper12c开发我的第一个ADF项目 因此,我有一个连接到Oracle数据库的Fusion Web应用程序。在其中一个jsf页面上有两个ADF表,它们显示来自数据库的数据。下面是一个按钮,它向数据库发送一个“DELETE”语句来删除所选条目。出于某些原因,在此之后必须刷新这两个表(删除操作会影响两个表中显示的条目) 当我对表显示了正确的数据感到非常高兴,并且按钮做得太好之后,我很快意识到,如果数据库发生变化,jsf页面中的表将不会自动刷新。我在网上搜索了一些关于如何在
public String update() {
getDBConnection c = new DBConnection();
Connection conn = c.getConn();
RowKeySet selectedEntries = getDetailTable().getSelectedRowKeys();
Iterator selectedEntryIter = selectedEntries.iterator();
DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding entryIter = bindings.findIteratorBinding("my_iterator");
RowSetIterator rSIter = entryIter.getRowSetIterator();
try {
PreparedStatement pstmt1 = conn.prepareStatement("DELETE ...");
PreparedStatement pstmt2 = conn.prepareStatement("DELETE ...");
while(selectedEntryIter.hasNext()){
Key key = (Key)((List)selectedEntryIter.next()).get(0);
Row currentRow = rSIter.getRow(key);
BigDecimal barcode = (BigDecimal) currentRow.getAttribute("id");
BigDecimal field1 = (BigDecimal) currentRow.getAttribute("field1");
BigDecimal field2 = (BigDecimal) currentRow.getAttribute("field2");
pstmt1.setBigDecimal(1, id);
pstmt1.setBigDecimal(2, field1);
pstmt2.setBigDecimal(1, id);
pstmt2.setBigDecimal(2, field2);
pstmt1.executeUpdate();
pstmt2.executeUpdate();
}
conn.commit();
//i guess here i have to trigger to refresh the tables but I have pretty to no clue of how to do that
//where do I have to set the functionality? I read sth about creating another bean in the "session" package
//but somehow i have to access the jsf i want to have refreshed. Where do I create that connection?
//even a simple example or a good reference to a tutorial would be helpful for me
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return null;
}
也许这个问题是一个已经存在的问题的重复,我只是太愚蠢了,找不到它,但我无论如何都会尝试一下。提前谢谢 在本例中,您只需添加一个entryIter.executeQuery();就在您的conn.commit()之后;(还应避免运行直接sql删除,并使用标准ADF BC delete) 但为了回答未来查询的问题标题,下面是一个简单的刷新表按钮的示例,该按钮易于重用,我通常将其添加到“客户端表”工具栏上:
//in your jsff
<af:panelCollection id="pc" >
<f:facet name="menus"/>
<f:facet name="statusbar"/>
<f:facet name="toolbar">
<af:toolbar id="t1" flex="5">
<af:group id="g1">
<af:commandImageLink shortDesc="Reload" partialSubmit="true" actionListener="#{YOUR_SCOPE.YOUR_BEAN.refreshTable}"
icon="#{resource['images:YOUR_RELOAD_ICON.png']}">
<f:attribute name="tableIdToRefresh" value="YOUR_TABLE_ID"/>
</af:commandImageLink>
</af:group>
</af:toolbar>
</f:facet>
<af:table id="YOUR_TABLE_ID" value="#{bindings.YOUR_VO.collectionModel}" var="row" rows="#{bindings.YOUR_VO.rangeSize}"
selectedRowKeys="#{bindings.YOUR_VO.collectionModel.selectedRow}" selectionListener="#{bindings.YOUR_VO.collectionModel.makeCurrent}" rowSelection="single"
fetchSize="#{bindings.YOUR_VO.rangeSize}" filterModel="#{bindings.XxcnVieIntSearchVCQuery.queryDescriptor}"
queryListener="#{bindings.XxcnVieIntSearchVCQuery.processQuery}" varStatus="vs" >
<!-- COLUMNS -->
</af:table>
</af:panelCollection>
//in your bean #{YOUR_SCOPE.YOUR_BEAN.refreshTable}
public void refreshTable(ActionEvent actionEvent) {
//Get the attribute tableIdToRefresh value. I like to have it as a jsff attribute so i can easily reuse the button elsewhere
String tableToRefreshId = "" + ((RichCommandImageLink)actionEvent.getSource()).getAttributes().get("tableIdToRefresh");
if (sValeurCode != null) {
addPprToComponentById(tableToRefreshId);
//If it doesn't suffice (see below) you can use this :
//refreshTableIterator(tableToRefreshId);
}
}
public static void addPprToComponentById(String id) {
Object component = findComponentInRoot(id); //from the great JSFUtils library
if (component != null) {
AdfFacesContext.getCurrentInstance().addPartialTarget((UIComponent)component);
AdfFacesContext.getCurrentInstance().partialUpdateNotify((UIComponent)component);
}
}
/**
* Locate an UIComponent in view root with its component id. Use a recursive way to achieve this.
* @param id UIComponent id
* @return UIComponent object
*/
public static UIComponent findComponentInRoot(String id) {
UIComponent component = null;
if (id != null) {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext != null) {
UIComponent root = facesContext.getViewRoot();
if (root != null) {
component = findComponent(root, id);
}
}
}
return component;
}
很抱歉,到目前为止我没有对此做出反应,我正在尝试根据您的答案实施一个解决方案,但这需要一段时间。我是ADF的新手,Jdeveloper不能通过VPN(homeoffice)稳定运行,其背后的过程对我来说也是全新的。尽管如此,感谢您的努力,我们将看看它是否会打开成功之门
public static void refreshTableIterator(String tableId) {
RichTable table = findComponentInRoot(tableId);
DCIteratorBinding treeIterator = null;
if (table != null) {
treeIterator = getTableIterator(table);
if (treeIterator != null) {
RowSetIterator rsi = treeIterator.getRowSetIterator();
treeIterator.executeQuery();
rsi.closeRowSetIterator();
}
}
}
public static DCIteratorBinding getTableIterator(RichTable table) {
DCIteratorBinding treeIterator = null;
CollectionModel model = (CollectionModel)table.getValue();
if (model != null) {
JUCtrlHierBinding treeBinding = (JUCtrlHierBinding)model.getWrappedData();
if (treeBinding != null) {
treeIterator = treeBinding.getDCIteratorBinding();
}
}
return treeIterator;
}