wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Per Newgro <per.new...@gmx.ch>
Subject Model for dropdowns in a listview
Date Sat, 20 Apr 2013 18:09:25 GMT
Hi,

i have to implement a questionnaire but i'm not sure how to capture the 
selected values in a model.

My questionnaire has some questions. The questions have some reply options.
The selected reply options will be assigned to an answer. The answers 
are the data i try to capture.

So i put the questions in a listview and a dropdown for the reply 
options on it's item.
But i have no clue how to implement the "business model" containing the 
answers.
Every answer is related to one selected reply option.

Can some1 please give me some pointers. Thanks for your support.
Per

Here some code

<code>
     public class QuestionListView extends ListView<QuestionBO> {

         public QuestionListView(String id, IModel<? extends List<? 
extends QuestionBO>> model) {
             super(id, model);
         }

         @Override
         protected void populateItem(ListItem<QuestionBO> item) {
             item.add(new Label("questionText", new 
PropertyModel<String>(item.getModel(), QuestionBO.TEXT)));
             // TODO the null has to be replaced by a smart model 
assigning the selected reply option to an answer in the business model
             item.add(new DropDownChoice<ReplyOptionBO>("replyOptions", 
null, new LoadableDetachableReplyOptionsModel(item.getModel()), new 
ReplyOptionBORenderer()));
         }
     }

     public class LoadableDetachableReplyOptionsModel extends 
LoadableDetachableModel<List<? extends ReplyOptionBO>> {

         private final IModel<QuestionBO> question;

         public LoadableDetachableReplyOptionsModel(IModel<QuestionBO> 
question) {
             this.question = question;
         }

         @Override
         protected List<? extends QuestionBO> load() {
             return service.loadReplyOptionsFor(question.getObject());
         }

         @Override
         public void detach() {
             question.detach();
             super.detach();
         }
     }
</code>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Mime
View raw message