Example usage for org.apache.wicket.markup.repeater RepeatingView getDefaultModelObject

List of usage examples for org.apache.wicket.markup.repeater RepeatingView getDefaultModelObject

Introduction

In this page you can find the example usage for org.apache.wicket.markup.repeater RepeatingView getDefaultModelObject.

Prototype

public final Object getDefaultModelObject() 

Source Link

Document

Gets the backing model object.

Usage

From source file:com.userweave.module.methoden.questionnaire.page.survey.dimensions.DimensionsQuestionSurveyPanel.java

License:Open Source License

public DimensionsQuestionSurveyPanel(String id, DimensionsQuestion question, QuestionnaireSurveyContext context,
        Locale locale) {/*from   w  w  w. j a v  a 2 s .  c  om*/
    super(id, question, context, locale);

    final int numberOfRatingSteps = question.getNumberOfRatingSteps();

    showNoAnswerOption = question.getShowNoAnswerOption();
    if (showNoAnswerOption == null) {
        showNoAnswerOption = false;
    }

    add(new WebMarkupContainer("notStatedHeaderLeft").setVisible(showNoAnswerOption));

    IModel model = new PropertyModel(getDefaultModel(), "antipodePairs") {
        private boolean sorted = false;

        @Override
        public Object getObject() {
            List objects = (List) super.getObject();
            if (!sorted) {
                sortPossibleAnswers(objects);
                sorted = true;
            }
            return objects;
        }
    };

    RepeatingView view = new RepeatingView("antipodePairs", model);

    add(view);

    for (final AntipodePair antipodePair : (List<AntipodePair>) view.getDefaultModelObject()) {
        WebMarkupContainer container = new WebMarkupContainer(view.newChildId());

        view.add(container);

        container.add(
                new DimensionsSingleRatingPanel("singleRatingPanel", numberOfRatingSteps, showNoAnswerOption,
                        question.getRandomizeAntipodePosition(), new Model(antipodePair), new Model<Integer>() {
                            @Override
                            public Integer getObject() {
                                return getRating(antipodePair);
                            }

                            @Override
                            public void setObject(Integer rating) {
                                setRating(antipodePair, rating);
                            }
                        }, DimensionsQuestionSurveyPanel.this.getLocale()));
    }

    //      add(
    //         new PropertyListView("antipodePairs", model) {
    //            
    //             @Override
    //            protected void populateItem(ListItem item) {
    //                final AntipodePair antipodePair = (AntipodePair) item.getModelObject();
    //                               
    //                item.add(
    //                   new DimensionsSingleRatingPanel(
    //                     "singleRatingPanel", 
    //                     numberOfRatingSteps, 
    //                     showNoAnswerOption, 
    //                     item.getModel(),
    //                     new Model() {
    //                         @Override
    //                         public Object getObject() {
    //                            return getRating(antipodePair);
    //                         }
    //
    //                         @Override
    //                        public void setObject(Object rating) {                           
    //                           setRating(antipodePair, (Integer) rating);
    //                        }
    //                     },
    //                     DimensionsQuestionSurveyPanel.this.getLocale()
    //                  )
    //               );         
    //             }                   
    //         }
    //      );            

    add(new WebMarkupContainer("notStatedFooterLeft").setVisible(showNoAnswerOption));
}

From source file:com.userweave.module.methoden.questionnaire.page.survey.multiplerating.MultRatingSurveyPanel.java

License:Open Source License

public MultRatingSurveyPanel(String id, MultipleRatingQuestion question, QuestionnaireSurveyContext console,
        Locale locale) {//from w  ww  .  j  ava  2s . c  om
    super(id, question, console, locale);

    add(new Label("antipode1",
            new LocalizedPropertyModel(getDefaultModel(), "antipodePair.antipode1", getLocale())));
    add(new Label("antipode2",
            new LocalizedPropertyModel(getDefaultModel(), "antipodePair.antipode2", getLocale())));

    numberOfRatingSteps = question.getNumberOfRatingSteps();

    showNoAnswerOption = question.getShowNoAnswerOption();
    if (showNoAnswerOption == null) {
        showNoAnswerOption = false;
    }

    add(new WebMarkupContainer("notStatedHeaderLeft").setVisible(showNoAnswerOption));

    IModel model = new PropertyModel(getDefaultModel(), "ratingTerms") {
        private boolean sorted = false;

        @Override
        public Object getObject() {
            List objects = (List) super.getObject();
            if (!sorted) {
                sortPossibleAnswers(objects);
                sorted = true;
            }
            return objects;
        }
    };

    RepeatingView ratingTermsView = new RepeatingView("ratingTerms", model);

    add(ratingTermsView);

    for (final RatingTerm ratingTerm : (List<RatingTerm>) ratingTermsView.getDefaultModelObject()) {
        WebMarkupContainer container = new WebMarkupContainer(ratingTermsView.newChildId());

        ratingTermsView.add(container);

        container.add(
                new MultiRatingSingleRatingPanel("singleRatingPanel", numberOfRatingSteps, showNoAnswerOption,
                        LocalizationUtils.getValue(ratingTerm.getText(), getLocale()), new Model<Integer>() {
                            @Override
                            public Integer getObject() {
                                return getRating(ratingTerm);
                            }

                            @Override
                            public void setObject(Integer rating) {
                                setRating(ratingTerm, rating);
                            }
                        }));
    }

    //      add(
    //         new ListView("ratingTerms", model) {
    //            
    //             private boolean notApplicable;
    //             
    //             @Override
    //            protected void populateItem(ListItem item) {
    //                final RatingTerm ratingTerm = (RatingTerm) item.getModelObject();
    //                
    //                item.add(
    //                   new MultiRatingSingleRatingPanel(
    //                         "singleRatingPanel", 
    //                         numberOfRatingSteps, 
    //                         showNoAnswerOption, 
    //                         LocalizationUtils.getValue(ratingTerm.getText(), getLocale()),
    //                     new Model() {
    //                         @Override
    //                         public Object getObject() {
    //                            return getRating(ratingTerm);
    //                         }
    //                         
    //                        @Override
    //                        public void setObject(Object rating) {                           
    //                           setRating(ratingTerm, (Integer) rating);
    //                        }
    //                     } 
    //                  ) 
    //               );                     
    //             }
    //         }
    //      );

    add(new WebMarkupContainer("notStatedFooterLeft").setVisible(showNoAnswerOption));
}