简体   繁体   English

如何以编程方式在ADF中实现UncommitedDataWarning?

[英]How to programatically achieve UncommitedDataWarning in ADF?

ADF has this document property (UncommitedDataWarning) that warns the user when he wants to navigate to another page having some not Commited date in the actual page. ADF具有此文档属性(UncommitedDataWarning),当用户想要导航到实际页面中具有某些未提交日期的另一页面时,该警告会警告用户。 This is just a warning. 这只是一个警告。 I want to perform a Rollback for the entered data when the user press OK in the dialog box. 当用户在对话框中按“确定”时,我想对输入的数据执行回滚。 Does anyone know any way on how to achieve this? 有人知道如何实现这一目标吗?

If someone has any idea to achieve this through JSF & JavaScript please tell me that, maybe I will find someway to adapt that :). 如果有人想通过JSF和JavaScript实现此目标,请告诉我,也许我会找到某种方法来适应它:)。

Did you check https://blogs.oracle.com/shay/entry/warning_of_uncommitted_unsaved_changes . 您是否检查过https://blogs.oracle.com/shay/entry/warning_of_uncommitted_unsaved_changes

I assume you just need to switch it on. 我认为您只需要打开它。 <AF:document uncommittedDataWarning="on"> <AF:document uncommittedDataWarning =“上”>

ok you want to do a rollback yourself when you press ok although your changes will not be committed by itself if you do not commit it 好的,您想在按ok时自己回滚,尽管如果不提交更改,更改将不会自己提交

you can check your Application module.If the data is dirty (so there are changes had been made) you can call a popup window (RichPopup) which you made in your page and has output text tells you about the changes and a button which rollback your changes 您可以检查您的应用程序模块。如果数据不干净(因此进行了更改),您可以调用在页面中创建的弹出窗口(RichPopup),并带有输出文本来告诉您有关更改的信息以及可以回滚的按钮您的更改

get your Application module by 通过获取您的应用程序模块

private ApplicationModule getApplicationModule(String dataProvider) {
    FacesContext fc = FacesContext.getCurrentInstance();
    Application app = fc.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = fc.getELContext();
    ValueExpression valueExp = elFactory.createValueExpression(elContext, dataProvider, Object.class);

    return (ApplicationModule)valueExp.getValue(elContext);
}

check for any changes by the following method 通过以下方法检查是否有任何更改

 private boolean pendingChangesExist() {
    return this.getApplicationModule("#{data.AppModuleDataControl.dataProvider}").getTransaction().isDirty();
}

and in the button you use for navigation call the following method 并在用于导航的按钮中调用以下方法

 public String gotosecondpage() {
    if (!this.pendingChangesExist()) {
        make navigation-
    } else {
         call your pop up window }
    return null;
}

this is the code of phase listener i use it to check if the user is logged in in ADF.make the changes you want to check about anything else 这是阶段侦听器的代码,我用它来检查用户是否已在ADF中登录。进行要检查的更改是否需要进行其他检查

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;

import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import oracle.adf.controller.ControllerContext;
import oracle.adf.controller.faces.lifecycle.JSFLifecycle;
import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;

import view.backing.UserData;


 public class SecurityPagePhaseListener implements PagePhaseListener {
      public static final String LOGIN_VIEW = "/Home";
public static final String LOGOUT_MSG = "You are not logged in";
public static final String PASTE_MSG = "Don't try  to copy and paste URL address :)";
public static final String currentView=FacesContext.getCurrentInstance().getViewRoot().getId();


public static Object resolveExpression(String expression) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Application app = facesContext.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    ValueExpression valueExp = elFactory.createValueExpression(elContext, expression, Object.class);
    return valueExp.getValue(elContext);
}

public void beforePhase(PagePhaseEvent event) {

    if (event.getPhaseId() == JSFLifecycle.INIT_CONTEXT_ID) {

        ControllerContext cc = ControllerContext.getInstance();
        String viewId = cc.getCurrentViewPort().getViewId();
        Boolean protectedView = SecurityUtil.isProtectedPage(viewId);

        /** ------ [ If requested page is protected area ] ----- */
        if (protectedView) {
            UserData ud = (UserData)resolveExpression("#{UserData}");
            Boolean logedIn = ud.getLoggedIn();
            /** ------ [ If user is not logged in ] ----- */
            if (!logedIn) {
                FacesMessage fm = new FacesMessage(LOGOUT_MSG);
                fm.setSeverity(FacesMessage.SEVERITY_ERROR);
                FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, fm);
               SecurityUtil.displayView(LOGIN_VIEW);
            }


            /** [ If user try to paste direct link to protected page ] */
            if (!SecurityUtil.isViewState()) {
                FacesMessage fm = new FacesMessage(PASTE_MSG);
                fm.setSeverity(FacesMessage.SEVERITY_ERROR);
                FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, fm);
               SecurityUtil.displayView(LOGIN_VIEW );
            }
        }
    }

}

public void afterPhase(PagePhaseEvent event) {
}

 }

Do not forget to register it in adf-settings.xml as follows 不要忘记按如下所示在adf-settings.xml中注册它

 <lifecycle>
  <phase-listener>
    <listener-id>SecurityPagePhaseListener</listener-id>
      <class>security.SecurityPagePhaseListener</class>
  </phase-listener>
</lifecycle>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM