After purchasing a EWDT book and reading a chapter about dynamic forms I
was able to solve my problem. The problem was how to remember selected
radio buttons for all radio groups on the page. Of course there are any
number of radio groups each with any number of radio buttons.
HTML consists of two (nested) For components. Outer loop iterates over
radio groups (questions), inner over buttons (possible answers to those
questions). The data model for questions (Question class) must have a
field for storing currently selected answer. You must manually provide
selectedAnswer getter, setter and initialize method instead of just
using abstract declarations or .page property.
protected void initialize() {
selectedAnswer = null;
}
public void setSelectedAnswer(Answer answer) {
selectedAnswer = answer;
}
public Answer getSelectedAnswer() {
int index = getQuestionIndex();
Answer a =
getManager().selectQuestion(index).getSelectedAnswer();
System.out.println("getSelectedAnswer(): " + (a != null ?
a.getAnswer():""));
return a;
}
The heart of the solution is this method
public void updateAnswer(IRequestCycle cycle) {
if (cycle.isRewinding()) {
int questionIndex = getQuestionIndex();
System.out.printf("updateAnswer qi:%s sAnswer:%s\n",
questionIndex, selectedAnswer);
getManager().updateAnswer(questionIndex, selectedAnswer);
}
}
which gets called after every iteration of the outer loop by this piece
of code in the html template
<span jwcid="updateAnswer"/>
and in .page
<component id="updateAnswer" type="InvokeListener">
<binding name="listener" value="listener:updateAnswer"/>
</component>
Since this is my first Tapestry app, I don't know of any simpler
solution. I must say that Kent's book is the best tutorial on any
subject I have ever read. Keep up the good work - and if I may suggest a
theme for another chapter Kent - please include Cayenne. :-P
Regards,
Borut
Borut Bolčina wrote:
Hi,
I have several RadioGroup components, each with three radio buttons.
Also two TextFields and one submit button. When a validation error on
an input field is triggered by some incorrect user input, an error
message is displayed as explained in Kent Tong's book EWDT. When this
happens also all but last of the radio group buttons which were
selected by user gets deselected. How to prevent that? I tried with
volatile For binding - there are two nested For components, one for
RadioGroups and one for Radio buttons, but with no success.
-Borut
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]