For the previous blog, if multiple points are entered, how can this problem be solved:
1. The input page is as follows. Assume that the names of the three input points are the same.
- <% @ Page contenttype = "text/html; charset = GBK" %>
- <% @ Taglib prefix = "S" uri = "/Struts-tags" %>
- <S: Form Action = "converter" method = "Post">
- <S: textfield name = "point" label = "point1"/>
- <S: textfield name = "point" label = "point2"/>
- <S: textfield name = "point" label = "point3"/>
- <S: textfield name = "Age" label = "Age"/>
- <S: textfield name = "username" label = "username"/>
- <S: textfield name = "date" label = "date"/>
- <S: Submit label = "Submit"/>
- </S: Form>
2. The coverter class has been modified.
- Package edu. HUST. Common;
- Import java. util. arraylist;
- Import java. util. List;
- Import java. util. Map;
- Import org. Apache. struts2.util. strutstypeconverter;
- Import edu. HUST. Bean. Point;
- Public class converter extends strutstypeconverter {
- @ Suppresswarnings ("unchecked ")
- @ Override
- Public object convertfromstring (MAP context, string [] values, class toclass ){
- List <point> pointlist = new arraylist <point> ();
- For (string value: values ){
- Point point = new point ();
- String [] paramvalues = value. Split (",");
- Int x = integer. parseint (paramvalues [0]);
- Int y = integer. parseint (paramvalues [1]);
- Point. setx (X );
- Point. sety (y );
- Pointlist. Add (point );
- }
- Return pointlist;
- }
- @ Suppresswarnings ("unchecked ")
- @ Override
- Public String converttostring (MAP context, object O ){
- List <point> pointlist = (list <point>) O;
- Stringbuilder sb = new stringbuilder ();
- For (point: pointlist ){
- SB = sb. append (point. getx (). append (","). append (point. Gety (). append ("<br> ");
- }
- Return sb. tostring ();
- }
- }
3. Only one change is allowed to the converteraction class.
- /*
- * It turns out to be a point. Here we change it to list <point>. I haven't tried to use arrays, but using list is a common practice.
- */
- Public class converteraction extends actionsupport {
- Private list <point> point;
- Public list <point> getpoint (){
- Return Point;
- }
- Public void setpoint (list <point> point ){
- This. Point = point;
- }
- }
The other parts are not changed, so that multiple forms with the same name can be submitted simultaneously.