0

I am not able to make something work that I think should. I posted a week ago but have not had any replies accessing a list within a list in p:datatable.

This is the same question but with specific code that demonstrates the problem. By making P1 editable and P2 display you can see that the property is changed without user input. I believe it is a system bug but hope I am wrong as I really need this to work. Here is the code:

    <h:body>
    <h:form>   
        <p:selectOneButton value="#{test.selectedIndex}">
            <f:selectItem itemLabel="1" itemValue="0"/>
            <f:selectItem itemLabel="2" itemValue="1"/>
            <p:ajax process="@form" update="@form" listener="#{test.doNothingAjax()}"/> 
        </p:selectOneButton>

        <p:panelGrid>
            <p:row>
                <p:column>Name</p:column>
                <p:column>Selected Index</p:column>
                <p:column>P1</p:column>
                <p:column>P2</p:column>
            </p:row>

            <c:forEach items="#{test.list}" var="item2">
                <c:set value="#{test.getMinor(item2)}" var="sub"/>
                <p:row>
                    <p:column>#{item2.name}</p:column>
                    <p:column>${test.selectedIndex}</p:column>
                    <p:column><p:inputText value="#{sub.p1}"/></p:column>
                    <p:column>#{sub.p2}</p:column>
                </p:row>
            </c:forEach>
        </p:panelGrid>
    </h:form>
</h:body>

and The JAVA @ManagedBean @SessionScoped public class Test {

private List<ItemHolder> list;
private int selectedIndex=0;

public Test() {
    list = new ArrayList();
    list.add(new ItemHolder());
}

public void doNothingAjax() {
}

public Item getMinor(ItemHolder holder) {
    return holder.getItems().get(selectedIndex);
}
//Getters & Setters

public class ItemHolder {

    private String name;
    List<Item> items;

    public ItemHolder() {
        name = "Test";
        items = new ArrayList();
        items.add(new Item("index 0",0,0));
        items.add(new Item("index 1",1,1));            
    }
    //getters and setters

public class Item {
    private String label;
    private int p1; //property 1
    private int p2; //property 2

    public Item(String label, int p1, int p2) {
        this.label = label;
        this.p1 = p1;
        this.p2 = p2;
    }

    //Getters and Setters

Any help would be greatly appreciated. If it is a system bug any suggestions for a workaround would also be helpful. I'm running out of ideas.

Thanks, John

Community
  • 1
  • 1
GolfAddict
  • 183
  • 3
  • 15
  • Just edit the original question instead. – BalusC May 05 '14 at 07:36
  • possible duplicate of [accessing a list within a list in p:datatable](http://stackoverflow.com/questions/23316607/accessing-a-list-within-a-list-in-pdatatable) – BalusC May 05 '14 at 07:37
  • Fair enough. I wasn't getting any traction and I thought something complete and straight-forward might be better than just making the other excessively long. As per your comment, the other post is updated. – GolfAddict May 05 '14 at 10:41

0 Answers0