private void setFormFieldsFromQuestion(Question question) {
    Answer.AnswerType aType = question.getAnswerType();

    questionTitleField.setModelObject(question.getTitle());
    questionPromptField.setModelObject(question.getPrompt());
    questionPrefaceField.setModelObject(question.getPreface());
    questionCitationField.setModelObject(question.getCitation());
    questionResponseTypeModel.setObject(question.getAnswerType());
    Long answerReasonId = question.getAnswerReasonExpressionId();
    questionAnswerReasonModel.setObject(
        answerReasonId == null ? answerAlways : Expressions.get(answerReasonId));
    String msg = "Asking style in setFormFields: " + askingStyleModel.getObject();
    askingStyleModel.setObject(question.getAskingStyleList());
    msg +=
        " -> "
            + askingStyleModel.getObject()
            + " (question had "
            + question.getAskingStyleList()
            + ")";
    // throw new RuntimeException(msg);
    // questionUseIfField.setModelObject(question.getUseIfExpression());
    otherSpecifyCheckBox.setModelObject(question.getOtherSpecify());
    noneButtonCheckBox.setModelObject(question.getNoneButton());
    if (aType == Answer.AnswerType.NUMERICAL) {
      numericLimitsPanel.setVisible(true);
    } else if (aType == Answer.AnswerType.MULTIPLE_SELECTION) {
      multipleSelectionLimitsPanel.setVisible(true);
      noneButtonLabel.setVisible(true);
      noneButtonCheckBox.setVisible(true);
    }
    if (aType == Answer.AnswerType.SELECTION || aType == Answer.AnswerType.MULTIPLE_SELECTION) {
      otherSpecifyLabel.setVisible(true);
      otherSpecifyCheckBox.setVisible(true);
    } else {
      otherSpecifyLabel.setVisible(false);
      otherSpecifyCheckBox.setVisible(false);
    }
    if (aType == Answer.AnswerType.DATE || aType == Answer.AnswerType.TIME_SPAN) {
      timeUnitsPanel.setVisible(true);
    } else {
      timeUnitsPanel.setVisible(false);
    }
    numericLimitsPanel.setMinLimitType(question.getMinLimitType());
    numericLimitsPanel.setMinLiteral(question.getMinLiteral());
    numericLimitsPanel.setMinPrevQues(question.getMinPrevQues());
    numericLimitsPanel.setMaxLimitType(question.getMaxLimitType());
    numericLimitsPanel.setMaxLiteral(question.getMaxLiteral());
    numericLimitsPanel.setMaxPrevQues(question.getMaxPrevQues());

    multipleSelectionLimitsPanel.setMinCheckableBoxes(question.getMinCheckableBoxes());
    multipleSelectionLimitsPanel.setMaxCheckableBoxes(question.getMaxCheckableBoxes());

    listLimitsPanel.setQuestion(question);
  }
  private void build() {

    feedbackPanel = new FeedbackPanel("feedback");
    add(feedbackPanel);

    form = new Form("questionForm");
    form.setOutputMarkupId(true);

    questionTitleField = new TextField("questionTitleField", new Model(""));
    questionTitleField.setRequired(true);
    questionTitleField.add(new FocusOnLoadBehavior());
    form.add(questionTitleField);

    if (question.getType().equals(Question.QuestionType.ALTER)) {
      form.add(new Label("promptHelpText", "(Refer to the alter as $$)"));
    } else if (question.getType().equals(Question.QuestionType.ALTER_PAIR)) {
      form.add(new Label("promptHelpText", "(Refer to the alters as $$1 and $$2)"));
    } else {
      form.add(new Label("promptHelpText", ""));
    }

    numericLimitsPanel = new NumericLimitsPanel("numericLimitsPanel", question);
    form.add(numericLimitsPanel);
    numericLimitsPanel.setVisible(false);

    multipleSelectionLimitsPanel = new MultipleSelectionLimitsPanel("multipleSelectionLimitsPanel");
    form.add(multipleSelectionLimitsPanel);
    multipleSelectionLimitsPanel.setVisible(false);

    timeUnitsPanel = new TimeUnitsPanel("timeUnitsPanel", question);
    form.add(timeUnitsPanel);
    timeUnitsPanel.setVisible(false);

    listLimitsPanel = new ListLimitsPanel("listLimitsPanel", question);
    form.add(listLimitsPanel);
    listLimitsPanel.setVisible(question.getAskingStyleList());

    questionPromptField = new TextArea("questionPromptField", new Model(""));
    questionPromptField.setRequired(true);
    form.add(questionPromptField);

    questionPrefaceField = new TextArea("questionPrefaceField", new Model(""));
    form.add(questionPrefaceField);

    questionCitationField = new TextArea("questionCitationField", new Model(""));
    form.add(questionCitationField);

    questionResponseTypeModel = new Model(Answer.AnswerType.TEXTUAL); // Could also leave this null.
    dropDownQuestionTypes =
        new DropDownChoice(
            "questionResponseTypeField",
            questionResponseTypeModel,
            Arrays.asList(Answer.AnswerType.values()));

    dropDownQuestionTypes.add(
        new AjaxFormComponentUpdatingBehavior("onchange") {
          protected void onUpdate(AjaxRequestTarget target) {
            onSelectionChanged(Integer.parseInt(dropDownQuestionTypes.getModelValue()));
            // target.addComponent(form);
            target.addComponent(numericLimitsPanel);
            target.addComponent(multipleSelectionLimitsPanel);
            target.addComponent(noneButtonLabel);
            target.addComponent(noneButtonCheckBox);
            target.addComponent(otherSpecifyLabel);
            target.addComponent(otherSpecifyCheckBox);
            target.addComponent(timeUnitsPanel);
            target.addComponent(listLimitsPanel);
          }
        });

    form.add(dropDownQuestionTypes);

    questionAnswerReasonModel = new Model(answerAlways);
    List<Object> answerChoices = new ArrayList<Object>();
    answerChoices.add(answerAlways);
    for (Expression expression : Expressions.forStudy(question.getStudyId())) {
      answerChoices.add(expression);
    }
    form.add(
        new DropDownChoice("questionAnswerReasonField", questionAnswerReasonModel, answerChoices));

    Label askingStyleListLabel = new Label("askingStyleListLabel", "Ask with list of alters:");
    askingStyleModel = new Model();
    askingStyleModel.setObject(Boolean.FALSE);
    AjaxCheckBox askingStyleListField =
        new AjaxCheckBox("askingStyleListField", askingStyleModel) {
          protected void onUpdate(AjaxRequestTarget target) {
            Boolean listLimitsVisible = false;

            if (questionResponseTypeModel.getObject().equals(Answer.AnswerType.MULTIPLE_SELECTION)
                || questionResponseTypeModel.getObject().equals(Answer.AnswerType.SELECTION))
              listLimitsVisible = (Boolean) askingStyleModel.getObject();

            listLimitsPanel.setVisible(listLimitsVisible);
            target.addComponent(form);
          }
        };
    askingStyleListLabel.setOutputMarkupId(true);
    askingStyleListLabel.setOutputMarkupPlaceholderTag(true);
    askingStyleListField.setOutputMarkupId(true);
    askingStyleListField.setOutputMarkupPlaceholderTag(true);
    form.add(askingStyleListLabel);
    form.add(askingStyleListField);
    if (question.getType().equals(Question.QuestionType.EGO)
        || question.getType().equals(Question.QuestionType.EGO_ID)) {
      askingStyleListLabel.setVisible(false);
      askingStyleListField.setVisible(false);
    }

    otherSpecifyLabel = new Label("otherSpecifyLabel", "Other/Specify Type Question?: ");
    otherSpecifyModel = new Model();
    otherSpecifyModel.setObject(Boolean.FALSE);
    otherSpecifyCheckBox = new CheckBox("otherSpecifyField", otherSpecifyModel);
    form.add(otherSpecifyLabel);
    form.add(otherSpecifyCheckBox);
    otherSpecifyLabel.setOutputMarkupId(true);
    otherSpecifyCheckBox.setOutputMarkupId(true);
    otherSpecifyLabel.setOutputMarkupPlaceholderTag(true);
    otherSpecifyCheckBox.setOutputMarkupPlaceholderTag(true);
    noneButtonLabel = new Label("noneButtonLabel", "NONE Button?: ");
    noneButtonModel = new Model();
    noneButtonModel.setObject(Boolean.FALSE);
    noneButtonCheckBox = new CheckBox("noneButtonField", noneButtonModel);
    form.add(noneButtonLabel);
    form.add(noneButtonCheckBox);
    noneButtonLabel.setOutputMarkupId(true);
    noneButtonCheckBox.setOutputMarkupId(true);
    noneButtonLabel.setOutputMarkupPlaceholderTag(true);
    noneButtonCheckBox.setOutputMarkupPlaceholderTag(true);
    noneButtonLabel.setVisible(false);
    noneButtonCheckBox.setVisible(false);

    // questionUseIfField = new TextField("questionUseIfField", new Model(""));
    // form.add(questionUseIfField);

    form.add(
        new AjaxFallbackButton("submitQuestion", form) {
          @Override
          public void onSubmit(AjaxRequestTarget target, Form form) {
            insertFormFieldsIntoQuestion(question);
            if (question.getId() == null) {
              List<Question> questions =
                  Questions.getQuestionsForStudy(question.getStudyId(), question.getType());
              questions.add(question);
              for (Integer i = 0; i < questions.size(); i++) {
                questions.get(i).setOrdering(i);
                DB.save(questions.get(i));
              }
            } else {
              DB.save(question);
            }
            form.setVisible(false);
            target.addComponent(parentThatNeedsUpdating);
            target.addComponent(form);
          }
        });
    add(form);

    setFormFieldsFromQuestion(question);
  }