I want to use WrapDynaBean in JSF

Asked 1 years ago, Updated 1 years ago, 72 views

I want to wrap Bean with the rapper Bean who inherited org.apache.commons.beanutils.WrapDynaBean and display it in h:dataTable.

The following code does not allow WrapperBean to see the value of TestBean, so javax.el.PropertyNotFoundException occurs.Is there a solution?

Rapper Bean

public classWrapperBean extensionsWrapDynaBean{
    // Table No.
    private int no;

    // setter, getter...
}

Bean wrapped

public class TestBean{
    private String value;

    // setter, getter...
}

Management Bean

public class TestController {

    private List <WrapperBean>wbList;

    @ PostConstract
    private void init() {
        // Wrap the TestBean that holds the contents of the table.
        wbList.add(newWrapperBean(newTestBean("hoge"));
        wbList.add(new WrapperBean(new TestBean("huga"));
        wbList.add(newWrapperBean(newTestBean("piyo"));
    }
}

test.xhtml

<h:dataTable value="#{testController.wbList}"var="row"
    <h:column>
        <h:outputText value="#{row.no}"/>
    </h:column>

    <h:column>
        <h:outputText value="#{row.value}"/>
    </h:column>
</h:dataTable>

java java-ee jsf

2022-09-30 13:57

1 Answers

Rewrite test.xhtml as shown below and you will see the output.

<h:dataTable value="#{testController.wbList}"var="row">
    <h:column>
        <h:outputText value="#{row.no}"/>
    </h:column>

    <h:column>
        <h:outputText value="#{row.get('value')}"/gt;
    </h:column>
</h:dataTable>


2022-09-30 13:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.