2 Replies Latest reply on Sep 11, 2008 11:40 AM by Piotr Janik

    referencing different objects in datagrid

    Piotr Janik Newbie

      Hi,


      I have a problem with some objects and scope.


      Here is my code:



      <rich:dataGrid var="variant" value="#{productShow.product.variants}" columns="3" id="variantGrid">
          <rich:panel>
               <f:facet name="header"><h:outputText value="#{variant.name}"/></f:facet>
                    <h:inputText id="optionInput" value="#{productVariantOption.value}"/>
                    <h:commandButton value="Dodaj" action="#{variant.AddOption(newOption)}"/>
                    <rich:dataList  value="#{variant.options}" var="option">
                            <h:outputText value="#{option.value}"/>
                    </rich:dataList>
           </rich:panel>
      </rich:dataGrid>





      What's the problem?
      When running, every rich:panel <h:inputText id="optionInput" value="#{productVariantOption.value}"/> points to the same object(productVariantOption).
      I'd like to create new object of productVariantOption for every rich:panel(in dataGrid).


      This is head of productVariantOption:


      @Name("productVariantOption")
      @Entity
      public class ProductVariantOption {
      
          @Id
          @GeneratedValue
          int id;
          @Column(name = "value")
          public String value;
          @ManyToOne
          ProductVariant variant;



      Thanks,
      Peter

        • 1. Re: referencing different objects in datagrid
          Joshua Jackson Master

          Give us a look on how your Action class look like for displaying this xhtml page.

          • 2. Re: referencing different objects in datagrid
            Piotr Janik Newbie
            @Stateful
            @Name(value = "productShow")
            @Scope(value = ScopeType.SESSION)
            public class ProductShow implements ProductShowLocal {
            
            private Product product;
             public Product getProduct() {
                    return product;
             }
            ... some other properties
            


            and productVariant


            @Name(value = "productVariant")
            @Entity
            @Scope(value = ScopeType.EVENT)
            public class ProductVariant {
            
                @Id
                @GeneratedValue
                int id;
                @Column(name = "name")
                public String name;
                @OneToMany(cascade = CascadeType.ALL, mappedBy = "variant")
                public Collection<ProductVariantOption> options;
                @ManyToOne
                Product product;



            Mentioned page displays product information(Product object).
            Product has a collection of variants(ProductVariant) and every variant has a collection of values/options(ProductVariantOption).


            JSF renders page with datagrid for variants, so every variant has its own rich:panel.
            Every rich:panel has its own h:inputText with commandButton to add new option.
            Problem: value of above h:inputText is the same for every rich:panel.


            One of solutions would be linking OPTION_STRING on client side, as below:


            <h:inputText id="OPTION_STRING"/>
                <h:commandButton value="Dodaj" action="#{variant.AddOption(OPTION_STRING)}"/>
            




            Thanks and sorry for my english!


            Peter