首页 > 解决方案 > 在 JSF 自定义组件上添加 onclick 事件

问题描述

我只是想构建一个自定义组件:

.

// HelloComponent.java
@FacesComponent(createTag = true, tagName = "helloComponent", namespace = "http://example.com/tags")
public class HelloComponent extends UIComponentBase {

    @Override
    public String getFamily() {
        return "Greeting";
    }

    @Override
    public void encodeBegin(FacesContext context) throws IOException {
        String message = (String) getAttributes().get("message");

        ResponseWriter writer = context.getResponseWriter();
        writer.startElement("p", this);
        writer.write(message);
        writer.endElement("p");
    }
}


// index.xhtml (simplified)
<html ...>
    <h:body>
        <t:helloComponent message="Hello World !" />
    </h:body>
</html>

我一直在阅读有关事件/行为的内容,但我无法弄清楚它是如何工作的。

标签: jsfjsf-2.2

解决方案


推荐阅读