Example usage for org.apache.wicket.markup.html.form Form get

List of usage examples for org.apache.wicket.markup.html.form Form get

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form Form get.

Prototype

@Override
public final Component get(String path) 

Source Link

Document

Get a child component by looking it up with the given path.

Usage

From source file:au.org.theark.core.web.form.AbstractArchiveDetailForm.java

License:Open Source License

protected void initialiseForm() {

    cancelButton = new AjaxButton(Constants.CANCEL) {

        private static final long serialVersionUID = 1L;

        @Override/*ww w  . j a  v a 2s  .c o  m*/
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (isNew()) {
                editCancelProcess(target);
            } else {
                crudVO.getSearchResultPanelContainer().setVisible(true);// Hide the Search Result List Panel via the WebMarkupContainer
                crudVO.getDetailPanelContainer().setVisible(false);// Hide the Detail Panle via the WebMarkupContainer
                target.add(crudVO.getDetailPanelContainer());
                target.add(crudVO.getSearchResultPanelContainer());// Attach the resultListContainer WebMarkupContainer to be re-rendered
                onCancelPostProcess(target);
            }
        }

        @Override
        protected void onError(AjaxRequestTarget arg0, Form<?> arg1) {

        }
    };

    saveButton = new AjaxButton(Constants.SAVE) {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return ArkPermissionHelper.isActionPermitted(Constants.SAVE);
        }

        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onSave(containerForm, target);
            target.add(crudVO.getDetailPanelContainer());
        }

        @SuppressWarnings("unchecked")
        public void onError(AjaxRequestTarget target, Form<?> form) {
            boolean setFocusError = false;
            WebMarkupContainer wmc = (WebMarkupContainer) form.get("detailFormContainer");
            for (Iterator iterator = wmc.iterator(); iterator.hasNext();) {
                Component component = (Component) iterator.next();
                if (component instanceof FormComponent) {
                    FormComponent formComponent = (FormComponent) component;

                    if (!formComponent.isValid()) {
                        if (!setFocusError) {
                            // Place focus on field in error (for the first field in error)
                            target.focusComponent(formComponent);
                            setFocusError = true;
                        }
                    }
                }
            }

            processErrors(target);
        }
    };

    addComponentsToForm();
}

From source file:au.org.theark.lims.web.component.inventory.form.AbstractInventoryDetailForm.java

License:Open Source License

/**
 * Initialise the form, with the general edit/save/cancel/delete buttons
 * /*from   ww w.  j  a  va2 s. co m*/
 */
protected void initialiseForm() {
    cancelButton = new AjaxButton(Constants.CANCEL) {

        private static final long serialVersionUID = 1684005199059571017L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            detailContainer.setVisible(false);
            target.add(detailContainer);
            processErrors(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedbackPanel);
        }
    };

    saveButton = new ArkBusyAjaxButton(Constants.SAVE) {

        private static final long serialVersionUID = -423605230448635419L;

        @Override
        public boolean isVisible() {
            return ArkPermissionHelper.isActionPermitted(Constants.SAVE);
        }

        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onSave(containerForm, target);
            target.add(detailFormContainer);
            target.add(containerPanel);
        }

        @SuppressWarnings("unchecked")
        public void onError(AjaxRequestTarget target, Form<?> form) {
            boolean setFocusError = false;
            WebMarkupContainer wmc = (WebMarkupContainer) form.get("detailFormContainer");
            for (Iterator iterator = wmc.iterator(); iterator.hasNext();) {
                Component component = (Component) iterator.next();
                if (component instanceof FormComponent) {
                    FormComponent formComponent = (FormComponent) component;

                    if (!formComponent.isValid()) {
                        if (!setFocusError) {
                            // Place focus on field in error (for the first field in error)
                            target.focusComponent(formComponent);
                            setFocusError = true;
                        }
                    }
                }
            }

            processErrors(target);
        }
    };

    deleteButton = new AjaxDeleteButton(Constants.DELETE, new StringResourceModel("confirmDelete", this, null),
            new StringResourceModel(Constants.DELETE, this, null)) {

        private static final long serialVersionUID = 4005032637149080009L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onDeleteConfirmed(target);
            target.add(feedbackPanel);
            detailContainer.setVisible(false);
            target.add(detailContainer);

            // remove node
            DefaultTreeModel treeModel = (DefaultTreeModel) tree.getDefaultModelObject();
            for (Object selectedNode : tree.getTreeState().getSelectedNodes()) {
                treeModel.removeNodeFromParent((MutableTreeNode) selectedNode);
            }

            tree.updateTree(target);
        }

        @Override
        public boolean isVisible() {
            return (ArkPermissionHelper.isActionPermitted(Constants.DELETE) && !isNew());
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedbackPanel);
        }

        @Override
        public boolean isEnabled() {
            return canDelete();
        }
    };

    //editButton.setDefaultFormProcessing(false);
    cancelButton.setDefaultFormProcessing(false);
    /* Defines a edit mode */
    editButtonContainer = new WebMarkupContainer("editButtonContainer");
    editButtonContainer.setOutputMarkupPlaceholderTag(true);
    editButtonContainer.setVisible(isNew());

    // Initialise in read only
    detailFormContainer = new WebMarkupContainer("detailFormContainer");
    detailFormContainer.setOutputMarkupPlaceholderTag(true);
    detailFormContainer.setEnabled(isNew());

    addComponentsToForm();
}

From source file:com.evolveum.midpoint.web.page.forgetpassword.PageForgotPassword.java

License:Apache License

private ObjectQuery createDynamicFormQuery(Form form) {
    DynamicFormPanel<UserType> userDynamicPanel = (DynamicFormPanel<UserType>) form
            .get(createComponentPath(ID_DYNAMIC_LAYOUT, ID_DYNAMIC_FORM));
    List<ItemPath> filledItems = userDynamicPanel.getChangedItems();
    PrismObject<UserType> user;/*w w w .j  a  v  a2  s . c o m*/
    try {
        user = userDynamicPanel.getObject();
    } catch (SchemaException e1) {
        getSession().error(getString("pageForgetPassword.message.usernotfound"));
        throw new RestartResponseException(PageForgotPassword.class);
    }

    List<EqualFilter> filters = new ArrayList<>();
    QueryFactory queryFactory = getPrismContext().queryFactory();
    for (ItemPath path : filledItems) {
        PrismProperty property = user.findProperty(path);
        EqualFilter filter = queryFactory.createEqual(path, property.getDefinition(), null);
        filter.setValue(property.getAnyValue().clone());
        filters.add(filter);
    }
    return queryFactory.createQuery(queryFactory.createAnd((List) filters));
}

From source file:com.evolveum.midpoint.web.page.forgetpassword.PageForgotPassword.java

License:Apache License

private ObjectQuery createStaticFormQuery(Form form) {
    RequiredTextField<String> usernameTextFiled = (RequiredTextField) form
            .get(createComponentPath(ID_STATIC_LAYOUT, ID_USERNAME_CONTAINER, ID_USERNAME));
    RequiredTextField<String> emailTextField = (RequiredTextField) form
            .get(createComponentPath(ID_STATIC_LAYOUT, ID_EMAIL_CONTAINER, ID_EMAIL));
    String username = usernameTextFiled != null ? usernameTextFiled.getModelObject() : null;
    String email = emailTextField != null ? emailTextField.getModelObject() : null;
    LOGGER.debug("Reset Password user info form submitted. username={}, email={}", username, email);

    ResetPolicyDto resetPasswordPolicy = getResetPasswordPolicy();
    if (resetPasswordPolicy == null) {
        passwordResetNotSupported();// w  w w. j ava  2  s. c  o  m
    }
    ResetMethod method = resetPasswordPolicy.getResetMethod();
    if (method == null) {
        passwordResetNotSupported();
    }

    switch (method) {
    case MAIL:
        return getPrismContext().queryFor(UserType.class).item(UserType.F_EMAIL_ADDRESS).eq(email)
                .matchingCaseIgnore().build();

    case SECURITY_QUESTIONS:
        return getPrismContext().queryFor(UserType.class).item(UserType.F_NAME).eqPoly(username).matchingNorm()
                .and().item(UserType.F_EMAIL_ADDRESS).eq(email).matchingCaseIgnore().build();

    default:
        passwordResetNotSupported();
        return null; // not reached
    }

}

From source file:com.evolveum.midpoint.web.page.self.PageAccountActivation.java

License:Apache License

private void propagatePassword(AjaxRequestTarget target, Form<?> form) {

    List<ShadowType> shadowsToActivate = getShadowsToActivate();

    PasswordTextField passwordPanel = (PasswordTextField) form.get(createComponentPath(ID_PASSWORD));
    String value = passwordPanel.getModelObject();

    ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_GUI_USER_URI);
    UsernamePasswordAuthenticationToken token;
    try {// ww  w  .j av  a  2s.  c om
        token = authenticationEvaluator.authenticate(connEnv,
                new PasswordAuthenticationContext(userModel.getObject().getName().getOrig(), value));
    } catch (Exception ex) {
        LOGGER.error("Failed to authenticate user, reason {}", ex.getMessage());
        getSession().error(getString("PageAccountActivation.authentication.failed"));
        throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
    }
    if (token == null) {
        LOGGER.error("Failed to authenticate user");
        getSession().error(getString("PageAccountActivation.authentication.failed"));
        throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
    }
    ProtectedStringType passwordValue = new ProtectedStringType();
    passwordValue.setClearValue(value);

    Collection<ObjectDelta<ShadowType>> passwordDeltas = new ArrayList<>(shadowsToActivate.size());
    for (ShadowType shadow : shadowsToActivate) {
        ObjectDelta<ShadowType> shadowDelta = getPrismContext().deltaFactory().object()
                .createModificationReplaceProperty(ShadowType.class, shadow.getOid(),
                        SchemaConstants.PATH_PASSWORD_VALUE, passwordValue);
        shadowDelta.addModificationReplaceProperty(ShadowType.F_LIFECYCLE_STATE,
                SchemaConstants.LIFECYCLE_PROPOSED);
        passwordDeltas.add(shadowDelta);
    }

    OperationResult result = runPrivileged(new Producer<OperationResult>() {
        private static final long serialVersionUID = 1L;

        @Override
        public OperationResult run() {
            OperationResult result = new OperationResult(OPERATION_ACTIVATE_SHADOWS);
            Task task = createAnonymousTask(OPERATION_ACTIVATE_SHADOWS);
            WebModelServiceUtils.save((Collection) passwordDeltas, null, result, task,
                    PageAccountActivation.this);
            return result;
        }
    });

    result.recomputeStatus();

    if (!result.isSuccess()) {
        getSession().error(getString("PageAccountActivation.account.activation.failed"));
        LOGGER.error("Failed to acitvate accounts, reason: {} ", result.getMessage());
        target.add(getFeedbackPanel());
    } else {
        getSession().success(getString("PageAccountActivation.account.activation.successful"));
        target.add(getFeedbackPanel());
        activated = true;
    }

    target.add(PageAccountActivation.this);

}

From source file:com.francetelecom.clara.cloud.presentation.designer.pages.DesignerPage.java

License:Apache License

public void addOrUpdateLogicalService(Form<?> form, AjaxRequestTarget target, boolean isNew) {

    LogicalModelItem service = (LogicalModelItem) form.getModelObject();

    if (!checkServiceExistence(service)) {
        // TODO REFACTOR.... Too bad to set maven reference extension here
        if (service instanceof LogicalSoapService) {
            MavenReference mavenReference = ((LogicalSoapService) service).getServiceAttachments();
            mavenReference.setExtension("jar");

            try {
                WebMarkupContainer fullvalidationContent = (WebMarkupContainer) form
                        .get("fullvalidationContent");
                CheckBox fullvalidation = (CheckBox) fullvalidationContent.get("fullvalidation");
                manageLogicalDeployment.checkLogicalSoapServiceConsistency((LogicalSoapService) service,
                        fullvalidation.getModelObject());
            } catch (BusinessException ex) {
                BusinessExceptionHandler handler = new BusinessExceptionHandler(this);
                handler.error(ex);// w  w w  .j  a va2s .c o  m
                target.add(getFeedbackPanel());
            }
        }

        if (service instanceof LogicalRelationalService
                && ((LogicalRelationalService) service).getInitialPopulationScript() != null) {
            MavenReference sqlInitScript = ((LogicalRelationalService) service).getInitialPopulationScript();

            if (sqlInitScript.getGroupId() == null && sqlInitScript.getArtifactId() == null
                    && sqlInitScript.getVersion() == null) {
                ((LogicalRelationalService) service).setInitialPopulationScript(null);
            } else {
                if (sqlInitScript.getClassifier() == null) {
                    sqlInitScript.setClassifier("");
                    sqlInitScript.setExtension("sql");
                }
                sqlInitScript.setExtension("sql");
            }

        }

        if (isNew) {
            if (service instanceof LogicalService) {
                logicalDeployment.addLogicalService((LogicalService) service);
            } else if (service instanceof ProcessingNode) {
                if (service instanceof JeeProcessing) {
                    ((ProcessingNode) service).getSoftwareReference().setExtension("ear");
                }
                logicalDeployment.addExecutionNode((ProcessingNode) service);
            }
        }

        saveLogicalDeployment(logicalDeployment);

        //            DesignerArchitectureMatrixPanel matrixPanel = ((DesignerArchitectureMatrixPanel) get("matrix"));
        //            matrixPanel.updateTable();

        serviceDefinitionPanel.updateServiceFormPanel(target, null, this, true);

        updateMatrixPanel(target);

        //            target.addComponent(matrixPanel);

    } else {
        form.get("label").error(getString("portal.designer.service.already.exist.error",
                new Model<String[]>(new String[] { ((RequiredTextField) form.get("label")).getInput() })));
        target.add(form);
    }

}

From source file:com.tysanclan.site.projectewok.pages.member.senate.ModifyRegulationPage.java

License:Open Source License

/**
*///from www  .j  ava2  s .  co m
private Form<RegulationChange> createModifyForm() {
    Form<RegulationChange> form = new Form<RegulationChange>("editForm") {
        private static final long serialVersionUID = 1L;

        @SpringBean
        private DemocracyService democracyService;

        /**
         * @see org.apache.wicket.markup.html.form.Form#onSubmit()
         */
        @SuppressWarnings("unchecked")
        @Override
        protected void onSubmit() {
            TextArea<String> descriptionArea = (TextArea<String>) get("description");
            TextField<String> newTitleField = (TextField<String>) get("newTitle");
            DropDownChoice<Regulation> regulationChoice = (DropDownChoice<Regulation>) get("regulation");

            String newDescription = descriptionArea.getModelObject();
            String newTitle = newTitleField.getModelObject();
            Regulation regulation = regulationChoice.getModelObject();

            RegulationChange vote = democracyService.createModifyRegulationVote(getUser(), regulation, newTitle,
                    newDescription);
            if (vote != null) {
                if (getUser().getRank() == Rank.SENATOR) {
                    setResponsePage(new RegulationModificationPage());
                } else {
                    setResponsePage(new VetoPage());
                }
            }

        }

    };

    form.add(new TextField<String>("newTitle", new Model<String>("")));

    form.add(new BBCodeTextArea("description", "").setRequired(true));

    form.add(new Label("example", new Model<String>("")).setEscapeModelStrings(false).setVisible(false)
            .setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true));

    form.add(new DropDownChoice<Regulation>("regulation", ModelMaker.wrap((Regulation) null, true),
            ModelMaker.wrapChoices(regulationDAO.findAll()), new IChoiceRenderer<Regulation>() {
                private static final long serialVersionUID = 1L;

                /**
                 * @see org.apache.wicket.markup.html.form.IChoiceRenderer#getDisplayValue(java.lang.Object)
                 */
                @Override
                public Object getDisplayValue(Regulation object) {
                    return object.getName();
                }

                /**
                 * @see org.apache.wicket.markup.html.form.IChoiceRenderer#getIdValue(java.lang.Object,
                 *      int)
                 */
                @Override
                public String getIdValue(Regulation object, int index) {
                    return object.getId().toString();
                }
            }).setNullValid(false).add(new AjaxFormComponentUpdatingBehavior("onchange") {
                private static final long serialVersionUID = 1L;

                @SuppressWarnings("unchecked")
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    System.out.println("FOO!!");
                    Form<Regulation> regForm = (Form<Regulation>) getComponent().getParent();
                    Label example = (Label) regForm.get("example");

                    DropDownChoice<Regulation> regulationChoice = (DropDownChoice<Regulation>) regForm
                            .get("regulation");
                    Regulation regulation = regulationChoice.getModelObject();

                    if (regulation != null) {

                        Component example2 = new Label("example", new Model<String>(regulation.getContents()))
                                .setEscapeModelStrings(false).setVisible(true).setOutputMarkupId(true)
                                .setOutputMarkupPlaceholderTag(true);

                        example.replaceWith(example2);

                        if (target != null) {
                            target.add(example2);
                        }
                    } else {
                        example.setVisible(false);
                        if (target != null) {
                            target.add(example);
                        }
                    }
                }

            }));

    return form;
}

From source file:com.tysanclan.site.projectewok.pages.member.senate.RepealRegulationPage.java

License:Open Source License

/**
*//*ww w .  jav  a 2  s .c  o m*/
private Form<RegulationChange> createRepealForm() {
    Form<RegulationChange> form = new Form<RegulationChange>("repealForm") {
        private static final long serialVersionUID = 1L;

        @SpringBean
        private DemocracyService democracyService;

        /**
         * @see org.apache.wicket.markup.html.form.Form#onSubmit()
         */
        @SuppressWarnings("unchecked")
        @Override
        protected void onSubmit() {
            DropDownChoice<Regulation> regulationChoice = (DropDownChoice<Regulation>) get("regulation");

            Regulation regulation = regulationChoice.getModelObject();

            RegulationChange vote = democracyService.createRepealRegulationVote(getUser(), regulation);
            if (vote != null) {
                if (getUser().getRank() == Rank.SENATOR) {
                    setResponsePage(new RegulationModificationPage());
                } else {
                    setResponsePage(new VetoPage());
                }
            }

        }

    };

    RegulationChangeFilter filter = new RegulationChangeFilter();
    filter.setUser(getUser());

    if (regulationChangeDAO.countByFilter(filter) > 0) {
        error("You have already submitted a regulation change proposal. You can not submit more than 1 simultaneously.");
        form.setEnabled(false);
    }

    form.add(new Label("example", new Model<String>("")).setEscapeModelStrings(false).setVisible(false)
            .setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true));

    form.add(new DropDownChoice<Regulation>("regulation", ModelMaker.wrap((Regulation) null, true),
            ModelMaker.wrapChoices(regulationDAO.findAll()), new IChoiceRenderer<Regulation>() {
                private static final long serialVersionUID = 1L;

                /**
                 * @see org.apache.wicket.markup.html.form.IChoiceRenderer#getDisplayValue(java.lang.Object)
                 */
                @Override
                public Object getDisplayValue(Regulation object) {
                    return object.getName();
                }

                /**
                 * @see org.apache.wicket.markup.html.form.IChoiceRenderer#getIdValue(java.lang.Object,
                 *      int)
                 */
                @Override
                public String getIdValue(Regulation object, int index) {
                    return object.getId().toString();
                }
            }).setNullValid(false).add(new AjaxFormComponentUpdatingBehavior("onchange") {
                private static final long serialVersionUID = 1L;

                @SuppressWarnings("unchecked")
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    Form<Regulation> regForm = (Form<Regulation>) getComponent().getParent();
                    Label example = (Label) regForm.get("example");

                    DropDownChoice<Regulation> regulationChoice = (DropDownChoice<Regulation>) regForm
                            .get("regulation");
                    Regulation regulation = regulationChoice.getModelObject();

                    if (regulation != null) {

                        Component example2 = new Label("example", new Model<String>(regulation.getContents()))
                                .setEscapeModelStrings(false).setVisible(true).setOutputMarkupId(true)
                                .setOutputMarkupPlaceholderTag(true);

                        example.replaceWith(example2);

                        if (target != null) {
                            target.add(example2);
                        }
                    } else {
                        example.setVisible(false);
                        if (target != null) {
                            target.add(example);
                        }
                    }
                }

            }));

    return form;
}

From source file:com.userweave.pages.configuration.editentitypanel.EditQuestionEntityWebPage.java

License:Open Source License

@Override
protected WebMarkupContainer getAcceptButton(String componentId, final ModalWindow window) {
    return new AjaxButton(componentId, getForm()) {
        private static final long serialVersionUID = 1L;

        @Override//  ww w. j a v a  2  s.  com
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            String q = (String) ((TextField) form.get("name")).getModelObject();

            Question question = getQuestion();

            question.setName(new LocalizedString(q, locale));

            questionService.saveQuestion(configurationId, question);

            window.close(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
        }
    };
}

From source file:gr.interamerican.wicket.bo2.validation.BusinessObjectFormValidator.java

License:Open Source License

/**
 * Creates a new BusinessObjectFormValidator object.
 * @param formToValidate //from  w  w  w.  j  a v a 2s  .c o  m
 * @param descriptor 
 */
public BusinessObjectFormValidator(Form<?> formToValidate, BusinessObjectDescriptor<?> descriptor) {
    this.expressions = descriptor.getExpressions();
    if (!(formToValidate instanceof SelfDrawnForm)) {
        throw new RuntimeException(
                "BusinessObjectFormValidator will not work for a Form that is not a SelfDrawnForm"); //$NON-NLS-1$
    }
    MarkupContainer selfDrawnPanel = (MarkupContainer) formToValidate.get(SelfDrawnForm.PANEL_WICKET_ID);
    List<FormComponent<?>> componentsList = new ArrayList<FormComponent<?>>();
    for (String property : DescriptorUtils.getPropertyNames(descriptor)) {
        Component cmp = SelfDrawnUtils.getComponentFromSelfDrawnPanel(selfDrawnPanel, property);
        if (cmp instanceof FormComponent) {
            FormComponent<?> fc = (FormComponent<?>) cmp;
            componentsList.add(fc);
            index.put(property, fc);
        }
    }
    components = componentsList.toArray(new FormComponent[0]);
}