Primefaces widgetVar干扰ui:repeat或ui:datatable

问题描述 投票:3回答:2

我有一个<ui:repeat>,它会在List<String>上进行迭代,并使用<p:commandButton>中的当前字符串的值创建一个<p:lightBox>。但是,当我将widgetVar添加到<p:lightBox>的属性中时,<p:commandButton>的值始终是上次迭代的字符串。

有人可以解释会发生什么,并且(我需要widgetVar)可能会指出解决方案?

这是我的html:

<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:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head />
<h:body>
    <ui:repeat var="thing" value="#{bugBean.things}">
        <p:lightBox widgetVar="whatever">
            <h:outputLink>
                <h:outputText value="#{thing}" />
            </h:outputLink>
            <f:facet name="inline">
                <h:form>
                        <p:commandButton action="#{bugBean.writeThing(thing)}"
                            value="#{thing}" />
                </h:form>
            </f:facet>
        </p:lightBox>
    </ui:repeat>
</h:body>
</html>

这是支持bean:

package huhu.main.managebean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@SessionScoped
public class BugBean implements Serializable {

   private static final long serialVersionUID = 1L;
   List<String> things = new ArrayList<String>();

   public BugBean(){
      things.add("First");
      things.add("Second");
      things.add("Third");
   }

   public void writeThing(String thing){
      System.out.println(thing);
   }

   public List<String> getThings() {
      return things;
   }

   public void setThings(List<String> things) {
      this.things = things;
   }

}
jsf-2 primefaces
2个回答
8
投票

widgetVar基本上会生成一个窗口范围的JavaScript变量。您现在在JavaScript上下文中实际上正在做的是:

window['whatever'] = new Widget(lightboxElement1);
window['whatever'] = new Widget(lightboxElement2);
window['whatever'] = new Widget(lightboxElement3);
// ...

0
投票

最近我升级到primefaces 4.0-> 5.1时遇到了类似的问题

© www.soinside.com 2019 - 2024. All rights reserved.