jsf - 在 JSF 自定义组件上添加 onclick 事件
问题描述
我只是想构建一个自定义组件:
- 首先,
onclick
我的标签上的基本 javascript 事件p
呈现为alert("...")
- 其次,服务器端处理点击事件
.
// 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>
我一直在阅读有关事件/行为的内容,但我无法弄清楚它是如何工作的。
解决方案
推荐阅读
- angular - 在 Angular 2+ 中过滤子内容
- php - 登录表单 - 无法登录 codeigniter
- reactjs - 启动 server.js 文件时,登陆页面未显示在 Reactjs /Express 中
- flutter - 如何在导航到路线之前进行验证?
- asp.net-web-api - 如何使用 Azure AD 对企业用户以及单页应用程序中的外部用户进行身份验证?
- c# - 从对象列表创建一个 csv 文件 C#
- sql-server - 无法从 Ubuntu SQL Server Express 连接到 Amazon AWS SQL Server Express 数据库
- list - 查询地图列表的元素,并更新 dart 中的一个元素
- sql-server - 用相同的字符串替换替换多个字符串
- wordpress - 如何在 Wordpress 中显示类似 Google 财经的数据