2011-12-30 68 views
0

我想通过primefaces datalist组件显示一些数据。为了达到这个我有一个arrayList像ArrayList<Person>如何以编程方式添加对话框使用primefaces

Person类看起来是这样的

class Person{ 
    private String name; 
    private String age; 
    private ArrayList<String> hobbies; 
} 

要显示的数据,我用下面的代码:

<p:dataList value="{gameBean.persons}" var="person" itemType="disc"> 
    Name: #{person.getName()}, Age: #{person.getAge()}, 
    <h:link value="Hobbies" onclick="dlg1.show();" /> 
</p:dataList> 

我想现在做事情,就是创建一个链接,点击时打开一个对话框:

<p:dialog header="Hobbies" widgetVar="dlg1" modal="true"height="100"> 
    //iterate through hobbies list to print it 
</p:dialog> 

到目前为止,这是工作,因为我硬编码的对话框为如上所述在xhtml文件中。

这种方法当然不适用于动态数量的人,因为我不能硬编码对话框和链接。我的问题是,如何以编程方式创建此对话框并将正确的widgetVar变量分配给链接的onClick方法?

任何帮助高度apprechiated, 欢呼尼古拉斯

回答

1

你可以试试这个:

<h:form id="form"> 
    <p:dataList value="{gameBean.persons}" var="person" itemType="disc"> 
     Name: #{person.getName()}, Age: #{person.getAge()}, 
     <p:column> 
      <p:commandLink value="Hobbies" actionListener="#{gameBean.onPersonSelect(person)}" 
         oncomplete="dlg1.show();" update=":form:hobbiesDlg" /> 
     </p:column> 
    </p:dataList> 

    <p:dialog header="Hobbies" id="hobbiesDlg" widgetVar="dlg1" modal="true"height="100"> 
     //iterate through hobbies of gameBean.person to show here 
    </p:dialog> 
</h:form> 

@ManagedBean 
@ViewScoped 
public class GameBean { 
    private Person person; 

    public void onPersonSelect(Person person) { 
     this.person = person; 
    } 
} 
+0

非常感谢你。我认为这是正确的方法。不幸的是,当我尝试它时,我收到以下错误消息:Dez 30,2011 8:01:24 PM org.primefaces.util.ComponentUtils findClientIds 信息:找不到标识为“hobbiesDlg”的组件。 – 2011-12-30 19:02:11

+0

hmmm ...假设你有'',你可以尝试改变'update =“hobbiesDlg”''update =“myForm:hobbiesDlg”或'update =“:myForm: hobbiesDlg“'。 – 2011-12-30 19:21:32

+0

你是对的。现在更新正在运行,但不幸的是还有另一个问题。看来,行动侦查者从未被解雇。我试图改变这个stlye(actionListener =“#{})的动作监听器,但它仍然不起作用编辑:似乎有一些问题,当在数据存储器中分别执行动作时,因为我试图把链接外部表单和它的工作...想法? – 2011-12-30 20:08:40

相关问题