2010-11-30 10 views
2

Ont après la première .jsf:Définir les propriétés à jsf bean géré

<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> 

suivant shoppingCart.jsf Avez-:

<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> 

Faces-config:

<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> 
... 

Le problème:
nom du haricot géré défini comme product
itération va dans ce sens (shoppingCart.jsf):
h:dataTable value="#{prod}">
donc cela signifie que cette itération n'est pas connecté à la fève nommé product de toute façon

Comment définir les propriétés prod.price,prod.weight,prod.count à propriétés de haricots immobiliers gérés:

product.price,product.weight,product.size 

Répondre

5

Il y a deux problèmes:

  1. Vous Aren » t la définition d'un prod spécifique dans le bean scope scoped session. Vous devriez faire ceci.

    <h:commandButton value="Buy" action="shoppingCart"> 
        <f:setPropertyActionListener target="#{showProducts.product}" value="#{prod}" /> 
    </h:commandButton> 
    

    Par ailleurs, la déclaration managed-property définit seulement un haricot nouveau/vide comme propriété pendant la cération de haricot mère. Ce n'est pas nécessairement le mêmeprod par exemple que vous avez dans le ui:repeat. Vous pouvez simplement supprimer le haricot #{product} de votre faces-config.xml. Le h:dataTable n'a aucun sens ici. Vous avez besoin de h:panelGrid ici.

    <h:panelGrid columns="3"> 
        <h:outputText value="#{showProducts.product.name}" /> 
        <h:outputText value="#{showProducts.product.price}" /> 
        <h:outputText value="#{showProducts.product.count}" /> 
    </h:panelGrid> 
    
+0

BalusC, merci beaucoup. Cela fonctionne. Je ne sais même pas à propos de sergionni

Questions connexes