jsf - 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>
解决方案
推荐阅读
- javascript - 如何在数据表烧瓶中添加按钮
- javascript - 从下拉reactjs中过滤一个值
- javascript - Redirect to another website with sweetalert2 and GET information
- mysql - MySQL中选择闰年的查询条件
- android - 重新创建android活动而不眨眼
- bash - bash "<<<" 在一行上打印多行变量
- html - 将个人资料图片保留在 flexbox 的右侧
- python - pdfkit-警告:阻止访问文件
- c - memcpy 真的是一个带符号的函数吗?
- python - Python中的预测模型、目标函数和优化