使用ADF实现基于Form的CRUD (2)
来源:互联网 发布:python 2 3区别 编辑:程序博客网 时间:2024/06/17 02:13
运行环境:JDeveloper 11.1.2.1.0 + Oracle Database 10g Express Edition 10.2.0.1。
接上一个Project,在测试Delete功能时,发现了两个小问题。
(1)点击Delete时应该有提示,当用户确认后再删除
(2)点击Delete后,不需要再点击Commit按钮提交。
好,我们现在就把Delete功能按照上面的要求修改一下。
重要步骤说明:
1. 拖放Popup组件到Delete按钮后面,拖放Dialog组件到Popup组件中,拖放OutputText组件到Dialog组件中
弹出的窗口是使用Popup组件来实现的,弹出窗口的内容是用Dialog组件来实现的,提示信息是用OutputText来实现的。
把popup的id="popupDelete",供后面引用。
2. 拖放Show Popup Behavior Operation到Delete按钮上
Show Popup Behavior是用来触发Popup组件的,设置其属性如下图:
![](http://4.bp.blogspot.com/--HtAtLCyUtI/TxRHSfVUDxI/AAAAAAAACsM/VYaztABL328/s400/1.GIF)
3. 使用dialogListener来监听用户选择了“确定”or“取消”
找到Dialog组件,设置其dialogListener属性,选择新Managed Bean和方法deleteDialogListener。
![](http://1.bp.blogspot.com/-WICf6nanHCI/TxRIvUXNlAI/AAAAAAAACsY/fHIvmK80Bqw/s400/2.GIF)
![](http://1.bp.blogspot.com/-xt9qh6LQ3mU/TxRIvhB4AyI/AAAAAAAACsg/aUGU_DbvZXU/s400/3.GIF)
其中deleteDialogListener方法,代码如下:
至于doDelete方法,我们在下一步定义。
4. 使用Java代码调用Delete按钮
(1)查看Delete按钮的页面源码,内容如下:
<af:commandButton actionListener="#{bindings.Delete.execute}" text="Delete" disabled="#{!bindings.Delete.enabled}" id="cb7">
<af:showPopupBehavior popupId="popupDelete" triggerType="action" align="endAfter"/>
</af:commandButton>
(2)双击Delete按钮,选择如下:
![](http://1.bp.blogspot.com/-WwHHXImSuBk/TxRL7jOg4MI/AAAAAAAACsw/cctKCs5G7Ms/s400/4.GIF)
确定后,会生成代码如下:
Delete按钮页面代码变为:
<af:commandButton text="Delete" action="#{myBackingBean.cb7_action}" disabled="#{!bindings.Delete.enabled}" id="cb7">
<af:showPopupBehavior popupId="popupDelete" triggerType="action" align="endAfter"/>
</af:commandButton>
(3)把cb7_action方法的代码复制到doDelete方法中,并做一定的修改,最终doDelete方法内容如下:
(4)删除cb7_action方法,同时删除页面中Delete按钮的action属性,因为真正的Delete操作已经dialogListener完成了。
最终的Delete页面代码如下:
<af:commandButton text="Delete" disabled="#{!bindings.Delete.enabled}" id="cb7">
<af:showPopupBehavior popupId="popupDelete" triggerType="action" align="endAfter"/>
</af:commandButton>
<af:popup childCreation="deferred" autoCancel="disabled" id="popupDelete">
<af:dialog id="d2" title="Confirm Delete"
dialogListener="#{myBackingBean.deleteDialogListener}">
<f:facet name="buttonBar"/>
<af:outputText value="The record will be deleted, are you sure?" id="ot1"/>
</af:dialog>
</af:popup>
5. 运行
点击Delete按钮,会提示是否删除记录,确定后,记录将被删除,无需再点击Commit提交。
![](http://4.bp.blogspot.com/-p0_5Y7YQdg4/TxRPVjzvQiI/AAAAAAAACs8/iWviOdL_468/s400/5.GIF)
接上一个Project,在测试Delete功能时,发现了两个小问题。
(1)点击Delete时应该有提示,当用户确认后再删除
(2)点击Delete后,不需要再点击Commit按钮提交。
好,我们现在就把Delete功能按照上面的要求修改一下。
重要步骤说明:
1. 拖放Popup组件到Delete按钮后面,拖放Dialog组件到Popup组件中,拖放OutputText组件到Dialog组件中
弹出的窗口是使用Popup组件来实现的,弹出窗口的内容是用Dialog组件来实现的,提示信息是用OutputText来实现的。
把popup的id="popupDelete",供后面引用。
2. 拖放Show Popup Behavior Operation到Delete按钮上
Show Popup Behavior是用来触发Popup组件的,设置其属性如下图:
3. 使用dialogListener来监听用户选择了“确定”or“取消”
找到Dialog组件,设置其dialogListener属性,选择新Managed Bean和方法deleteDialogListener。
其中deleteDialogListener方法,代码如下:
public void deleteDialogListener(DialogEvent dialogEvent) { if (dialogEvent.getOutcome().equals(DialogEvent.Outcome.ok)){ doDelete(); } }
至于doDelete方法,我们在下一步定义。
4. 使用Java代码调用Delete按钮
(1)查看Delete按钮的页面源码,内容如下:
<af:commandButton actionListener="#{bindings.Delete.execute}" text="Delete" disabled="#{!bindings.Delete.enabled}" id="cb7">
<af:showPopupBehavior popupId="popupDelete" triggerType="action" align="endAfter"/>
</af:commandButton>
(2)双击Delete按钮,选择如下:
确定后,会生成代码如下:
public BindingContainer getBindings() { return BindingContext.getCurrent().getCurrentBindingsEntry(); } public String cb7_action() { BindingContainer bindings = getBindings(); OperationBinding operationBinding = bindings.getOperationBinding("Delete"); Object result = operationBinding.execute(); if (!operationBinding.getErrors().isEmpty()) { return null; } return null; }
Delete按钮页面代码变为:
<af:commandButton text="Delete" action="#{myBackingBean.cb7_action}" disabled="#{!bindings.Delete.enabled}" id="cb7">
<af:showPopupBehavior popupId="popupDelete" triggerType="action" align="endAfter"/>
</af:commandButton>
(3)把cb7_action方法的代码复制到doDelete方法中,并做一定的修改,最终doDelete方法内容如下:
private void doDelete() { BindingContainer bindings = getBindings(); OperationBinding operationBinding = bindings.getOperationBinding("Delete"); Object result = operationBinding.execute(); if (operationBinding.getErrors().isEmpty()) { operationBinding = bindings.getOperationBinding("Commit"); operationBinding.execute(); } }
(4)删除cb7_action方法,同时删除页面中Delete按钮的action属性,因为真正的Delete操作已经dialogListener完成了。
最终的Delete页面代码如下:
<af:commandButton text="Delete" disabled="#{!bindings.Delete.enabled}" id="cb7">
<af:showPopupBehavior popupId="popupDelete" triggerType="action" align="endAfter"/>
</af:commandButton>
<af:popup childCreation="deferred" autoCancel="disabled" id="popupDelete">
<af:dialog id="d2" title="Confirm Delete"
dialogListener="#{myBackingBean.deleteDialogListener}">
<f:facet name="buttonBar"/>
<af:outputText value="The record will be deleted, are you sure?" id="ot1"/>
</af:dialog>
</af:popup>
5. 运行
点击Delete按钮,会提示是否删除记录,确定后,记录将被删除,无需再点击Commit提交。
Project 下载: Form_CRUD(2).7z
http://maping930883.blogspot.com/2009/09/adf042adfformcrud-2.html
0 0
- 使用ADF实现基于Form的CRUD (2)
- 使用ADF实现基于Form的CRUD (1)
- 使用ADF实现基于Form的CRUD (3)
- ADF组件之 SelectBooleanCheckbox使用(用于查询Form)
- 使用MyBatis对表执行CRUD操作——基于注解的实现
- 使用MyBatis对表执行CRUD操作——基于XML的实现
- 使用MyBatis对表执行CRUD操作——基于XML的实现
- 使用MyBatis对表执行CRUD操作——基于XML的实现
- 使用MyBatis对表执行CRUD操作——基于XML的实现
- MVC中使用EF(2):实现基本的CRUD功能
- Mybatis的CRUD操作(基于xml)
- Mybatis的CRUD操作(基于注解)
- 使用sinatra实现简单的crud功能
- 使用ADF Faces 之一:开发用户界面(基于AJAX)
- Sharepoint 2010 Form 身份认证的实现(基于SQL)
- Sharepoint 2010 Form 身份认证的实现(基于AD)
- Sharepoint 2010 Form 身份认证的实现(基于AD)
- ADF 多选框树的实现
- ehcache 的 diskStore
- 使用ADF实现基于Form的CRUD (1)
- 使用keytool生成ssl密钥文件keystore和truststore
- zoj-3197-Google Book
- JAVA web项目中的no result defined for action result input 错误
- 使用ADF实现基于Form的CRUD (2)
- OpenCV配置(64位 vs2010)
- POJ 3623 Best Cow Line, Gold(模拟)
- 2014-08-19 19:33:41
- HDU 4965 Fast Matrix Calculation 矩阵快速幂
- 使用ADF实现基于Form的CRUD (3)
- Codeforces 4C (STL map)
- 如何在ADF页面中显示警告信息?
- ADF与JSF的区别