Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Capturing the element in collection that was chosen  RSS feed

 
Mark Brothers
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application where the original programmer takes data, looks up a small collection of addition data (like classes for a student), iterates through that data to display to the browser. One piece of data is a link to another screen. How can I capture and pass along the index associated with the exact item in the collection that the user clicked? I can get the entire collection to show in the next screen, but I want only the data in the collection associated with that particular element in the collection.

Code for iterating through collection to show the data in rows:
<logic:iterate indexId="indx" id="part" name="r.juvParticipationData">
<TR bgcolor="<osca:evenodd name='indx' even='#ffffff' odd='#cccccc'/>">
<TD><bean:write name="part" property="contactPhone"/> 
</TD>
<TD><bean:write name="part" property="contactFax"/> 
</TD>
<TD> <a href="<osca:sendEmail juvenile="r.juvData"
part="part"/>"><bean:write name="part"
property="contactEmail"/></a>
</TD>
</TR>
</logic:iterate>

This iteration may return one or many rows for the original data item (in this case a juvenile) � when the user clicks on the email link to start the process of sending an email, how do I capture which item in the collection they have chosen, so I can then get that same element from the collection for data on the next screen? My question is basically � How do I capture the index of the item they have selected, and pass it to the next page, so I can look up the corresponding element in the collection again for data display?

Thanks so much for any responses.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

You could pass the row index, or data uniquely identifying the juvenile, in the parameters of the URL. That may mean you have to wrap osca:sendEmail.

I expect there are better ways of doing it, but that is one that sprang to mind.

Jules
 
Mark Brothers
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you pass the row index of the particvular row the user has chosen? Can you merely set an attribute on the session to store the row index? Sounds simple, but I still do not understand how you know which row they have clisked on - after all the iteration through the collection doesn't addd a row and wait to see if the user has responded before placing the next row. Any code samples of this sort of task anywhere to look at and learn from? Thanks again so much for the help.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't have any code samples or pointers but you want your HTML (via View Source) to look something like this:

So the row id/unique id is actually encoded in the URL when the user clicks on the link.
Can you see how to achieve that by modifying the URL in the HREF? Does that help?

Jules
[ August 05, 2004: Message edited by: Julian Kennedy ]
 
Mark Brothers
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, if I understand you correctly, I can add a piece to the HREF that adds the index of the collection iteration to the HREF. The HREF actually isnot a URL to send the user to, but a forward to the appropriate page.

Original line of code:
<TD> <a href="<osca:sendEmail juvenile="r.juvData"
part="part"/>"><bean:write name="part"
property="contactEmail"/></a>
</TD>

New version:
<TD> <a href="<osca:sendEmail juvenile="r.juvData"
part="part"/>"><bean:write name="part"
property="contactEmail"/>&rowid=<%indexId%></a>
</TD>

Then, in my next jsp page, I could iterate through the collection of participation data to the element in that particular location. Am I in the ballpark on this? Thanks so much Jules.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks about right. Of course you won't need to iterate through the collection if you have the index - you can just go straight to it.

Let me know if it works.

Jules
 
Mark Brothers
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is where I want to place the program name on my second jsp page: (This now works fine to get the program name � but it returns the program names in the collection, so I can have multiple program names if there were more than one row of data on the previous page)

<TD align="right"><I>Program</I></TD>
<TD>
<logic:iterate indexId="indx" id="part" name="r.juvParticipationData">
<osca:emailProgram name="part" juvenile="r.juvData" user="s.userData"/> 
</logic:iterate>
</TD>

How do I check each iteration in the above code to see if it equals the row index of the selected data row that was on the previous jsp page (shown below)? Here is the code that places the link on the jsp (IN BOLD) that a user might choose (each row would have a different index number for the collection of iterations). Where in this code would I put some code to write the row index to the session (or somewhere so it can be available to the next page to test against the collection again to get the program name associated with the same record row as on this page)?

<logic:iterate indexId="indx" id="part" name="r.juvParticipationData">
<TR bgcolor="<osca:evenodd name='indx' even='#ffffff' odd='#cccccc'/>">
<TD rowspan="2" valign="top"><bean:write name="part" property="agencyName"/> </TD>
<TD rowspan="2" valign="top"><osca:casenetLink name="part" juvenile="r.juvData" user="s.userData"/> </TD>
<TD><bean:write name="part" property="contactFName"/> <bean:write name="part" property="contactLName"/> </TD>
<TD> </TD>
<TD><bean:write name="part" property="agencyLocation"/> </TD>
</TR>
<TR bgcolor="<osca:evenodd name='indx' even='#ffffff' odd='#cccccc'/>">
<TD><bean:write name="part" property="contactPhone"/> </TD>
<TD><bean:write name="part" property="contactFax"/> </TD>
<TD> <a href="<osca:sendEmail juvenile="r.juvData" part="part"/>"><bean:write name="part" property="contactEmail"/></a></TD>
</TR>
</logic:iterate>


Thanks so much for your help!
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, I'm afraid you've lost me a bit.
What JSP dialect do things like <osca:evenodd>, <bean:write> and <logic:iterate> come from?

Jules
 
Mark Brothers
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The osca: tag is a custom tag to alternately color the rows of data on the page, the logic: tag is a struts tag to iterate through the rows of data, and the bean:write tag gets data from a data bean to read onto the jsp page. Sorry about that - we are using the Struts framework for our application.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the Web App Frameworks forum. The principle is as I've described, but those boys (and girls, lest we forget!) should be able to help you with the mechanics.

Jules
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!