0

ADF 具有此文档属性 (UncommitedDataWarning),当用户想要导航到实际页面中具有未提交日期的另一个页面时,该属性会向用户发出警告。这只是一个警告。当用户在对话框中按 OK 时,我想对输入的数据执行回滚。有谁知道如何实现这一目标?

如果有人有任何想法通过 JSF 和 JavaScript 实现这一点,请告诉我,也许我会找到某种方式来适应它:)。

4

3 回答 3

1

您检查了吗https://blogs.oracle.com/shay/entry/warning_of_uncommitted_unsaved_changes

我假设你只需要打开它。<AF:document uncommittedDataWarning="on">

于 2013-10-02T13:20:35.927 回答
1

好的,当您按下 ok 时,您想自己进行回滚,尽管如果您不提交更改,您的更改将不会自行提交

您可以检查您的应用程序模块。如果数据不干净(因此已经进行了更改),您可以调用您在页面中进行的弹出窗口(RichPopup)并输出文本告诉您有关更改和回滚的按钮你的改变

通过以下方式获取您的应用程序模块

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);
}

通过以下方法检查是否有任何更改

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

并在您用于导航的按钮中调用以下方法

 public String gotosecondpage() {
    if (!this.pendingChangesExist()) {
        make navigation-
    } else {
         call your pop up window }
    return null;
}
于 2013-10-02T13:44:44.880 回答
1

这是相位侦听器的代码,我用它来检查用户是否已登录 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) {
}

 }

不要忘记在 adf-settings.xml 中注册它,如下所示

 <lifecycle>
  <phase-listener>
    <listener-id>SecurityPagePhaseListener</listener-id>
      <class>security.SecurityPagePhaseListener</class>
  </phase-listener>
</lifecycle>
于 2013-10-02T16:03:35.450 回答