简体   繁体   English

丰富:效果使用问题

[英]rich:effect usage problem

I would like to use a rich:effect with a JSF element in my app but am having a little trouble with the AJAX side of things. 我想在我的应用程序中使用一个带有JSF元素的rich:effect ,但是在AJAX方面遇到了一些麻烦。

As per the below, I have an h:outputText element which has a JSF referenced value ( #{MyBacking.sysMsg} ) which changes during the user experience with the app. 根据下面的内容,我有一个h:outputText元素,它有一个JSF引用值( #{MyBacking.sysMsg} ),它在应用程序的用户体验期间发生了变化。 As the rich:effect element uses javascript events, specifying the code below doesn't work. 由于rich:effect元素使用javascript事件,因此指定下面的代码不起作用。

I've tried using a4j:support to ajaxify the h:outputText element but this is seemingly ignored too. 我已经尝试使用a4j:支持ajaxify h:outputText元素,但这似乎也被忽略了。 No buttons will be clicked by the user - the sysMsg variable is updated elsewhere and I want to highlight a change to the audience. 用户不会点击任何按钮 - sysMsg变量在其他地方更新,我想突出显示对受众的更改。

The code is as follows: 代码如下:

<h:outputText value="#{MyBacking.sysMsg}" id="sysMsg" style="#{MyBacking.colour}" />
<rich:effect event="onchange" type="Highlight" params="duration:0.8" />
<rich:effect event="onchange" for="sysMsg" type="Appear" params="delay:3.0,duration:0.5" />

I think there's bound to be a simple answer for this, but I cannot seem to find the answer in my head or on the net. 我认为这肯定会有一个简单的答案,但我似乎无法在脑海中或网上找到答案。 Can anyone help me? 谁能帮我?

To update the text based on serverside changes you will have to use <a4j:poll> or <a4j:push> . 要根据服务器端更改更新文本,您必须使用<a4j:poll><a4j:push>

Eg: 例如:

<rich:effect name="highlight" for="sysMsg" type="Highlight" params="duration:0.8" />

<h:form>
<a4j:poll id="poll" interval="1000" reRender="sysMsg" oncomplete="highlight();"/>
</h:form>

This of course will highlight every second and not only when the value has changed. 这当然会突出每一秒,而不仅仅是当价值发生变化时。 To highlight only on change you are probably better of to use a custom javascript/jquery function, remember the value und call highlight when it changed. 要仅突出显示更改,您可能更好地使用自定义javascript / jquery函数,请记住更改时的值和调用高亮显示。

Here is a possible solution: 这是一个可能的解决方案:

<h:form id="form">
<a4j:region renderRegionOnly="true">
    <h:outputText value="#{MyBacking.sysMsg}" id="sysMsg" style="#{MyBacking.colour}" />
    <a4j:poll id="poll" interval="1000" reRender="sysMsg" oncomplete="checkChange();" limitToList="true"/>
</a4j:region>

<rich:effect name="highlight" for="sysMsg" type="Highlight" params="duration:0.8" />

</h:form>

<script>
var value = $('form:sysMsg').textContent ;
function checkChange(){
    if($('form:sysMsg').textContent  != value){
        highlight();
    }
}
</script>

Here are samples: Exadel Demo and the documentation: rich:effect a4j:poll 以下是示例: Exadel Demo和文档: rich:effect a4j:poll

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM