当然可以, tag不就是输出定制的页面html代码嘛, 4个property可以都在你自己的tld里面定义

解决方案 »

  1.   

    楼上的自己做过没有?
    你如何映射你的tag 的property 和ActionForm 的关系?
      

  2.   

    这是tag的一段代码,其中id1,id2 是其属性:
        public int doStartTag() {
    JspWriter out = pageContext.getOut();
    try{
        String outs = " <input type=\"text\" name=\""+p1+"\" size=\"16\" value=\"\" class=\"inp\">"
            + "<input type=\"text\" name=\""+p2+"\" size=\"16\" value=\"\" class=\"inp\">" ;
        out.print(outs); 
        out.print("==>");
    }catch(Exception e){
        e.printStackTrace();
    }
    return super.SKIP_BODY;
        }
    -------------------------------------------------Jsp 代码:
    <html:form action="TestTagsAction">
    <mytags:fourinputs p1="id1" p2="id2"/> <html:submit property="submit"/>
    </html:form>
    -------------------------------------------------Form Action:
        public ActionForward perform(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
            TestForm f =(TestForm)form;
            System.out.println("from f,id1="+f.getId1());
            f.setId1("ok~");
            return mapping.findForward("tags");
        }
        
    最后执行结果:
    from f,id1=123
    但返回到页面时,2个文本框都是空的
      

  3.   

    呵呵, 这样当然没有值拉, 你的TAG仅仅生成HTML,但是并没有从formBean中取值的过程。
    加入取的过程就可以了:
    ...
    try{
     String p1 = (String) TagUtils.getInstance().lookup(super.pageContext, name, p1, scope);
     String p2 = (String) TagUtils.getInstance().lookup(super.pageContext, name, p2, scope);
    ...
      

  4.   

    回复人: super_zzw(之支吾) ( ) 信誉:110  2005-09-02 18:19:00  得分: 0  
     
     
       呵呵, 这样当然没有值拉, 你的TAG仅仅生成HTML,但是并没有从formBean中取值的过程。
    加入取的过程就可以了:
    ...
    try{
     String p1 = (String) TagUtils.getInstance().lookup(super.pageContext, name, p1, scope);
     String p2 = (String) TagUtils.getInstance().lookup(super.pageContext, name, p2, scope);
    ...
    ------------------------------------------------------------
    小弟实在愚钝,兄弟能否详细解释一下这个tag的写法?
    下面这样写似乎不行:
    ackage com.tag;import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.JspWriter;
    import javax.servlet.jsp.tagext.BodyTagSupport;import org.apache.struts.taglib.tiles.util.TagUtils;
    public class FourInputs extends BodyTagSupport {
        //String p1;
        //String p2;
        String p1 = (String) TagUtils.getInstance().lookup(super.pageContext, name, p1, scope);
        String p2 = (String) TagUtils.getInstance().lookup(super.pageContext, name, p2, scope);
        public String getP1() {
            return p1 ;
        }
        public void setP1(String p1) {
            this.p1 = p1;
        }
        public String getP2() {
            return p2;
        }
        public void setP2(String p2) {
            this.p2 = p2;
        }
        public int doStartTag() throws JspException{
    JspWriter out = pageContext.getOut();
    try{
        String outs =
        "<input type=\"text\" name=\""+p1+"\"  size=\"16\" value=\"\" class=\"inp\">"
        +"<input type=\"text\" name=\""+p2+"\"  size=\"16\" value=\"\" class=\"inp\">";

        out.print(outs);
        out.print(" ==>");
    }catch(Exception e){
        e.printStackTrace();
    }
    return super.SKIP_BODY;
        }
    }
      
     
      

  5.   

    faint, 兄弟, 你看仔细我给你的代码啊, 在try下面取啊,而不是放在属性初始化取。
    ...
    try{
     String p1Value = (String) TagUtils.getInstance().lookup(super.pageContext, name, p1, scope);
     String p2Value = (String) TagUtils.getInstance().lookup(super.pageContext, name, p2, scope);
     String outs =
        "<input type=\"text\" name=\""+p1+"\"  size=\"16\" value=\"" + p1Value  + "\" class=\"inp\">"
        +"<input type=\"text\" name=\""+p2+"\"  size=\"16\" value=\"" + p2Value +  "\" class=\"inp\">";
    ...
      

  6.   

    TagUtils.getInstance().lookup(super.pageContext, name, p1, scope);这个类TagUtils 和方法getInstance() 是哪里来的?
    我这里怎么没有?
      

  7.   

    这是struts1.1以上版本支持的1.1以前的版本用这个方法:
    String p1Value = (String)RequestUtils.lookup(super.pageContext, name, p1, scope);