GWTP奇怪的错误消息(这是不准确的)

时间:2013-10-03 22:36:29

标签: java gwt gin gwtp presenter

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

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

我遇到的问题是,当我遇到客户端错误时(几乎可以在我的客户端的任何地方,不确定边界在哪里)我收到一条非常神秘的消息,要求用GIN而不是消息将帮助我解决问题。似乎与GWTP Proxying有关,这是我得到的典型消息:http://pastebin.com/YgxPbkru真正的问题不是错误消息呈现给我的。 OpenIcidentPresenter扩展了IncidentPresenter,它是我为管理事件生命周期所做的Presenter(在这种情况下),这扩展了另一个我称之为RequestPresenter的演示者,这是一个允许用户向其中请求PresenterWidget类的Presenter(进入这个演示者生命周期的任何给定的插槽),这扩展了另一个名为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 ...
}

IncidentPresenter

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

RequestPresenter

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

RichPresenter

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

我觉得这可能是一个促成因素。我有一大群主持人,我可能会犯错误。

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

干杯!本

0 个答案:

没有答案