Example usage for org.apache.wicket.ajax AjaxRequestTarget getPage

List of usage examples for org.apache.wicket.ajax AjaxRequestTarget getPage

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AjaxRequestTarget getPage.

Prototype

@Override
Page getPage();

Source Link

Document

Returns the page.

Usage

From source file:net.ftlines.wicket.fullcalendar.callback.ViewDisplayCallback.java

License:Apache License

@Override
protected void respond(final AjaxRequestTarget target) {
    final Request r = target.getPage().getRequest();
    final ViewType type = ViewType.forCode(r.getRequestParameters().getParameterValue("view").toString());
    final DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser().withZone(PFUserContext.getDateTimeZone());
    final DateMidnight start = fmt.parseDateTime(r.getRequestParameters().getParameterValue("start").toString())
            .toDateMidnight();/*  www .  jav  a2  s .  com*/
    final DateMidnight end = fmt.parseDateTime(r.getRequestParameters().getParameterValue("end").toString())
            .toDateMidnight();
    final DateMidnight visibleStart = fmt
            .parseDateTime(r.getRequestParameters().getParameterValue("visibleStart").toString())
            .toDateMidnight();
    final DateMidnight visibleEnd = fmt
            .parseDateTime(r.getRequestParameters().getParameterValue("visibleEnd").toString())
            .toDateMidnight();
    final View view = new View(type, start, end, visibleStart, visibleEnd);
    final CalendarResponse response = new CalendarResponse(getCalendar(), target);
    onViewDisplayed(view, response);
}

From source file:org.apache.isis.viewer.wicket.ui.panels.FormExecutorDefault.java

License:Apache License

private void addComponentsToRedraw(final AjaxRequestTarget target) {
    final List<Component> componentsToRedraw = Lists.newArrayList();
    final List<Component> componentsNotToRedraw = Lists.newArrayList();

    final Page page = target.getPage();
    page.visitChildren(new IVisitor<Component, Object>() {
        @Override//from   w  w  w.  ja  v a  2 s  .  com
        public void component(final Component component, final IVisit<Object> visit) {
            if (component.getOutputMarkupId() && !(component instanceof Page)) {
                List<Component> listToAddTo = shouldRedraw(component) ? componentsToRedraw
                        : componentsNotToRedraw;
                listToAddTo.add(component);
            }
        }

        private boolean shouldRedraw(final Component component) {

            // hmm... this doesn't work, because I think that the components
            // get removed after they've been added to target.
            // so.. still getting WARN log messages from XmlPartialPageUpdate

            //                final Page page = component.findParent(Page.class);
            //                if(page == null) {
            //                    // as per logic in XmlPartialPageUpdate, this has already been
            //                    // removed from page so don't attempt to redraw it
            //                    return false;
            //                }

            final Object defaultModel = component.getDefaultModel();
            if (!(defaultModel instanceof ScalarModel)) {
                return true;
            }
            final ScalarModel scalarModel = (ScalarModel) defaultModel;
            final UnchangingFacet unchangingFacet = scalarModel.getFacet(UnchangingFacet.class);
            return unchangingFacet == null || !unchangingFacet.value();
        }
    });

    for (Component componentNotToRedraw : componentsNotToRedraw) {
        MarkupContainer parent = componentNotToRedraw.getParent();
        while (parent != null) {
            parent = parent.getParent();
        }

        componentNotToRedraw.visitParents(MarkupContainer.class, new IVisitor<MarkupContainer, Object>() {
            @Override
            public void component(final MarkupContainer parent, final IVisit<Object> visit) {
                componentsToRedraw.remove(parent); // no-op if not in that list
            }
        });
        if (componentNotToRedraw instanceof MarkupContainer) {
            final MarkupContainer containerNotToRedraw = (MarkupContainer) componentNotToRedraw;
            containerNotToRedraw.visitChildren(new IVisitor<Component, Object>() {
                @Override
                public void component(final Component parent, final IVisit<Object> visit) {
                    componentsToRedraw.remove(parent); // no-op if not in that list
                }
            });
        }
    }

    if (LOG.isDebugEnabled()) {
        debug(componentsToRedraw, componentsNotToRedraw);
    }

    for (Component component : componentsToRedraw) {
        target.add(component);
    }
}

From source file:org.apache.isis.viewer.wicket.ui.panels.PromptFormAbstract.java

License:Apache License

private void onOkSubmittedOf(final AjaxRequestTarget target, final Form<?> form, final AjaxButton okButton) {

    setLastFocusHint();//from w  ww .  ja  v  a2 s . c o  m

    final FormExecutor formExecutor = new FormExecutorDefault<>(getFormExecutorStrategy());
    boolean succeeded = formExecutor.executeAndProcessResults(target.getPage(), target, form);

    if (succeeded) {
        completePrompt(target);

        okButton.send(target.getPage(), Broadcast.EXACT, newCompletedEvent(target, form));
        target.add(form);
    }

}

From source file:org.artifactory.webapp.actionable.action.ZapAction.java

License:Open Source License

@Override
public void onAction(RepoAwareItemEvent e) {
    RepoPath repoPath = e.getRepoPath();
    getRepoService().zap(repoPath);// w w  w .ja  va2 s . c  om
    AjaxRequestTarget target = e.getTarget();
    WebMarkupContainer nodePanelContainer = e.getTargetComponents().getNodePanelContainer();
    target.add(nodePanelContainer);
    Page page = target.getPage();
    page.info("Completed zapping item: '" + repoPath + "'");
}

From source file:org.dcm4chee.web.war.common.UIDFieldBehavior.java

License:LGPL

@SuppressWarnings("unchecked")
@Override/*from   w w  w.j  av a  2  s  . c om*/
protected final void onEvent(final AjaxRequestTarget target) {
    final FormComponent<String> formComponent = (FormComponent<String>) getComponent();
    boolean b = QueryUtil.isUniversalMatch(formComponent.getModelObject());
    try {
        formComponent.inputChanged();
        formComponent.validate();
        if (formComponent.hasErrorMessage()) {
            formComponent.invalid();
        } else {
            formComponent.valid();
            formComponent.updateModel();
            if (b != QueryUtil.isUniversalMatch(formComponent.getModelObject())) {
                updateOtherFields(target.getPage().getRequest().getParameterMap(),
                        formComponent.getInputName());
                addToTarget(target);
            }
        }
    } catch (RuntimeException e) {
        onError(target, e);
    }
}

From source file:org.hippoecm.frontend.plugins.yui.layout.UnitBehavior.java

License:Apache License

@Override
public void bind(final Component component) {
    super.bind(component);

    // re-render complete wireframe during the render phase
    AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
    if (target != null) {
        target.addListener(new IListener() {
            public void onBeforeRespond(Map map, AjaxRequestTarget target) {
                if (target.getPage() != component.findParent(Page.class)) {
                    return;
                }/*from www.j a v a2 s .  c o m*/
                IWireframe wireframe = WireframeUtils.getParentWireframe(component);
                if (wireframe != null) {
                    wireframe.render(target);
                } else {
                    log.warn("Unable to find parent wireframe-behavior");
                }
            }

            public void onAfterRespond(Map map, AjaxRequestTarget.IJavaScriptResponse response) {
            }
        });
    }
}

From source file:org.jabylon.rest.ui.wicket.components.AjaxFeedbackListener.java

License:Open Source License

@Override
public void onBeforeRespond(Map<String, Component> map, AjaxRequestTarget target) {
    if (target.getPage() instanceof IAjaxFeedbackPage) {
        IAjaxFeedbackPage feedbackPage = (IAjaxFeedbackPage) target.getPage();
        feedbackPage.showFeedback(target);
    }//from  w  ww  .  j a  va 2  s.  com
}

From source file:org.sakaiproject.delegatedaccess.tool.pages.EditablePanelAdvancedOptions.java

License:Educational Community License

public EditablePanelAdvancedOptions(String id, IModel inputModel, final NodeModel nodeModel,
        final TreeNode node, final int userType) {
    super(id);/*from w w  w .  j a v a  2s  .  c  o m*/

    this.nodeModel = nodeModel;
    this.node = node;

    final WebMarkupContainer advancedOptionsSpan = new WebMarkupContainer("advancedOptionsSpan");
    advancedOptionsSpan.setOutputMarkupId(true);
    final String editableSpanId = advancedOptionsSpan.getMarkupId();
    add(advancedOptionsSpan);

    AjaxLink<Void> saveEditableSpanLink = new AjaxLink<Void>("saveEditableSpanLink") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            target.appendJavascript("document.getElementById('" + editableSpanId + "').style.display='none';");
            //In order for the models to refresh, you have to call "expand" or "collapse" then "updateTree",
            //since I don't want to expand or collapse, I just call whichever one the node is already
            //Refreshing the tree will update all the models and information (like role) will be generated onClick
            if (((BaseTreePage) target.getPage()).getTree().getTreeState().isNodeExpanded(node)) {
                ((BaseTreePage) target.getPage()).getTree().getTreeState().expandNode(node);
            } else {
                ((BaseTreePage) target.getPage()).getTree().getTreeState().collapseNode(node);
            }
            ((BaseTreePage) target.getPage()).getTree().updateTree(target);
        }
    };
    advancedOptionsSpan.add(saveEditableSpanLink);

    Label editableSpanLabel = new Label("editableNodeTitle", nodeModel.getNode().title);
    advancedOptionsSpan.add(editableSpanLabel);

    AjaxLink<Void> restrictToolsLink = new AjaxLink<Void>("advancedOptionsLink") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            target.appendJavascript("document.getElementById('" + editableSpanId + "').style.display='';");
        }
    };
    add(restrictToolsLink);

    Label advancedOptionsSpanLabel = new Label("advancedOptionsSpan",
            new StringResourceModel("advanced", null));
    restrictToolsLink.add(advancedOptionsSpanLabel);

    Label advnacedOptionsTitle = new Label("advnacedOptionsTitle",
            new StringResourceModel("advancedOptionsTitle", null));
    advancedOptionsSpan.add(advnacedOptionsTitle);

    Label advancedOptionsInstructions = new Label("advancedOptionsInstructions",
            new StringResourceModel("advancedOptionsDesc", null));
    advancedOptionsSpan.add(advancedOptionsInstructions);

    advancedOptionsSpan.add(new EditablePanelCheckbox("editablePanelCheckbox",
            new PropertyModel(node, "userObject.shoppingPeriodRevokeInstructorEditable"),
            (NodeModel) ((DefaultMutableTreeNode) node).getUserObject(), node,
            DelegatedAccessConstants.TYPE_ADVANCED_OPT));
    advancedOptionsSpan.add(new EditablePanelCheckbox("revokePublicOptCheckbox",
            new PropertyModel(node, "userObject.shoppingPeriodRevokeInstructorPublicOpt"),
            (NodeModel) ((DefaultMutableTreeNode) node).getUserObject(), node,
            DelegatedAccessConstants.TYPE_ADVANCED_OPT));
}

From source file:org.sakaiproject.delegatedaccess.tool.pages.EditablePanelAdvancedUserOptions.java

License:Educational Community License

public EditablePanelAdvancedUserOptions(String id, IModel inputModel, final NodeModel nodeModel,
        final TreeNode node, Map<String, Object> settings) {
    super(id);/*from  www .  j  av a2 s . co m*/

    this.nodeModel = nodeModel;
    this.node = node;

    final WebMarkupContainer advancedOptionsSpan = new WebMarkupContainer("advancedOptionsSpan");
    advancedOptionsSpan.setOutputMarkupId(true);
    final String editableSpanId = advancedOptionsSpan.getMarkupId();
    add(advancedOptionsSpan);

    AjaxLink<Void> saveEditableSpanLink = new AjaxLink<Void>("saveEditableSpanLink") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            target.appendJavascript("document.getElementById('" + editableSpanId + "').style.display='none';");
            //In order for the models to refresh, you have to call "expand" or "collapse" then "updateTree",
            //since I don't want to expand or collapse, I just call whichever one the node is already
            //Refreshing the tree will update all the models and information (like role) will be generated onClick
            if (((BaseTreePage) target.getPage()).getTree().getTreeState().isNodeExpanded(node)) {
                ((BaseTreePage) target.getPage()).getTree().getTreeState().expandNode(node);
            } else {
                ((BaseTreePage) target.getPage()).getTree().getTreeState().collapseNode(node);
            }
            ((BaseTreePage) target.getPage()).getTree().updateTree(target);
        }
    };
    advancedOptionsSpan.add(saveEditableSpanLink);

    Label editableSpanLabel = new Label("editableNodeTitle", nodeModel.getNode().title);
    advancedOptionsSpan.add(editableSpanLabel);

    AjaxLink<Void> restrictToolsLink = new AjaxLink<Void>("advancedOptionsLink") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            target.appendJavascript("document.getElementById('" + editableSpanId + "').style.display='';");
        }
    };
    add(restrictToolsLink);

    Label advancedOptionsSpanLabel = new Label("advancedOptionsSpan",
            new StringResourceModel("advanced", null));
    restrictToolsLink.add(advancedOptionsSpanLabel);

    Label advnacedOptionsTitle = new Label("advnacedOptionsTitle",
            new StringResourceModel("advancedOptionsTitle", null));
    advancedOptionsSpan.add(advnacedOptionsTitle);

    Label advancedOptionsInstructions = new Label("advancedOptionsInstructions",
            new StringResourceModel("advancedOptionsDesc", null));
    advancedOptionsSpan.add(advancedOptionsInstructions);

    //Allow Become User:

    //check settings to see if user can update the allow become user checkbox:
    Boolean allowBecomeUser = Boolean.FALSE;
    if (settings.containsKey(PropertyEditableColumnAdvancedUserOptions.SETTINGS_ALLOW_SET_BECOME_USER)
            && settings.get(
                    PropertyEditableColumnAdvancedUserOptions.SETTINGS_ALLOW_SET_BECOME_USER) instanceof Boolean) {
        allowBecomeUser = (Boolean) settings
                .get(PropertyEditableColumnAdvancedUserOptions.SETTINGS_ALLOW_SET_BECOME_USER);
    }
    EditablePanelCheckbox allowBecomeUserCheckbox = new EditablePanelCheckbox("allowBecomeUserCheckbox",
            new PropertyModel(node, "userObject.allowBecomeUser"),
            (NodeModel) ((DefaultMutableTreeNode) node).getUserObject(), node,
            DelegatedAccessConstants.TYPE_ADVANCED_OPT);
    if (!allowBecomeUser) {
        allowBecomeUserCheckbox.setEnabled(false);
    }
    advancedOptionsSpan.add(allowBecomeUserCheckbox);
}

From source file:org.sakaiproject.delegatedaccess.tool.pages.EditablePanelCheckbox.java

License:Educational Community License

/**
 * Creates a simple checkbox panel for TreeTable's access column.
 * @param id/*ww  w. j av a  2s.c o m*/
 * @param inputModel
 * @param nodeModel
 * @param node
 */
public EditablePanelCheckbox(String id, IModel inputModel, final NodeModel nodeModel, final TreeNode node,
        final int type) {
    super(id);

    this.nodeModel = nodeModel;
    this.node = node;

    final CheckBox field = new CheckBox("checkboxField", inputModel) {
        @Override
        public boolean isVisible() {
            if (DelegatedAccessConstants.TYPE_SHOPPING_PERIOD_ADMIN == type) {
                return !nodeModel.getInheritedShoppingPeriodAdmin();
            } else if (DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == type) {
                return nodeModel.getNodeShoppingPeriodAdmin();
            } else {
                return true;
            }
        }

    };
    add(field);

    field.add(new AjaxFormComponentUpdatingBehavior("onClick") {
        protected void onUpdate(AjaxRequestTarget target) {
            //only update if its not an advanced option:
            if (DelegatedAccessConstants.TYPE_ADVANCED_OPT != type) {
                //toggle selection to trigger a reload on the current node 
                ((BaseTreePage) target.getPage()).getTree().getTreeState().selectNode(node,
                        !((BaseTreePage) target.getPage()).getTree().getTreeState().isNodeSelected(node));

                //In order for the models to refresh, you have to call "expand" or "collapse" then "updateTree",
                //since I don't want to expand or collapse, I just call whichever one the node is already
                //Refreshing the tree will update all the models and information (like role) will be generated onClick
                if (((BaseTreePage) target.getPage()).getTree().getTreeState().isNodeExpanded(node)) {
                    ((BaseTreePage) target.getPage()).getTree().getTreeState().expandNode(node);
                } else {
                    ((BaseTreePage) target.getPage()).getTree().getTreeState().collapseNode(node);
                }
                ((BaseTreePage) target.getPage()).getTree().updateTree(target);
            }
        }
    });
}