首页 > 解决方案 > jsf在编辑时在输入中显示实体的值

问题描述

我有一个产品列表,当我按下“编辑产品”时,它会重定向到 editProduct.xhtml,我想在输入中查看所选实体的值(以及我从 getRequest 获得的值)。我有一个 inputHidden 和 metadata 和 f:param 但我可能用错了所以它不起作用。

产品列表.xhtml

<f:view>

    <h:body>

        <ui:composition template="template.xhtml">
        <ui:define name="content">

            <h:form id="productForm">
                <h:dataTable id="productTable"
                             class="table table-hover"
                             var="product"
                             value = "#{listProductController.getProductListForUser()}">

                            <h:column>
                                <f:facet name = "header">Id: </f:facet>
                                     #{product.id}
                            </h:column>


                    <h:column>
                        <f:facet name = "header">Title: </f:facet>
                        <h:outputLabel value="#{product.title}"
                                          />
                    </h:column>



                            <h:column>
                                <f:facet name = "header">Category:</f:facet>
                            #{product.category.name}
                            </h:column>

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

                            <h:column>
                                <f:facet name = "header">Pictures:</f:facet>
                                <ui:repeat var="picture" value="#{listProductController.getFirstPicByProductId(product.id)}">
                                    <h:graphicImage value = "#{picture.link}" height="60px" width="60px" alt="Image not found"/>
                                </ui:repeat >
                            </h:column>

                            <h:column>
                                <f:facet name = "header">Parameters:</f:facet>
                                <ui:repeat var="productParametr" value="#{listProductController.getParamByProductId(product.id)}">
                                <h:outputText value="#{productParametr.parameter.value} : #{productParametr.value}"
                                             />
                                </ui:repeat>
                            </h:column>

                            <h:column>
                                <f:facet name = "header">Price:</f:facet>
                                <h:outputText value="#{product.price}" />
                            </h:column>


                                <h:column>
                                    <f:facet name = "header">Edit:</f:facet>
                               <h:commandButton value = "Edit Product"
                                                action = "#{productController.edit()}"
                               >
                                    <f:param name="id" value="#{productController.getAddRequest().id}"/>
                               </h:commandButton>
                                </h:column>

                </h:dataTable>
            <br/>

            </h:form>
</ui:define>
        </ui:composition>
    </h:body>
</f:view>

编辑产品.xhtml

<f:view>

    <f:metadata>
        <f:viewParam name="id" value="#{productController.getAddRequest().id}"/>
    </f:metadata>

    <h:body>

        <ui:composition template="template.xhtml">
            <ui:define name="content">

                <h:form>

                    <h:inputHidden value="#{productController.getAddRequest().id}" />

                    <div class="wrap-login100" align="center">
                        <h:outputLabel for="id" value = "Id: "/>
                        #{productController.getAddRequest().id}
                    </div>

                    <div class="wrap-login100" align="center">
                        <h:outputLabel for="title" value = "Title: "/>
                            <h:inputText id="title" value="#{productController.getAddRequest().title}"/>
                        </div>



                    <div class="wrap-login100" align="center">
                        <h:outputLabel for="description" value = "Description: "/>
                        <h:inputText id="description" value="#{productController.getAddRequest().description}"/>
                    </div>


                    <div class="wrap-login100" align="center">
                        <h:outputLabel for="price" value = "Price: "/>
                            <h:inputText id="price" value="#{productController.getAddRequest().price}" />
                    </div>


                    <div class="wrap-login100" align="center">
                            <h:commandButton value = "Edit Product"
                                             action = "#{productController.editProduct()}"
                            >
                            </h:commandButton>
                    </div>

                    <br/>

                </h:form>

            </ui:define>
        </ui:composition>
    </h:body>
</f:view>

标签: jsf

解决方案


推荐阅读