How to programmatically add dialogs with performances

I want to display some data through the datalist component. For this, I have an arrayList, for example ArrayList<Person>.

A person's class looks something like this:

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

To display the data, I use 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>

Now I want to do 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>

So far this works, because I hardcoded the dialog, as mentioned above, in the xhtml file.

This method, of course, does not work for a dynamic number of people, since I cannot hard-code dialogs and links. My question is: how can I create these dialogs programmatically and assign the correct widgetVar variable to the onClick method for links?

Any help is extremely limited, greetings of Nikolaus

0
source
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;
   }
}
+1

All Articles