简体   繁体   English

如何从支持bean获取JSF 2.0组件生成的HTML的DOM?

[英]How to get the DOM of a JSF 2.0 component's generated HTML from the backing bean?

I have a JSF-page containing only a PrimeFaces Calendar component, backed by a view scoped bean. 我有一个仅包含PrimeFaces Calendar组件的JSF页面,该组件由视图作用域的bean支持。

<p:calendar value="#{calendarBean.today}" mode="inline" showOtherMonths="true" pages="1" binding="#{calendarBean.model}" />

The generated HTML for this component contains a table that I'd like to adjust. 为此组件生成的HTML包含我要调整的表。 More specifically, I want to put icons dynamically into this calendar by adding some HTML-code under the td-tags of the targeted days. 更具体地说,我想通过在目标日期的td标签下添加一些HTML代码,将图标动态地放入此日历中。

From the CalendarBean I can fetch from some service a list of objects representing days "with icons". 我可以从CalendarBean中从某些服务中获取代表带有“图标”的日期的对象列表。 I need this list to decide which days to alter in the table. 我需要此列表来确定表中要更改的日期。 I tried to get the HTML DOM in my backing bean, but I don't understand how. 我试图在支持bean中获得HTML DOM,但我不知道如何。 The UIComponent tree (that I get via the binding property) only contains the JSF-components, not the generated HTML. UIComponent树(通过绑定属性获得)仅包含JSF组件,而不包含生成的HTML。 I start to doubt if this is even the way to approach the problem. 我开始怀疑这是否是解决问题的方法。

My google-skills seem to fall short here. 我的Google技术在这里似乎不足。 Can anybody help me? 有谁能够帮助我?

The concrete functional requirement is not entirely clear, so it's hard to propose the right way for this, but there are in general varous ways to alter the look'n'feel of the JSF/PrimeFaces-generated HTML. 具体的功能要求尚不完全清楚,因此很难为此提出正确的方法,但是通常有多种方法可以改变JSF / PrimeFaces生成的HTML的外观。

  1. Use custom CSS. 使用自定义CSS。 Icons could simply be set as CSS background images. 图标可以简单地设置为CSS背景图像。

  2. Use custom JS. 使用自定义JS。 JS has instant access to the entire HTML DOM tree. JS可以立即访问整个HTML DOM树。

  3. Use custom JSF renderer. 使用自定义JSF渲染器。 Extend the PrimeFaces CalendarRenderer class and override the encodeXxx() method(s) accordingly. 扩展PrimeFaces CalendarRenderer类,并相应地重写encodeXxx()方法。

The backing bean is supposed to be the controller between the view (the XHTML file) and the model (the javabean entity class holding the data which is to be presented to the enduser or to capture the submitted data from enduser). 支持bean应该是视图(XHTML文件)和模型(保存要提供给最终用户的数据或捕获来自最终用户的提交数据的javabean实体类)之间的控制器。 It isn't supposed to manipulate the HTML. 它不应该操纵HTML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jsf-将ID从支持bean分配给组件 - jsf - assign id to a component from a backing bean 如何将JSF组件绑定到支持bean属性 - How to bind JSF component to backing bean property JSF 1.2 自定义组件 - 来自 Backing Bean 的正文内容 - JSF 1.2 Custom Component - Body Content From Backing Bean JSF:如何在支持bean中的组件中添加ajax功能? - JSF: How to add ajax functionality to component in backing bean? 如何从自定义JSF组件中的支持bean加载jquery json数据? - How to load with jquery json data from a backing bean in a custom JSF component? 如何/从jsf将字符串列表传递到支持bean的最佳方法是什么 - How/What's the best way to pass a list of Strings from jsf to backing bean JSF页面元素无法从具有动作属性的bean触发方法。(JSF2.0 + primefaces) - JSF page element cannot trigger method from backing bean with action attribute.(JSF2.0 + primefaces) JSF-应用程序设计问题。 用户登录到备份Bean B后,如何在备份Bean A中获取数据 - JSF - App design issue. How to get data in backing bean A, after user logs in to backing bean B 如何从LIferay / IceFaces / JSF Portlet支持bean中获取URL请求参数 - How to get url request parameter from inside LIferay/IceFaces/JSF portlet backing bean 如何将get-parameter传递到jsf中的backing bean? - How to pass get-parameter to backing bean in jsf?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM