List of usage examples for org.apache.wicket.markup.html.form Radio getLabel
@Override
public IModel<String> getLabel()
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.QuestionCategoryRadioPanel.java
License:Open Source License
/** * Constructor.//from w ww . j a v a2 s. 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); } } }