如何以编程方式添加带有撇号的对话框 [英] How to programmatically add dialogs with primefaces
问题描述
我想通过primefaces数据列表组件显示一些数据.为了实现这一点,我有一个ArrayList<Person>
之类的arrayList.
I want to display some data through primefaces datalist component. To achieve this I have an arrayList like ArrayList<Person>
.
人类看起来像这样
class Person{
private String name;
private String age;
private ArrayList<String> hobbies;
}
使用以下代码显示我正在使用的数据:
To display the data I'm using the following code:
<p:dataList value="{gameBean.persons}" var="person" itemType="disc">
Name: #{person.getName()}, Age: #{person.getAge()},
<h:link value="Hobbies" onclick="dlg1.show();" />
</p:dataList>
我现在要做的是创建一个链接,单击该链接可打开一个对话框:
What I want do do now, is to create a link that opens a dialog when clicked:
<p:dialog header="Hobbies" widgetVar="dlg1" modal="true"height="100">
//iterate through hobbies list to print it
</p:dialog>
到目前为止,这是可行的,因为如上所述,我已经在xhtml文件中对对话框进行了硬编码.
So far this is working because I've hard coded the dialog as mentioned above in the xhtml file.
由于无法对对话框和链接进行硬编码,因此这种方法对于大量的人当然不起作用.我的问题是,如何才能以编程方式创建此对话框并将正确的widgetVar变量分配给链接的onClick方法?
This method is of course not working for a dynamic amount of persons as I can not hard code the dialogs and the links. My question is, how can I create this dialogs programmatically and assign the right widgetVar variable to the onClick method of the Links?
我们非常感谢您的帮助, 尼古拉斯欢呼
Any help is highly apprechiated, cheers Nikolaus
推荐答案
您可以尝试以下操作:
<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;
}
}
这篇关于如何以编程方式添加带有撇号的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!