jsf - 您可以为 PrimeFace 组件设置 Ajax 响应操作,该组件的 html 是在 Bean 中生成的吗?
问题描述
亲爱的友好陌生人,
在 JSF 2.2 上使用 PrimeFaces 7.0 我在我的 Bean 中生成 html-Code 并将其注入到我的 xhtml 中<h:outputText value="#{myBean.myHtml}" escape="false"/>
。这自然不适用于<p:.../>
组件,因为它们本身会生成/渲染实际的 html。我从我的数据库中更改数据以获取最终 html 的方式对于 html 函数来说太复杂了,所以我仍然想在我的 Java-Beans 中完成它,而不是使用大量ui:repeat
和超复杂的自定义样式 - 即使我知道这不是如何使用 jsf/PrimeFaces。p:commandLink
现在检查它给出的实际呈现的 html 例如
<a id="myContainerID:myComponentID" href="#" class="ui-commandlink ui-widget" onclick="PrimeFaces.ab({s:"myContainerID:myComponentID",f:"myContainerID"});return false;">myComponentValue</a>
,我可以很容易地生成,但是在接收到组件的 Ajax 请求时调用的响应动作s:"myContainerID:myComponentID"
(<p:...>
有没有办法手动设置响应动作,如果是这样,如何/在哪里?
编辑:因为(引用PrimeFaces.ab 函数)
//ajax shortcut ab: function(cfg, ext) { return PrimeFaces.ajax.AjaxRequest(cfg, ext); }
PrimeFaces.ajax.AjaxRequest 可以是异步的或同步的。AjaxRequest 使用 AjaxUtils,它处理所有发送、处理、响应和更新。
PrimeFaces.ajax.AjaxRequest = function(cfg, ext) { cfg.ext = ext; if(cfg.async) { return PrimeFaces.ajax.AjaxUtils.send(cfg); } else { return PrimeFaces.ajax.Queue.offer(cfg); } }
我想答案(如果有的话)应该在某处AjaxUtils
,但还没有找到。
感谢 helluvalot 的任何建议/帮助。
编辑 2:我最终确实设法将它全部转录到带有嵌套 ui:repeats 和许多自定义样式的 xhtml,但我仍然很好奇是否有办法使用 in-Bean 生成的 html 来做到这一点。
示例代码
我的豆:
@ManagedBean(name = "myBean")
@SessionScoped
public class myBean {
private String html1;
private String html2;
@PostConstruct
public void init() {
html1 = "<p:commandLink id=\"myComponentID\" value=\"myComponentValue\" "
+ "action=\"#{someBean.doSomething()}\"";
html2 = "<a id=\"myContainerID:myComponentID\" "
+ "href=\"#\" class=\"ui-commandlink ui-widget\" "
+ "onclick=\"PrimeFaces.ab({s:\"myContainerID:myComponentID\","
+ "f:\"myContainerID\"});"
+ "return false;\">1. myComponentValue</a>";
}
public String getHtml1() {
return html1;
}
public void setHtml1(String html1) {
this.html1 = html1;
}
public String getHtml2() {
return html2;
}
public void setHtml2(String html2) {
this.html2 = html2;
}
}
我的索引.xhtml:
<h:html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
>
<h:head>
</h:head>
<h:body>
<h:form id="myContainerID">
<h:outputText value="#{myBean.html1}" escape="false" />
<h:outputText value="#{myBean.html2}" escape="false" />
</h:form>
</h:body>
</h:html>
解决方案
推荐阅读
- javascript - MongoDB/猫鼬 | 扩展模式功能
- google-cloud-platform - 使用来自 GCP 市场的 terrafrom 创建实例
- php - 如何在 Visual Composer 标题中的 Wordpress 简码中获取页面 ID
- ruby-on-rails - Rails SQL select,CASE 语句似乎没有按预期工作
- c# - 为什么数据库不在服务中调用 onCreate?
- c# - 我想使用相同的视图使用 MVC razor Engine 在不同的导航栏中显示不同的结果。我设计了一个使用 html 标签的页面
- javascript - 将 ValidatorJS isISIN 转换为 Typescript 并出现错误?
- python - 有没有办法让 Python 脚本考虑机器的默认代理设置?
- android - 将统一应用程序上传到 Play 商店时出错
- html - 寻找有关如何将我的下拉导航栏居中以进行大学项目的建议