Hello dhay,
I think it useful addition with minimal changes of existing code -
good solution. But there is one problem for my mind - html:link with
index=x. All another tag proposals are simple and transparent.
Friday, July 06, 2001, 9:31:21 PM, you wrote:
dlc> Hi everyone.
dlc> I have been posting to the user list for some time now regarding creating
dlc> indexed names within an iterate tag. From feedback from that list, this seems
dlc> to be an important addition to the current tags.
dlc> While looking to write my own additional tags which would do this (eg
dlc> html:indexedText etc), I discovered that this functionality could easily be
dlc> added to the current tags, now that the getIndex() method is available, by
dlc> creating an extra parameter 'indexed' which when set to true would create the
dlc> indexed names. The necessary additions to current code were small and quite
dlc> clean, as follows:
dlc> - added 'indexed' as a parameter in BaseHandlerTag, with appropriate
dlc> setter/getter
dlc> - added if statement which checks for 'indexed=true', and if so, appends "[x]"
dlc> to the name, before appending property eg myProperty[x].value.
dlc> This was added to BaseFieldTag (to cover tags which extend this) and
dlc> CheckBoxTag, & SelectTag
dlc> as follows:
dlc> //if "indexed=true" parameter, create indexed name for this tag eg
dlc> name="myCollection[x].myproperty"
dlc> if ("true".equals(indexed))
dlc> {
dlc> // look for outer iterate tag
dlc> IterateTag iterateTag = (IterateTag) findAncestorWithClass(this,
dlc> IterateTag.class);
dlc> if (iterateTag == null)
dlc> {
dlc> // this tag should only be nested in iteratetag, if it's not, don't do
dlc> anything
dlc> return EVAL_PAGE;
dlc> }
dlc> results.append(getName());
dlc> results.append("[");
dlc> results.append(iterateTag.getIndex());
dlc> results.append("].");
dlc> }
dlc> - Slight variations were added to SubmitTag and ButtonTag to simply add index to
dlc> it's name ie mySubmit[x].
dlc> - linkTag was somewhat different due to its nature. I added if statement to add
dlc> "index=x" as a parameter to the link's querystring ie myAction.do?index=1 or
dlc> myAction.do?param1=37&index=1, as follows:
dlc> //if "indexed=true", add "index=x" parameter to query string
dlc> if ("true".equals(indexed))
dlc> {
dlc> // look for outer iterate tag
dlc> IterateTag iterateTag = (IterateTag) findAncestorWithClass(this,
dlc> IterateTag.class);
dlc> if (iterateTag == null)
dlc> {
dlc> // this tag should only be nested in iteratetag, if it's not,
dlc> don't do anything
dlc> System.out.println("couldn't find enclosing iterate tag");
dlc> return EVAL_PAGE;
dlc> }
dlc> //calculate index, and add as a parameter
dlc> if (params == null)
dlc> {
dlc> params = new HashMap(); //create new HashMap if no
dlc> other params
dlc> }
dlc> params.put("index", "" + iterateTag.getIndex());
dlc> }
dlc> - minimal changes to struts-html.tld to add 'indexed' as param.
dlc> All of this code has been available at Ted's site for a while, and I would like
dlc> to suggest it is added to the Struts source. Numerous people are already using
dlc> it, and I believe many more would if it was part of the build.
dlc> Would appreciate your feedback, and not sure what happens next (just joined this
dlc> list)!
dlc> Cheers,
dlc> Dave
dlc> PS code attached(See attached file: struts indexed files.ZIP)
--
Best regards,
Oleg mailto:[EMAIL PROTECTED]