1

所以我真的需要一些有用的提示来解决我在 GWTP 应用程序中遇到的问题,也许你们中的一个人以前遇到过这个问题。所以我使用 GWTP 1.1:

  • com.gwtplatform.mvp.Mvp(不带入口点)
  • com.gwtplatform.dispatch.Dispatch 与
  • com.google.gwt.uibinder.UiBinder

我遇到的问题是,当我遇到客户端错误时(几乎可以在客户端的任何地方,不确定边界在哪里),我会收到一条与 GIN 相关的非常神秘的消息,而不是一条可以帮助我的消息解决问题。似乎与 GWTP 代理有关,这是我得到的典型消息:http: //pastebin.com/YgxPbkru真正的问题不是错误信息向我展示的内容。OpenIcidentPresenter 扩展了 IncidentPresenter,它是我为管理事件的生命周期而制作的 Presenter(在这种情况下),它扩展了我制作的另一个 Presenter,称为 RequestPresenter,这是一个 Presenter,允许用户将 PresenterWidget 类请求到其中(进入该演示者生命周期的任何给定插槽),这扩展了另一个名为 RichPresenter 的演示者,它几乎具有我所有演示者都需要的东西,例如页面加载指示和某些页面锁定等。以下是这些类:

OpenIncidentPresenter

public class OpenIncidentPresenter extends IncidentPresenter<OpenIncidentPresenter.MyView,
        OpenIncidentPresenter.MyProxy> implements ViewUiHandlers, HasRequestedWidgets, NewIncidentHandler,
        ChangeSectionHandler, ConfigureHandler {

        public interface MyView extends View, HasUiHandlers<ViewUiHandlers> {
                ... Snip ...
        }

        @ProxyCodeSplit
        @NameToken(NameTokens.open)
        //@UseGatekeeper(LoginGatekeeper.class)
        public interface MyProxy extends ProxyPlace<OpenIncidentPresenter> {
        }

        private static Logger logger = Logger.getLogger(OpenIncidentPresenter.class.getName());

        Process process;

        SectionTuple currentSection = new SectionTuple();

        Map<Integer, SectionTuple> sections = new HashMap<Integer, SectionTuple>();
        List<AccordionSection> sectionWigets = new ArrayList<AccordionSection>();

        List<Activity> cachedActivities = new ArrayList<Activity>();
        List<Authority> cachedAuthorities = new ArrayList<Authority>();
        List<Severity> cachedSeverities = new ArrayList<Severity>();
        List<Location> cachedLocations = new ArrayList<Location>();
        List<Site> cachedSites = new ArrayList<Site>();
        List<Area> cachedAreas = new ArrayList<Area>();

        Severity currentSeverity;
        boolean configured = false;
        boolean changedConsequences = false;

        final ImageResources imageResources;

        RegisteredRequestWidget<ActionBarPresenterWidget> actionBarReg;
        RegisteredRequestWidget<ProgressBarPresenterWidget> progressBarReg;

        @Inject
        public OpenIncidentPresenter(final EventBus eventBus, final MyView view,
                        final MyProxy proxy, final DispatchAsync dispatch,
                        final PlaceManager placeManager, ImageResources imageResources) {
                super(eventBus, view, proxy, dispatch, placeManager);

                this.imageResources = imageResources;

                getView().setUiHandlers(this);

                logger.log(Level.INFO, "Constructed OpenIncidentPresenter");
        }

        @Override
        protected void revealInParent() {
                RevealContentEvent.fire(this, ApplicationPresenter.SLOT_MIDDLE, this);
        }

        ... Snip ...
}

事件主持人

public abstract class IncidentPresenter<T extends View,
                H extends Proxy<?>> extends RequestPresenter<T, H> implements HasIncident {

        Logger logger = Logger.getLogger(IncidentPresenter.class.getName());

        public static final String INCIDENT_COOKIE = "incidentId";

        public interface LoadCallback {
                void onFinished();
        }

        protected Incident incident;
        protected DispatchAsync dispatch;

        private boolean loaded = false;

        public IncidentPresenter(EventBus eventBus, T view, H proxy,
                        DispatchAsync dispatch, PlaceManager placeManager) {
                super(eventBus, view, proxy, placeManager, true);

                this.dispatch = dispatch;
        }

        public abstract void onFailureToLoadIncident(Integer incidentId);
        public abstract void onLoadedIncident(Incident incident);

        @Override
        public void loadIncident(final Integer id) {
                loadIncident(id, null);
        }

        @Override
        public void loadIncident(final Integer id, final LoadCallback callback) {
                .. Snip ..
        }

        /**
         * Process the incident dependencies
         */
        protected void loadDependencies(final Incident incident, final LoadCallback callback) {
                .. Snip ..
        }

        @Override
        public Incident getIncident() {
                return incident;
        }

        @Override
        public void setIncident(Incident incident) {
                this.incident = incident;
                if(hasIncident()) {
                        String incidentCookie = Cookies.getCookie("incidentId");
                        if(incidentCookie == null || !incidentCookie.equals(String.valueOf(
                                        incident.getId()))) {
                                // Set the cookie to the new incident id
                                Cookies.setCookie("incidentId", String.valueOf(incident.getId()));

                                logger.log(Level.INFO, "Set incident " + String.valueOf(incident.getId())
                                        + " to the cookie session");
                        }
                } else {
                        Cookies.removeCookie("incidentId");
                        logger.log(Level.INFO, "Set incident to null incident object, cleared " +
                                        "the cookie session");
                }
        }

        @Override
        public boolean isIncidentLoaded() {
                return hasIncident() && loaded;
        }

        @Override
        public boolean hasIncident() {
                return IncidentUtils.isValid(incident);
        }

        @Override
        public void resetIncident() {
                setIncident(null);
                loaded = false;
        }

        @Override
        public DispatchAsync getDispatch() {
                return dispatch;
        }

        public String getIncidentCookie() {
                return Cookies.getCookie(INCIDENT_COOKIE);
        }
}

请求演示者

public abstract class RequestPresenter<T extends View, H extends Proxy<?>>
                extends RichPresenter<T, H> implements HasRequestedWidgets {

        RequestWidgetManager requestManager = new RequestWidgetManager(this);

        public RequestPresenter(EventBus eventBus, T view, H proxy,
                        PlaceManager placeManager) {
                this(eventBus, view, proxy, placeManager, false);
        }

        public RequestPresenter(EventBus eventBus, T view, H proxy,
                        PlaceManager placeManager, boolean leaveConfirmation) {
                super(eventBus, view, proxy, placeManager, leaveConfirmation);
        }

        @Override
        public void prepareFromRequest(PlaceRequest request) {
                prepareFromRequest(request, null);
        }

        /**
         * Alternative to {@link RequestPresenter#prepareFromRequest(PlaceRequest)} that
         * will allow you to register the {@link FinalCallback} in case you have dependency
         * on the request widgets.
         * @param request
         * @param callback
         */
        public void prepareFromRequest(PlaceRequest request, FinalCallback callback) {
                super.prepareFromRequest(request);

                executeAfterRequesting(callback);
                requestWidgets();
        }

        @Override
        protected void onBind() {
                super.onBind();

                registerRequestWidgets();
        }

        @Override
        protected void onUnbind() {
                super.onUnbind();

                unregisterRequestWidgets();
        }

        @Override
        protected void onHide() {
                super.onHide();

                dismissWidgets();
        }

        @Override
        protected void onReveal() {
                super.onReveal();

                requestWidgets();
        }

        private void requestWidgets() {
                requestManager.requestAll();

                onRequestWidgets();
        }

        private void dismissWidgets() {
                requestManager.dismissAll();

                onDismissWidgets();
        }

        public void unregisterRequestWidgets() {
                requestManager.unregisterAllWidgets();
        }

        @Override
        public abstract void registerRequestWidgets();

        public void onRequestWidgets() {
                // Do nothing by default
        }

        public void onDismissWidgets() {
                // Do nothing by default
        }

        protected RequestWidgetManager getRequestManager() {
                return requestManager;
        }

        /**
         * This will execute the callback method when the final request is made on loading.<br>
         * This must be set before super.onReveal or super.prepareFromRequest are called.
         * Or use {@link RequestPresenter#prepareFromRequest(PlaceRequest, FinalCallback)} to
         * set the final callback.
         * @param callback
         */
        public void executeAfterRequesting(FinalCallback callback) {
                requestManager.setFinalCallback(callback);
        }

        public <P extends PresenterWidget<?>> RequestedWidget<P> getRequestedWidget(
                        RegisteredRequestWidget<P> registry) {
                return requestManager.get(registry);
        }

        public <P extends PresenterWidget<?>> RegisteredRequestWidget<P> registerRequestWidget(
                        HasHandlers handler, Class<P> clazz, Object slot, boolean clearSlot) {
                return registerRequestWidget(handler, clazz, slot, clearSlot, null);
        }

        public <P extends PresenterWidget<?>> RegisteredRequestWidget<P> registerRequestWidget(
                        HasHandlers handler, Class<P> clazz, Object slot, boolean clearSlot,
                        RequestWidgetEvent.Callback<P> callback) {
                return requestManager.registerWidget(handler, clazz, slot, clearSlot, callback);
        }
}

丰富的演示者

public abstract class RichPresenter<T extends View,
        H extends Proxy<?>> extends Presenter<T, H> {

        protected final PlaceManager placeManager;

        private boolean leaveConfirmation;
        private String defaultLeaveMessage = "Any unsaved work will be lost when " +
                "leaving this page, are you sure you would like to leave?";

        public RichPresenter(EventBus eventBus, T view, H proxy,
                        PlaceManager placeManager) {
                this(eventBus, view, proxy, placeManager, false);
        }

        public RichPresenter(EventBus eventBus, T view, H proxy,
                        PlaceManager placeManager, boolean leaveConfirmation) {
                super(eventBus, view, proxy);

                this.placeManager = placeManager;
                this.leaveConfirmation = leaveConfirmation;
        }

        /**
         * Setup component control handlers for the UI
         */
        protected void setupHandlers(final T view) {
                // Do nothing by default
        }

        @Override
        public void prepareFromRequest(PlaceRequest request) {
                super.prepareFromRequest(request);

                // Start Load Indicator
                LoadingIndicatorEvent.fire(this, true);

                // Attempt to set leave confirmation
                setLeaveConfirmation(leaveConfirmation);
        }

        @Override
        protected void onBind() {
                super.onBind();

                setupHandlers(getView());
        }

        @Override
        protected void onUnbind() {
                super.onUnbind();

                // Remove all the event handlers
                for(HandlerRegistration reg : handlerRegistrations) {
                        reg.removeHandler();
                }
                handlerRegistrations.clear();
        }

        @Override
        protected void onReveal() {
                super.onReveal();

                // Stop Load Indicator
                LoadingIndicatorEvent.fire(this, true);

                // Attempt to set leave confirmation
                setLeaveConfirmation(leaveConfirmation);
        }

        @Override
        protected void onReset() {
                super.onReset();

                // Stop Load Indicator
                LoadingIndicatorEvent.fire(this, false);
        }

        /**
         * Set the page leave confirmation.
         * @param leaveConfirmation
         */
        public void setLeaveConfirmation(boolean leaveConfirmation) {
                this.leaveConfirmation = leaveConfirmation;

                if(leaveConfirmation && !BrowserUtils.isIEBrowser()) {
                        placeManager.setOnLeaveConfirmation(defaultLeaveMessage);
                } else {
                        placeManager.setOnLeaveConfirmation(null);
                }
        }

        public boolean isConfirmOnLeave() {
                return leaveConfirmation;
        }

        public String getDefaultLeaveMessage() {
                return defaultLeaveMessage;
        }

        public void setDefaultLeaveMessage(String message) {
                this.defaultLeaveMessage = message;
        }
}

我觉得这可能是一个促成因素。我有一大串演示者,我可能实施错误。

这让我很难识别客户端代码中的问题。我必须完成我的更改,还原它们,直到我不再收到此消息。这太荒谬了。如果您发现我做错了什么或需要更多信息,请告诉我!将不胜感激。

干杯! 本

4

0 回答 0