【问题标题】:java primefaces auto update imagejava primefaces 自动更新图片
【发布时间】:2012-06-20 08:56:07
【问题描述】:

我有一个显示来自雅虎财经的图表的应用程序,我希望在图表每次在线更改时更新。下面是我的代码。

<table style="width: 100%">
                <tr>
                    <td> 
                        <b>Nifty 50</b><br/>
                        <b><h:outputText value="#{equityBean.niftyChange}"/></b><br/>
                        <b><h:outputText value="#{equityBean.niftyChangePer}"/></b><br/>
                        <b><h:outputText value="#{equityBean.niftyLTP}"/></b></td>
                <td><img src="http://ichart.yahoo.com/t?s=^NSEI"/></td>
                <td>&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td> 
                    <b>BSE Sensex</b><br/>
                    <b><h:outputText value="#{equityBean.sensexChange}"/></b><br/>
                    <b><h:outputText value="#{equityBean.sensexChangePer}"/></b><br/>
                    <b><h:outputText value="#{equityBean.sensexLTP}"/></b></td>
                <td><img src="http://ichart.yahoo.com/t?s=^BSESN"/></td>
                <td>&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td> 
                     <b>Gold</b><br/>
                    <b><h:outputText value="#{equityBean.sensexChange}"/></b><br/>
                    <b><h:outputText value="#{equityBean.sensexChangePer}"/></b><br/>
                    <b><h:outputText value="#{equityBean.sensexLTP}"/></b></td>
                <td><img src="http://ichart.yahoo.com/t?s=GCQ12.CMX"/></td>
                </tr>


                </table>

我如何使用 p:ajax 做到这一点?或者除了调度程序之外还有其他方式吗? 已编辑

<p:poll interval="3"   
               listener="#{equityBean.sensexChange}" update=":frm" />  

frm 是表单的id,我已经在表单中显示了日期但是它没有更新

 <h:form id="frm">

        <h:outputText value="#{equityBean.tdate}"/>

再次编辑:

public String getSensexChange() {
     setIndex("^BSESN");
    return sensexChange;
}

【问题讨论】:

    标签: java ajax jakarta-ee primefaces


    【解决方案1】:

    您需要的是 p:pool 组件,它以指定的时间间隔进行 ajax 调用。示例:

    <p:poll interval="3"   
                listener="#{counterBean.increment}" update="txt_count" />
    

    你可以在here看到它。

    【讨论】:

    • 请参考我编辑的问题,我使用民意调查但它不起作用
    • 是表单内的 p:poll 吗? sensexChange 方法有什么作用?请也更新代码 sn-ps
    • 是的,民意调查在表格内,我再次编辑了我的问题以包含 sensexChange 的代码 sn-p。
    • 为什么要从侦听器方法返回字符串?它们应该是无效的。你期望会发生什么?民意调查与其他组件的形式相同?为什么要更新日期?您没有在侦听器方法中更新它..
    猜你喜欢
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-02
    • 2018-08-15
    • 2023-01-26
    • 2014-02-24
    相关资源
    最近更新 更多