简体   繁体   中英

JSF: Empty nested dataTable

I'm writing my own implementation of JMX console for JBoss 6.1 based on JSF.

There is a part of code of managed bean:

@ManagedBean
@SessionScoped
public class InspectionBean implements Serializable {
    private MBeanInfo data; 
    private List<OperationWrapper> operations;

    public void setInitData(MBeanInfo data) {
        this.data = data;   
        initOperations();
    }

    public List<MBeanOperation> getOperations() {
        return operations;
    }

    public void setOperations(List<MBeanOperation> list) {
        operations = list;
    }

    private void initOperations() {
        operations = new ArrayList<MBeanOperation>();

        for (MBeanOperationInfo opInfo : data.getOperations()) {
            OperationWrapper opWrapper = new OperationWrapper();

            opWrapper.setName(opInfo.getName());
            opWrapper.setDescription(opInfo.getDescription());
            opWrapper.setReturnType(opInfo.getReturnType());

            List<ParameterWrapper> paramList = 
                    new ArrayList<ParameterWrapper>(); 

            for (MBeanParameterInfo paramInfo : opInfo.getSignature()) {
                ParameterWrapper paramWrapper = 
                        new ParameterWrapper();

                paramWrapper.setName(paramInfo.getName());
                paramWrapper.setDescription(paramInfo.getDescription());
                paramWrapper.setType(paramInfo.getType());
                paramWrapper.setValue("");

                paramList.add(paramWrapper);
            }

            mBeanOp.setSignature(paramList);

            operations.add(mBeanOp);
        }
    }

    //some other code
}

The OperationWrapper class code:

public class OperationWrapper implements Serializable {
    private String name;
    private String returnType;
    private List<ParameterWrapper> signature; 
    private String description;

    //other getters and setters

    public List<ParameterWrapper> getSignature() {
        return signature;
    }

    public void setSignature(List<ParameterWrapper> signature) {
        this.signature = signature;
    }   
}

The ParameterWrapper class code:

public class ParameterWrapper implements Serializable {
    private String name;
    private String type;
    private String description;
    private String value;

    //simple getters and setters
}

And this is a code of a problem page:

<h:dataTable value="#{inspectionBean.operations}" var="operation"
        border="1" width="100%" cellpadding="5"
        style="border-style: solid; border-collapse: collapse;">
    <h:column>
        <f:facet name="header">Operation</f:facet>
        #{operation.name}
    </h:column>

    <h:column>
        <f:facet name="header">Return Value</f:facet>
        #{operation.returnType}
    </h:column>

    <h:column>
        <f:facet name="header">Description</f:facet>
        #{operation.description}
    </h:column>

    <h:column>
        <f:facet name="header">Parameters</f:facet>

        <h:form>
            <h:dataTable value="#{operation.signature}" var="param"
                    rendered="#{not empty operation.signature}"
                    border="1" width="100%"
                    style="border-style: solid; border-collapse: collapse;">
                <h:column>
                    #{param.name}
                </h:column>

                <h:column>
                    #{param.type}
                </h:column>

                <h:column>
                    #{param.description}
                </h:column>

                <h:column>
                    <h:inputText value="#{param.value}" size="20"/>
                </h:column>
            </h:dataTable>

            <a4j:commandButton value="Invoke" 
                    action="#{inspectionBean.invokeOperation(operation)}" 
                    render="@none"/>
        </h:form>
    </h:column>  
</h:dataTable>

When this part of the page is displayed, it looks like this: 示例页面 So there is no text in nested dataTables!

As you can see tables are in places where they should. And there are cells for text. And in the right quantity. But where is the text?

Debugging gives no result. Lists are filled with the correct data.

What's wrong? How can I fix this?

The culprit is in the var attribute of your nested table markup:

<h:dataTable value="#{operation.signature}" var="param" ...>
    <h:column>
        #{param.name}
    </h:column>
    ...

The #{param} is a reserved EL variable name which refers the request parameter map as obtained by ExternalContext#getRequestParameterMap() . Eg page.xhtml?id=123 will give print 123 when using #{param.id} . You can and should not override it.

Give it a different name. Eg var="signature" and #{signature.name} , etc.

See also:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM