My application allows users to set up questions and
valid responses for those questions, which are
subequently saved ot the db. Along with the question
is the ability to state what type of HTML element the
responses should show as. For example, if the
question is designated as CHECKBOX, then the responses
should all show as checkboxes.
When I display the questions that are in the database,
I loop through the questions and based on what type
they are, build the proper component. However, the
issue comes in because in the HTML, I have every type
of HTML form element that the question could be. So,
let's say quesiton one is a CHECKBOX, when it goes
through the HTML, it also finds wicket ids of
multiSelect, select, etc., but these do not exist in
the current ListItem, only checkbox does, so Wicket
throws an exception. Basically, I need an "if this id
exists, do this, otherwise, skip it." Am I going to
have to custom build something to do this, or is there
maybe something I'm missing or some other way to
accomplish this.
Thanks for any help you can give,
Andrew
Here is some code that may help out with my
explanation. In the page code I do this:
add(new ListView("categoryQuestions",
categoryQuestions) {
@Override
protected void populateItem(ListItem
item) {
CategoryQuestion cq =
(CategoryQuestion) item
.getModelObject();
ResponseType type =
cq.getResponseType();
List<CategoryQuestionResponse>
cqResponses = new ArrayList<CategoryQuestionResponse>(
cq.getValidResponses());
if
(type.equals(ResponseType.CHECKBOX)) {
item.add(new
CheckBoxMultipleChoice("checkbox", cqResponses,
new
ChoiceRenderer("response.text", "id")));
} else if
(type.equals(ResponseType.DROPDOWN)) {
item.add(new
DropDownChoice("dropdown", cqResponses,
new
ChoiceRenderer("response.text", "id")));
} else if
(type.equals(ResponseType.MULTI_SELECT)) {
item.add(new
ListMultipleChoice("multiSelect", cqResponses,
new
ChoiceRenderer("response.text", "id")).setMaxRows(5));
} else if
(type.equals(ResponseType.RATING)) {
//
}
}
Then in the HTML I do:
<form wicket:id="questionForm">
<span wicket:id="categoryQuestions">
<select wicket:id="dropdown">
<option>Option 1</option>
</select>
<select wicket:id="multiSelect">
<option>Option 1</option>
</select>
<input wicket:id="checkbox" type="checkbox"/>
</span>
</form>
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user