Jsf 如何以编程方式添加带有primefaces的对话框
我想通过PrimeFacesDataList组件显示一些数据。为了实现这一点,我有一个类似于Jsf 如何以编程方式添加带有primefaces的对话框,jsf,xhtml,primefaces,Jsf,Xhtml,Primefaces,我想通过PrimeFacesDataList组件显示一些数据。为了实现这一点,我有一个类似于arrayList的arrayList person类看起来像这样 class Person{ private String name; private String age; private ArrayList<String> hobbies; } 班级人员{ 私有字符串名称; 私弦时代; 私人爱好; } 要显示数据,我使用以下代码: <p:dataList
arrayList
的arrayList
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>
姓名:#{person.getName()},年龄:#{person.getAge()},
我现在要做的是创建一个链接,单击该链接可打开一个对话框:
<p:dialog header="Hobbies" widgetVar="dlg1" modal="true"height="100">
//iterate through hobbies list to print it
</p:dialog>
//反复浏览爱好列表以打印它
到目前为止,这是有效的,因为我已经在xhtml文件中硬编码了上面提到的对话框
这种方法当然不适用于动态数量的人,因为我无法硬编码对话框和链接。我的问题是,如何以编程方式创建此对话框并将正确的widgetVar变量分配给链接的onClick方法
任何帮助都会得到高度重视,
为尼古拉斯干杯你可以试试这个:
<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;
}
}
姓名:#{person.getName()},年龄:#{person.getAge()},
//反复浏览gameBean.person的嗜好以在此处显示
@ManagedBean
@视域
公共类GameBean{
私人;
公共无效onPersonSelect(个人){
这个人=人;
}
}
非常感谢。我认为这是正确的方法。不幸的是,我在尝试时收到了以下错误消息:Dez 3020118:01:24 PM org.primefaces.util.ComponentUtils findClientIds信息:无法在视图中找到标识符为“hobbiesDlg”的组件。hmmm。。。假设您有
,您可以尝试将update=“hobbiesDlg”
更改为update=“myForm:hobbiesDlg”
或update=“:myForm:hobbiesDlg”
。您是对的。现在更新工作正常,但不幸的是还有另一个问题。actionlistener似乎从未被解雇过。我曾尝试将动作侦听器更改为此stlye(actionListener=“#{}”),但它仍然不起作用。编辑:在表单中的datalast中启动动作时似乎出现了一些问题,因为我尝试将链接放在表单外,它起作用了…关于#{}
,我忘了键入:)。让我考虑一下第二个问题NP,谢谢你的帮助。事实上,我认为元素的“子级别”太多了,因为我的结构看起来像是表单->字段集->数据列表->链接…当将链接直接放在它正在工作的表单下时。。。