Example usage for org.apache.wicket.markup.html.form FormComponentLabel FormComponentLabel

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

Introduction

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

Prototype

public FormComponentLabel(String id, LabeledWebMarkupContainer component) 

Source Link

Document

Constructor

Usage

From source file:name.martingeisse.wicket.simpleform.DecoratorBuilder.java

License:Open Source License

/**
 * <p>/*www .  ja  v a2 s.co m*/
 * Adds a decorator by providing all the parts yourself.
 * </p>
 * 
 * <p>
 * Form component options <b>do not apply</b> here, as this method doesn't know about form
 * components at all. It handles the decorated body in a black-box way.
 * </p>
 *
 * @param decoratedBody the decorated body to wrap
 * @param labelTarget the component to refer to in the "for" attribute of the label.
 * This parameter may be null; in this case, the "for" attribute will be omitted.
 * @param errorSource the source for error messages. This parameter may be null;
 * in this case, no error messages will be shown.
 */
public final void addDecorator(final Component decoratedBody, final LabeledWebMarkupContainer labelTarget,
        final Component errorSource) {
    final Fragment decoratorFragment = panel.createBuiltInFormBlockFragment("decoratorFragment");
    decoratorFragment.add(new BootstrapComponentFeedbackPanel("error", errorSource));
    decoratorFragment.add(new FormComponentLabel("label", labelTarget).add(new Label("text", labelModel)));
    decoratorFragment.add(new Label("helpText", helpTextModel));
    decoratorFragment.add(new Label("toolLinks").setVisible(false));
    decoratorFragment.add(decoratedBody);
    panel.addFormBlock(decoratorFragment);
}

From source file:org.antbear.jee.wicket.guestbook.web.AddEntryPanel.java

License:Apache License

public AddEntryPanel(final String id, final Long guestbookId) {
    super(id);/*from   ww  w  . j  a  v  a2 s  . c  o m*/
    add(new FeedbackPanel("feedback"));

    Form<Entry> form = new Form<Entry>("form", new CompoundPropertyModel<Entry>(new Entry())) {
        private static final long serialVersionUID = 1L;

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

            Entry entry = getModel().getObject();
            entry.setCreationDate(new GregorianCalendar(getLocale()).getTime());

            // Persist entry by merging
            assert guestbookService != null;
            Guestbook guestbook = guestbookService.find(guestbookId);
            entry.setGuestbook(guestbook);
            guestbook.add(entry);
            guestbookService.merge(guestbook);

            // Create new fresh entry for next submit
            Entry freshEntry = new Entry();
            getModel().setObject(freshEntry);

            info("Your comment has been added.");

            // Notify observer, if any
            if (entrySubmitObserver != null)
                entrySubmitObserver.entrySubmitted();
        }
    };
    add(form);

    RequiredTextField<String> name = new RequiredTextField<String>("authorName");
    name.setLabel(new Model<String>("Name"));
    FormComponentLabel nameLabel = new FormComponentLabel("authorNameLabel", name);
    form.add(nameLabel);
    form.add(name);

    RequiredTextField<String> email = new RequiredTextField<String>("authorEmail");
    email.add(EmailAddressValidator.getInstance());
    email.setLabel(new Model<String>("Email"));
    FormComponentLabel emailLabel = new FormComponentLabel("authorEmailLabel", name);
    form.add(emailLabel);
    form.add(email);

    TextArea<String> text = new TextArea<String>("text");
    text.setRequired(true).setLabel(new Model<String>("Text"));
    FormComponentLabel textLabel = new FormComponentLabel("textLabel", text);
    form.add(textLabel);
    form.add(text);
}

From source file:org.apache.isis.viewer.wicket.ui.components.widgets.valuechoices.ValueChoices.java

License:Apache License

protected FormComponentLabel createFormComponentLabel() {
    final String name = getModel().getName();
    valueField.setLabel(Model.of(name));

    final FormComponentLabel labelIfRegular = new FormComponentLabel(ID_SCALAR_IF_REGULAR, valueField);

    final String describedAs = getModel().getDescribedAs();
    if (describedAs != null) {
        labelIfRegular.add(new AttributeModifier("title", Model.of(describedAs)));
    }//w w  w  . ja va  2 s  .  co m

    final Label scalarName = new Label(ID_SCALAR_NAME, getRendering().getLabelCaption(valueField));
    labelIfRegular.add(scalarName);
    labelIfRegular.add(valueField);

    // scalarNameAndValue.add(dropDownChoicesForValueMementos);

    return labelIfRegular;
}

From source file:org.cast.cwm.data.component.FormComponentContainer.java

License:Open Source License

/**
 * Constructor.  The component is added here, so you do not add it
 * in a separate statement./*from  w  w  w . j  a  va 2  s .co m*/
 * 
 * @param id
 * @param component
 */
public FormComponentContainer(String id, FormComponent<?> component) {
    super(id);

    setOutputMarkupPlaceholderTag(true);

    this.formComponent = component;

    // TODO: Create custom feedback border that shows a filter based on FormComponentContainer
    // TODO: OR see if you can add the component directly to the feedbackBorder
    addToBorder(new FormComponentLabel("label", formComponent)
            .add(new Label("labelText", new PropertyModel<String>(FormComponentContainer.this, "label"))));

    addToBorder(new WebMarkupContainer("errorIndicator") {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return hasErrors;
        }
    });

    add(component);
}

From source file:org.cast.isi.component.QuickFlipForm.java

License:Open Source License

public QuickFlipForm(String id, boolean addLabel, Integer currentPage) {
    super(id);//w  ww.j  a  v a2s.co m
    Model<String> numberModel;
    if (currentPage != null)
        numberModel = new Model<String>(currentPage.toString());
    else
        numberModel = new Model<String>("");
    TextField<String> numberField = new TextField<String>("numberField", numberModel);
    add(numberField);
    if (addLabel) {
        FormComponentLabel numberFieldLabel = new FormComponentLabel("numberFieldLabel", numberField);
        add(numberFieldLabel);
    }
    add(new SubmitLink("goLink"));
}

From source file:org.cast.isi.component.SingleSelectItem.java

License:Open Source License

public SingleSelectItem(String id, IModel<String> model, boolean correct) {
    super(id, model);
    this.correct = correct;
    final Radio<String> radio = new Radio<String>("radio", model);
    add(radio);/*ww w. ja  v a2 s  . com*/
    add(new FormComponentLabel("label", radio));
    radio.add(new AjaxEventBehavior("onclick") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            notifyListeners(target, SingleSelectItem.this);
        }
    });

}

From source file:org.cast.isi.panel.PeriodStudentSelectPanel.java

License:Open Source License

public PeriodStudentSelectPanel(String id, final boolean showStudents) {
    super(id);/*from w  ww.j a v a 2s  . co  m*/
    setOutputMarkupId(true);
    periodStudentSelectForm = new Form<Void>("periodStudentSelectForm") {

        @Override
        protected void onSubmit() {
            PeriodStudentSelectPanel.this.onFormSubmit(); // Subclass defined actions
            super.onSubmit();
        }
    };
    add(periodStudentSelectForm);
    periodStudentSelectForm.setOutputMarkupId(true);

    // Period Chooser
    periodChoice = new PeriodChoice("periodChoice", ISISession.get().getCurrentPeriodModel()); // Set default period from session
    periodChoice.add(new AttributeModifier("autocomplete", "off"));
    periodChoice.setOutputMarkupId(true);

    // Set Period onChange Behavior
    periodChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            ISISession.get().setStudentModel(null); // Reset session's selected student since period changed
            ISISession.get().setCurrentPeriodModel(periodChoice.getModel()); // Save period change in session
            // Save current site information
            Site currentSite = ISISession.get().getCurrentPeriodModel().getObject().getSite();
            IModel<Site> mCurrentSite = new Model<Site>(currentSite);
            ISISession.get().setCurrentSiteModel(mCurrentSite);
            if (showStudents) {
                studentChoice.setChoices(getUserListModel()); // Alert student drop-down of the change               
                studentChoice.setModel(new UserModel());
                target.add(studentChoice);
            }
            target.add(feedback); // Update Feedback Panel
            target.add(periodChoice);
            PeriodStudentSelectPanel.this.onPeriodUpdate(target); // Subclass defined actions
        }
    });
    // make sure the label is linked to the period dropdown      
    FormComponentLabel periodChoiceLabel = (new FormComponentLabel("periodChoiceLabel", periodChoice));
    periodStudentSelectForm.add(periodChoiceLabel);
    periodStudentSelectForm.add(periodChoice);

    // Student Chooser
    IModel<User> studentModel = ISISession.get().getStudentModel();
    if (studentModel == null) {
        studentModel = new UserModel();
    }
    studentChoice = new UserChoice("studentChoice", studentModel, getUserListModel());
    periodStudentSelectForm.add(studentChoice);
    studentChoice.setNullValid(true);
    if (studentChoice.getModelObject() == null) { // If session did not have a student or student was not in the session's period, reset session's student
        ISISession.get().setStudentModel(null);
    }
    studentChoice.setOutputMarkupPlaceholderTag(true);

    // Set Student onChange Behavior
    studentChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            ISISession.get().setStudentModel(studentChoice.getModel()); // Save student change in session
            target.add(feedback);
            target.add(studentChoice);
            PeriodStudentSelectPanel.this.onStudentUpdate(target); // Subclass defined actions
        }
    });
    if (!showStudents) {
        studentChoice.setVisible(false);
    }
    // make sure the label is linked to the student dropdown      
    FormComponentLabel studentChoiceLabel = (new FormComponentLabel("studentChoiceLabel", studentChoice));
    periodStudentSelectForm.add(studentChoiceLabel);

    feedback = new FeedbackPanel("feedback", new ContainerFeedbackMessageFilter(periodStudentSelectForm));
    feedback.setOutputMarkupId(true);
    feedback.setMaxMessages(1);
    periodStudentSelectForm.add(feedback);

}

From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.QuestionCategoryCheckBoxPanel.java

License:Open Source License

/**
 * Constructor.//  w  w  w .  java  2  s . c  o m
 * 
 * @param id
 * @param questionModel
 * @param questionCategoryModel
 * @param selectionsModel check group selections model
 * @param radioLabelVisible
 */
@SuppressWarnings("serial")
public QuestionCategoryCheckBoxPanel(String id, IModel<Question> questionModel,
        IModel<QuestionCategory> questionCategoryModel,
        IModel<Collection<IModel<QuestionCategory>>> selectionsModel, boolean radioLabelVisible) {
    super(id, questionModel, questionCategoryModel);
    setOutputMarkupId(true);

    // previous answer or default selection
    QuestionCategory questionCategory = (QuestionCategory) getDefaultModelObject();
    QuestionCategoryCheckBoxModel selectionModel = new QuestionCategoryCheckBoxModel(selectionsModel,
            questionCategoryModel);

    if (!activeQuestionnaireAdministrationService.isQuestionnaireDevelopmentMode()) {
        CategoryAnswer previousAnswer = activeQuestionnaireAdministrationService
                .findAnswer(questionModel.getObject(), questionCategory);
        if (previousAnswer != null)
            selectionModel.select();
    }

    checkbox = new CheckBox("checkbox", selectionModel);
    checkbox.setLabel(new QuestionnaireStringResourceModel(questionCategoryModel, "label"));

    // persist selection on change event
    // and make sure there is no active open field previously selected
    if (!activeQuestionnaireAdministrationService.isQuestionnaireDevelopmentMode()) {
        checkbox.add(new AjaxEventBehavior("onchange") {

            @Override
            protected void onEvent(AjaxRequestTarget target) {
                // toggle selection
                // note: call for setModelObject to ensure modelChanged trigger is properly called
                checkbox.setModelObject(!getSelectionModel().isSelected());

                if (getSelectionModel().isSelected()) {
                    activeQuestionnaireAdministrationService.answer(getQuestion(), getQuestionCategory(),
                            getQuestionCategory().getCategory().getOpenAnswerDefinition(), null);
                } else {
                    activeQuestionnaireAdministrationService.deleteAnswer(getQuestion(), getQuestionCategory());
                }
                if (getOpenField() != null) {
                    if (!getSelectionModel().isSelected()) {
                        resetOpenAnswerDefinitionPanels(target, getOpenField(), getQuestionCategoryModel());
                        updateFeedbackPanel(target);
                    }
                }

                fireQuestionCategorySelection(target, getQuestionModel(), getQuestionCategoryModel(),
                        getSelectionModel().isSelected());
            }

        });
    }

    FormComponentLabel checkboxLabel = new FormComponentLabel("categoryLabel", checkbox);
    add(checkboxLabel);
    checkboxLabel.add(checkbox);
    checkboxLabel.add(new Label("label", checkbox.getLabel()).setRenderBodyOnly(true)
            .setVisible(radioLabelVisible).setEscapeModelStrings(false));

    if (questionCategory.getCategory().getOpenAnswerDefinition() != null) {
        // there is an open field
        openField = newOpenAnswerDefinitionPanel("open");
        add(openField);

        checkbox.add(new AttributeAppender("class", new Model<String>("checkbox-open"), " "));
        checkboxLabel.add(new AttributeModifier("class", new Model<String>("label-open")));

    } else {
        // no open answer
        add(new EmptyPanel("open").setVisible(false));
    }
}

From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.QuestionCategoryRadioPanel.java

License:Open Source License

/**
 * Constructor./*from   w w w  .  ja va 2s  . c  o  m*/
 * 
 * @param id
 * @param questionModel
 * @param questionCategoryModel
 * @param radioLabelVisible
 */
@SuppressWarnings("serial")
public QuestionCategoryRadioPanel(String id, IModel<Question> questionModel,
        IModel<QuestionCategory> questionCategoryModel, RadioGroup<QuestionCategory> radioGroup,
        boolean radioLabelVisible) {
    super(id, questionModel, questionCategoryModel);
    this.radioGroup = radioGroup;

    // previous answer or default selection
    QuestionCategory questionCategory = (QuestionCategory) questionCategoryModel.getObject();
    Question question = (Question) questionModel.getObject();

    Radio<QuestionCategory> radio = new Radio<QuestionCategory>("radio", questionCategoryModel);
    radio.setLabel(new QuestionnaireStringResourceModel(questionCategoryModel, "label"));
    // persist selection on change event
    // and make sure there is no active open field previously selected
    if (!activeQuestionnaireAdministrationService.isQuestionnaireDevelopmentMode()) {
        radio.add(new AjaxEventBehavior("onchange") {

            @Override
            protected void onEvent(AjaxRequestTarget target) {

                // make the radio group active for the selection
                QuestionCategoryRadioPanel.this.radioGroup.setModel(getQuestionCategoryModel());

                // exclusive choice, only one answer per question
                activeQuestionnaireAdministrationService.deleteAnswers(getQuestion());
                activeQuestionnaireAdministrationService.answer(getQuestion(), getQuestionCategory());

                // make sure a previously selected open field is not asked for
                resetOpenAnswerDefinitionPanels(target, QuestionCategoryRadioPanel.this.radioGroup,
                        getQuestionCategoryModel());

                updateFeedbackPanel(target);

                fireQuestionCategorySelection(target, getQuestionModel(), getQuestionCategoryModel(), true);
            }

        });
    }

    FormComponentLabel radioLabel = new FormComponentLabel("categoryLabel", radio);
    add(radioLabel);
    radioLabel.add(radio);
    radioLabel.add(new Label("label", radio.getLabel()).setRenderBodyOnly(true).setVisible(radioLabelVisible)
            .setEscapeModelStrings(false));

    if (questionCategory.getCategory().getOpenAnswerDefinition() != null) {
        // there is an open field
        openField = newOpenAnswerDefinitionPanel("open");
        add(openField);

        // make radio associated to open answer optionally visible using css styling
        radio.add(new AttributeAppender("class", new Model<String>("radio-open"), " "));
        radioLabel.add(new AttributeModifier("class", new Model<String>("label-open")));

    } else {
        // no open answer
        add(new EmptyPanel("open").setVisible(false));
    }

    // previous answer or default selection
    if (!activeQuestionnaireAdministrationService.isQuestionnaireDevelopmentMode()) {
        CategoryAnswer previousAnswer = activeQuestionnaireAdministrationService.findAnswer(question,
                questionCategory);

        if (previousAnswer != null) {
            radioGroup.setModel(questionCategoryModel);
        }
    }

}

From source file:org.obiba.onyx.wicket.contraindication.ObservedContraIndicationPanel.java

License:Open Source License

@SuppressWarnings("serial")
public ObservedContraIndicationPanel(String id, IModel<IContraindicatable> contraindicatable) {
    super(id, contraindicatable);
    setOutputMarkupId(true);//from  ww w  . j  a v  a  2  s  . c  o  m

    final RadioGroup radioGroup = new RadioGroup("radioGroup", new PropertyModel(this, "selectedRadio"));
    radioGroup.setLabel(new StringResourceModel("ContraIndication", this, null));
    radioGroup.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            log.info("radioGroup.onUpdate={}", selectedRadio);
            if (selectedRadio.equals(NO)) {
                log.info("invalidating models");
                contraIndicationDropDownChoice.setModelObject(null);
                otherContraIndication.setModelObject(null);
            }
            target.addComponent(ObservedContraIndicationPanel.this);
            target.appendJavascript("Resizer.resizeWizard();");
        }
    });
    add(radioGroup);
    ListView radioList = new ListView("radioItem", Arrays.asList(new String[] { YES, NO })) {

        @Override
        protected void populateItem(final ListItem item) {
            Radio radio = new Radio("radio", item.getModel());
            radio.setLabel(new StringResourceModel((String) item.getModelObject(),
                    ObservedContraIndicationPanel.this, null));
            item.add(radio);
            item.add(new SimpleFormComponentLabel("radioLabel", radio));
        }

    }.setReuseItems(true);
    radioGroup.add(radioList);
    radioGroup.setRequired(true);

    contraIndicationDropDownChoice = new DropDownChoice("ciChoice",
            new PropertyModel(getDefaultModel(), "contraindication"),
            getContraindicatable().getContraindications(Contraindication.Type.OBSERVED),
            new ContraindicationChoiceRenderer()) {

        @Override
        public boolean isEnabled() {
            // return selectedRadio == null || selectedRadio.equals(YES);
            return (selectedRadio == null) ? false : selectedRadio.equals(YES);
        }

        @Override
        public boolean isRequired() {
            return isEnabled();
        }
    };
    contraIndicationDropDownChoice.setOutputMarkupId(true);
    contraIndicationDropDownChoice.setLabel(new StringResourceModel("ContraIndicationSelection", this, null));

    // Use an OnChangeAjaxBehavior so that the form submission happens, but only for this component
    // This allows us to have the model set to the proper value
    contraIndicationDropDownChoice.add(new OnChangeAjaxBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            log.debug("contraIndicationDropDownChoice.onUpdate() selectedRadio={} selectedCi={}", selectedRadio,
                    getContraindicatable().getContraindication());
            // make sure the right radio is selected
            // use setModelObject in order to let the RadioGroup component be aware of the change.
            radioGroup.setModelObject(getContraindicatable().isContraindicated() ? YES : NO);

            // Invalidate the reason.
            otherContraIndication.setModelObject(null);
            target.addComponent(ObservedContraIndicationPanel.this);
            target.appendJavascript("Resizer.resizeWizard();");
        }

    });
    add(contraIndicationDropDownChoice);

    otherContraIndication = new TextArea("otherCi",
            new PropertyModel(getDefaultModel(), "otherContraindication")) {

        @Override
        public boolean isVisible() {
            // The text area and its associated label should only be displayed when the selected contraindication requires a
            // description. The label's visibility is bound to the text area visibility using a <wicket:enclosure> tag in
            // the markup.
            Contraindication selectedCi = (Contraindication) contraIndicationDropDownChoice.getModelObject();
            return contraIndicationDropDownChoice.isEnabled() && selectedCi != null
                    && selectedCi.getRequiresDescription();
        }

        @Override
        public boolean isRequired() {
            return isVisible();
        }

    };
    otherContraIndication.setOutputMarkupId(true);
    otherContraIndication.setLabel(new StringResourceModel("OtherContraIndication", this, null));
    otherContraIndication.add(new StringValidator.MaximumLengthValidator(2000));
    add(otherContraIndication);

    FormComponentLabel otherContraIndicationLabel = new FormComponentLabel("otherLabel", otherContraIndication);
    add(otherContraIndicationLabel);
}