Hello, I'm really a beginner in wicket and I'm making an application that
will create dynamic surveys based on xml. I'm creating survey which is a
form containing different kinds of panel, and my problem is with submitting
users answers, can anyone help?
I would like to keep all answers in class
public class UserAnswer implements Serializable
{
private static final long serialVersionUID = 1L;
private long surveyID;
private List<SimpleAnswer> choosenAnswers = new
ArrayList<SimpleAnswer>();
...
}
Survey panel class generates the survey form.
public class SurveyPanel extends Panel
{
private Survey survey;
private UserAnswer userAnswer;
public SurveyPanel(String id, Survey s)
{
super(id);
this.survey = s;
userAnswer = new UserAnswer(s.getID());
Form form = new Form("surveyForm", new Model(userAnswer))
{
@Override
protected void onSubmit()
{
UserAnswer uA = (UserAnswer)getModelObject();
info(uA.toString());
info("the form was submitted!");
}
@Override
public boolean isTransparentResolver()
{
return true;
}
};
add(form);
form.add(new Label("surveyName", new PropertyModel(this,
"survey.name")));
questionsList = new ListView("survey", new PropertyModel(this,
"survey.questions"))
{
private static final long serialVersionUID = 1L;
protected void populateItem(ListItem item)
{
QuestionPanel questionPanel = null;
question = (Question)item.getModelObject();
QuestionType questionType =
question.getQuestionType();
int index = item.getIndex();
switch(questionType)
{
case CHECKBOX:
{
ArrayList<SimpleAnswer> ans = new
ArrayList<SimpleAnswer>
(question.getAnswers().size());
questionPanel = new
CheckBoxQuestion("question",
question, ans);
userAnswer.addList(ans);
}break;
case RADIO:
{
SimpleAnswer a = new
SimpleAnswer(question.getQuestionID());
userAnswer.add(a);
questionPanel = new
RadioGroupQuestion("question", question, a);
}break;
}
}
item.add(questionPanel);
}
};
form.add(questionsList);
}
And here is the problem (I hope). Question panel is abstract Panel.
public class CheckBoxQuestion extends QuestionPanel
{
private static final long serialVersionUID = 1L;
CheckBoxMultipleChoice checkbox;
ArrayList<SimpleAnswer> answers;
public CheckBoxQuestion(String id, final Question q,
ArrayList<SimpleAnswer>ans)
{
super(id,q);
setModel(new Model(ans));
add(new Label("question.text", q.getQText()));
List<SimpleAnswer> choices = q.getAnswers();
add(checkbox = new CheckBoxMultipleChoice("answers",
new Model((Serializable)
this.getModelObject()),choices, new
ChoiceRenderer("text","answerID"))
);
}
}
public class RadioGroupQuestion extends QuestionPanel
{
RadioGroup group;
public RadioGroupQuestion(String id, final Question q, SimpleAnswer u)
{
super(id, q);
add(new Label("question.text", q.getQText()));
group = new RadioGroup("group", new CompoundPropertyModel(u));
add(group);
ListView answers = new
ListView("answers",q.getCovertedAnswers())
{
@Override
protected void populateItem(ListItem item) {
final SimpleAnswer simpleAnswer =
(SimpleAnswer)item.getModelObject();
item.add(new Radio("answerID",new
PropertyModel(item.getModel(),"answerID")));
item.add(new Label("text", new
PropertyModel(item.getModel(),"answerText")));
}
};
group.add(answers);
}
}
Everything is displayed without any error submit also works but, well I
don't receive well filled UserAnswer object. Anyone has any idea what I do
wrong? Thanks in advance.
--
View this message in context:
http://www.nabble.com/Creating-dynamic-forms-and-sumbit-problem-tp20875344p20875344.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]