struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mead Lai <laiqi...@gmail.com>
Subject How to create a costume struts2 tag? any demo?
Date Sat, 09 Oct 2010 09:15:22 GMT
Hello all,

I create a simple tag following this link
http://joshuajava.wordpress.com/2008/12/27/creating-custom-components-with-struts-2/

<http://joshuajava.wordpress.com/2008/12/27/creating-custom-components-with-struts-2/>but,
I am trying to add some extra functions into that tag.
Actually, I create a template/simple-theme named:"lab.ftl"
the content:
<a href="#">${parameters.name?html}</a>
But, finally failed, I add a method:"evaluateExtraParams", I have no clue at
all.
Brilliant Thanks



@StrutsTag(
    name="tab",
    tldTagClass="lab.struts2.components.Hello",
    description="Render a checkbox input field"
    )
public class Hello extends Component {
    protected String name;

    public Hello(ValueStack stack) {
        super(stack);
    }


    public String getName() {
 return name;
}


@StrutsTagAttribute(description="The actual HTML value attribute of the
checkbox.", defaultValue="true")
    public void setName(String name) {
        this.name = name;
    }

    public boolean start(Writer writer) {
        try {
            writer.write("Hello " + name);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return true;
    }

    protected void evaluateExtraParams() {
        if (name != null) {
            addParameter("name", findString(name));
        } else {
            addParameter("name", "MMMM");
        }
    }

    public boolean end(Writer writer) {
        return true;
    }

    @Override
    public boolean usesBody() {
        return false;
    }
}



Regards,
Mead

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message