Hi Nathan,
A few comments below. Hope that helps.
> [...]
> <s:form beanclass="${actionBean.class.name}" name="frmExam">
> <p>(Q1). In which country were you born?</p>
> <p><s:radio name="answer[1]" value="1"/>Australia</p>
> <p><s:radio name="answer[1]" value="2"/>Other</p>
> <p> </p>
>
> <p>(Q2). Do you speak any of these languages?</p>
> <p><s:checkbox name="answer[2]" value="1"/>English</p>
> <p><s:checkbox name="answer[2]" value="2"/>French</p>
> <p> </p>
> [...]
Not a big deal, but note that you can use just
beanclass="${actionBean.class}" in <s:form>.
> And an action that looks like this:
>
> public class SomeAction {
> public String[][] answer = null;
>
> @DefaultHandler
> public Resolution submit() {
> if (answer == null)
> logger.debug("No answers provided by customer");
> else
> logger.debug(String.format("answer[][] first dimension is %d items
> long", answer.length));
> }
> }
I don't think this affects your code, but I would really
advise against using an event handler method named "submit".
I can't remember why exactly at the moment, but I remember that
it's a Really Bad Idea to have an HTML submit button named
submit.
> When I answer the questions and submit, my debugging output says
> "answer[][] first dimension is 0 items long". So answer gets set to a
> non-null, but of zero length. My reading of the section of the
> (excellent) stripes book on indexed properties suggests that I might
> be able to do this, but doesn't give an example that maps to exactly
> what I'm doing.
Thank you for your kind comment about the book--I'm glad you are
enjoying it. Sorry that I didn't have an example that matches your
use case..
> My experience when dealing with one dimensional arrays (changing
> answer[][] to answer1[], answer2[]) is that you get an array of
> answers propagated for you. eg. If you speak both English and French,
> you get answer2[] = {"1", "2"}; if you live in Australia you get
> answer1[] = {"1"}
>
> So, I would have thought that with the example I list the code for, if
> you live in Australia and speak English and French you should get
> answer[][] = {{}, {"1"}, {"1", "2"}} (my arrays are one indexed, so
> the zero index should be null or an empty array). Is this not the
> case?
I would have thought so too. I'll admit I am surprised. I'm not sure
why it doesn't work, but I can tell you that if you change your
property to
public List<List<String>> answer;
you will get what you expect, i.e.
answer = [null, [1], [1, 2]]
I'm hoping you don't mind working with List<List<String>> instead of
String[][]..
If it's an issue, I'll look further into why it doesn't work with
the two-dimensional array.
Cheers,
Freddy
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users