PrimeFaces.current().dialog().openDynamic(…) doesn’t work using ‘

huangapple go评论58阅读模式
英文:

PrimeFaces.current().dialog().openDynamic(...) doesn't work using '<p:poll ...'

问题

在名为TestView的bean中,我想要打开一个动态对话框:

    public void dynamicMenue(String menue) {
        System.out.println("dynamicMenue: " + menue);
        PrimeFaces.current().dialog().openDynamic("menue");
    };

使用:

    <p:commandButton value="onSubmit" action="#{testView.dynamicMenue('submit')}" />

这样可以正常工作,但是使用:

    <p:poll interval="10" listener="#{testView.dynamicMenue('autoUpdate')}" />

则无法工作。

我演示了这种行为,并将一个最小化的项目放在https://github.com/mafulafunk/primefaces-test

英文:

Given this code in the named bean TestView I'd like to open a dynamic dialog :

    public void dynamicMenue(String menue) {
        System.out.println(&quot;dynamicMenue: &quot; + menue);
        PrimeFaces.current().dialog().openDynamic(&quot;menue&quot;);
    };

Using

    &lt;p:commandButton value=&quot;onSubmit&quot; action=&quot;#{testView.dynamicMenue(&#39;submit&#39;)}&quot; /&gt;

this works, but using

    &lt;p:poll interval=&quot;10&quot; listener=&quot;#{testView.dynamicMenue(&#39;autoUpdate&#39;)}&quot; /&gt;

it doesn't.

What am I missing?

I've put a minimal project on <https://github.com/mafulafunk/primefaces-test>
to illustrate this behaviour.

答案1

得分: 1

I understand your request. Here's the translated code portion:

我知道原因。那是因为对话框处理是在 PrimeFaces 的 `OutcomeRenderer` 中完成的,`p:poll` 在构建其 AJAX 请求时不会扩展或使用它。只有按钮和链接才被允许打开对话框框架。

不过,有一个简单的解决方法。

1. 将您的按钮设置为不可见,使用 `display:none` 并为其设置一个小部件变量...

```xml
<p:commandButton 
  value="onSubmit" 
  action="#{testView.dynamicMenue('submit')}" 
  style="display:none" 
  widgetVar="wgtOpenDialog" />
  1. 更改您的 p:poller 以点击按钮。
<p:poll 
  interval="10" 
  onstart="PF('wgtOpenDialog').click(); return false;" />
英文:

I know why. It is because the Dialog handling is done in the PrimeFaces OutcomeRenderer which p:poll does NOT extend or use when constructing its AJAX requests. Only Buttons and Links are allowed to open the Dialog Framework.

There is an easy workaround though.

  1. Set your button to invisible with display:none and give it a widget var...
&lt;p:commandButton 
value=&quot;onSubmit&quot; 
action=&quot;#{testView.dynamicMenue(&#39;submit&#39;)} 
style=&quot;display:none&quot; 
widgetVar=&quot;wgtOpenDialog&quot; /&gt;
  1. Change your p:poller to click the button.
 &lt;p:poll 
interval=&quot;10&quot; 
onstart=&quot;PF(&#39;wgtOpenDialog&#39;).click(); return false;&quot; /&gt;

huangapple
  • 本文由 发表于 2023年5月14日 20:24:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247470.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定