| |

VerySource

 Forgot password?
 Register
Search
View: 745|Reply: 6

Custom struts tags can accept a List list parameter of the bean

[Copy link]

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-17 22:00:02
| Show all posts |Read mode
I wrote a custom struts tag,
/ *
 * Created on 2017-1-4
 *
 * TODO To change the template for this generated file, go to
 * Window-Preferences-Java-Code Style-Code Template
 * /
package com.yourcompany.struts.operation;
import javax.servlet. *;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext. *;
import java.util. *;

/ **
 * @author xm
 *
 * TODO To change the template of this generated type annotation, go to
 * Window-Preferences-Java-Code Style-Code Template
 * /
public class RadioListTag extends TagSupport {
    List list = null;
    public int doStartTag () {
    //list=(List)pageContext.getAttribute("admin ");
    Ranch
         JspWriter out = pageContext.getOut ();
         int counter = 1;
         if (list.size ()> 0)
         try {
         out.print ("<table border = 0 widht = 100% height = 100%> <tr>");
         for (Iterator it = list.iterator (); it.hasNext ();) {
         Ranch
         Ranch
         String value = (String) it.next ();
         out.print ("<td align = 'left'> <input type = 'radio' name = 'admin' value = '" + value + "'>" + value + "</ radio> </ td>");
         if (it.hasNext ()) {
         value = (String) it.next ();
         if (value == "彭 Liping1")
         out.print ("<td align = 'left'> <input type = 'radio' name = 'admin' checked = 'checked' value = '" + value + "'>" + value + "</ radio> </ td > </ tr> ");
         else
         out.print ("<td align = 'left'> <input type = 'radio' name = 'admin' value = '" + value + "'>" + value + "</ radio> </ td> </ tr> ");
         }
         else {
         out.print ("<td> </ td> </ tr>");
         }
         Ranch
             }
            out.print ("</ table>");
         } catch (Exception e) {
         e.printStackTrace ();
         }
    return EVAL_BODY_INCLUDE;
    }
}
Let the tag name be <jeffy: Radio> </ jeffy: Radio> I want to have a java bean on the page and have a List property. How do I pass this property to <jeffy: Radio> </ jeffy: Radio>
Reply

Use magic Report

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-20 23:15:01
| Show all posts
One of the solutions:
  
           allowable
               JspWriter out=pageContext.getOut(); add a code before
               List list=(List)HttpServletRequest.getAttribute("list");
           In this way, there is no need to pass parameters or anything!
    End this question here
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-22 23:30:01
| Show all posts
Halo, refer to other tag codes, vaguely remember that it seems to add a few attributes to the tag class, and it must conform to the javabean specification
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-23 03:45:01
| Show all posts
JspWriter out=pageContext.getOut(); add a code before
List list=(List)HttpServletRequest.getAttribute("list");
-------------------------------------------------- ------
The parameters passed in the request cannot be List, only strings or arrays, so the conclusion is not true!
Reply

Use magic Report

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-25 05:45:01
| Show all posts
JspWriter out=pageContext.getOut(); add a code before
List list=(List)HttpServletRequest.getAttribute("list");
-------------------------------------------------- ------
The parameters passed in the request cannot be List, only strings or arrays, so the conclusion is not true!

Then use array directly, or convert list to array to do it,
I didn’t experiment, I only thought of the principle.
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-7-25 09:15:01
| Show all posts
if(value=="彭丽萍1") // equals

Then the tags are actually JavaBeans,

<xxx:yyy zzz="abc" />

Is actually similar
tag = new xxx.Yyy();
tag.setZzz("abc");
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-7-25 09:30:01
| Show all posts
If you want List

Is <xxx:yyy list="<%= yourList %>" />
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list