Use indexed properties inside the Iterate tag
Using the indexed attribute in the scope of the iterate tag
There is often a need for a requirement, including multiple submission items, and the number of items is not fixed, while each item needs to interact with the user. For example: a questionnaire on training feedback, for different training, the project of investigations is different. And what we have to do is regardless of how the investigation project changes, our JSP, FORMBEAN and ACTION do not have to make any modifications.
1. First of all, FORMBEAN
Private feedbackItemBean [] feedbackItems;
Public void setPageItems (int index, feedbackItembean feedbackItem)
{
PageItems [INDEX] = feedbackItem
}
Public FeedbackItemBean getPageItems (int index)
{
Return PageItems [Index];
}
/ **
* @Return Returns the PageItems.
* /
Public feedbackItemBean [] getPageItems ()
{
Return PageItems;
}
/ **
* @Param PageItems The pageItems to set.
* /
Public void setPageItems (FeedbackItembean [] PageItems
{
THIS.PAGEITEMS = PageItems;
}
* Please note the above GET / SET method.
WherefeedbackItemBean is a user-defined bean, for example, only some attributes:
Private string feedbackItemtitle = NULL;
Private string feedbackItemContent = null;
Private long feedbackItemValue = 0;
2. In JSP
The code segment is as follows:
9 html: Radio>
8 html: Radio>
7 html: Radio>
6 html: Radio> td>
5 html: Radio>
4 html: Radio>
3 html: Radio>
2 html: Radio>
1 html: Radio> td>
TR>
logic: Equal>
TR>
logic: Equal>
logic: Iterate>
logic: NOTEMPTY>
Note that the HTML code after parsing is as follows:
10
9
8
7
6 td>
4
3 2
1 td>
TR>
10
9
8
7
6 td>
4
3
2
1 td>
TR>
10
9
8
7
6 td>
4
3
2
1 td>
TR>
Everyone has noticed the value of Name:
Taking PageItems [0] .FeedbackItemValue as an example, first Struts is working in the REFLECT mechanism, so he calls the method should be getPageItems (0) .GetFeedbackItemValue (), and take this method. Read here, you should understand.
So, the rest of the work is very simple, just need to be in Action ...
3. Action
ApplicationTrainingForm ApplicationTrainingForm = (ApplicationTrainingForm) Form;
FeedbackItemBean [] PageItems = ApplicationTrainingForm.getPageItems (); You can get the value of the user input.
All rights in this article belongs to the author of this article, and it is not allowed to reprint without permission.