Use indexed properties inside the Iterate tag

xiaoxiao2021-03-06  46

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:

10

9

8

7

6

5

4

3

2

1

Note that the HTML code after parsing is as follows:

Structure, Focus and logic.

10

9

8

7

6

5

4

3 2

1

Depth and Breadth

10

9

8

7

6

5

4

3

2

1

IMPACT OF Activities

10

9

8

7

6

5

4

3

2

1

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.

转载请注明原文地址:https://www.9cbs.com/read-61298.html

New Post(0)