属性以JSF托管bean
问题描述:
有下列第一.jsf:属性以JSF托管bean
<ui:repeat var="prod" value="#{showProducts.decoys}">
<h:form>
{prod.price}
{prod.weight}
{prod.size} >
<h:commandButton value="Buy" action="shoppingCart"/>
</h:form>
</ui:repeat>
有以下shoppingCart.jsf:
<h:form>
<h:dataTable value="#{prod}">
<h:column>
#{prod.name}<br/>
</h:column>
<h:column>
#{prod.price}<br/>
</h:column>
<h:column>
<h:inputText value="#{prod.count}" size="3"/>
</h:column>
</h:dataTable>
<h:inputText value="#{order.phone}"/><br/>
<h:inputText value="#{order.mail}"><br/>
<h:inputText value="#{order.city}"/><br/>
<h:commandButton value="Order" action="#{showProducts.persistOrder}">
</h:form>
面 - 配置:
<managed-bean>
<managed-bean-name>showProducts</managed-bean-name>
<managed-bean-class>main.ShowProducts</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
...
<managed-property>
<property-name>product</property-name>
<value>#{product}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>product</managed-bean-name>
<managed-bean-class>main.Product</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
...
的问题:
托管bean名称定义为product
迭代变这样(shoppingCart.jsf):h:dataTable value="#{prod}">
所以它意味着这个迭代不与命名product
豆无论如何
如何设置属性prod.price,prod.weight,prod.count
实际管理bean属性连接:
product.price,product.weight,product.size
答
有两个问题:
-
你AREN” t在会话作用域bean中设置特定的
prod
。你应该做这个。<h:commandButton value="Buy" action="shoppingCart"> <f:setPropertyActionListener target="#{showProducts.product}" value="#{prod}" /> </h:commandButton>
顺便说一句,在
managed-property
声明只设置父bean的细齿过程中新/空豆财产。这不一定是相同prod
实例,因为您在ui:repeat
中有。您可以从faces-config.xml
中删除#{product}
豆。 -
h:dataTable
在这里没有任何意义。您需要h:panelGrid
这里。<h:panelGrid columns="3"> <h:outputText value="#{showProducts.product.name}" /> <h:outputText value="#{showProducts.product.price}" /> <h:outputText value="#{showProducts.product.count}" /> </h:panelGrid>
BalusC,非常感谢。它工作。我甚至不知道
sergionni
2010-11-30 13:48:07