Page 1 of 1

Extend StructuredContentImpl

Posted: Tue Mar 26, 2013 4:45 am
by pbechu
Hi !

I'm working on the extension of the StructuredContentImpl (Broadleaf class). You can find the code below.

Code: Select all

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "MY_SC")
@EntityListeners(value = { AdminAuditableListener.class })
@AdminPresentationClass(friendlyName="MyStructuredContent", ceilingDisplayEntity="org.broadleafcommerce.cms.structure.domain.StructuredContent", populateToOneFields = PopulateToOneFieldsEnum.TRUE)
public class MyStructuredContent extends StructuredContentImpl {

   private static final long serialVersionUID = 1L;
   
   @ManyToMany(targetEntity = Product.class)
    @JoinTable(name = "MY_SC_PRODUCT_XREF", joinColumns = @JoinColumn(name = "SC_ID", referencedColumnName = "SC_ID"), inverseJoinColumns = @JoinColumn(name = "PRODUCT_ID", referencedColumnName = "PRODUCT_ID"))
    @BatchSize(size = 50)
    protected List<Product> allProduct = new ArrayList<Product>();

   /**
    * @return the allProduct
    */
   public List<Product> getAllProduct() {
      return allProduct;
   }

   /**
    * @param allProduct the allProduct to set
    */
   public void setAllProduct(List<Product> allProduct) {
      this.allProduct = allProduct;
   }
}


I want to attached some products to a structured content in order to use them in the Front Office. I have already read this subject : viewtopic.php?f=12&t=530&p=1572&hilit=structuredcontentimpl#p1572 but I haven't find the solution !

My main issue is when I want to add an instance of MyStructuredContent in the admin, the field "locale" isn't in the form... This field seems to be added in the StructuredContentCustomPersistenceHandler but I don't know if this Handler is used with an instance of MyStructuredContent.

Do you have any suggestions ?

Thank you for your help !
Pierre-Baptiste.

Re: Extend StructuredContentImpl

Posted: Mon Apr 08, 2013 10:41 am
by pbechu
Hi !

No suggestions for this issue ?

Pierre-Baptiste.

Re: Extend StructuredContentImpl

Posted: Mon Apr 08, 2013 12:56 pm
by phillipuniverse
Sorry for the delayed reply and thanks for the bump.

Yes, the subclass of StructuredContentImpl will apply to that custom persistence handler. The 'canHandleInspect' method checks the ceilingEntityFullyQualifiedClassname and even though you are pulling back MyStructuredContent, the ceiling entity in that persistence package will still be 'StructuredContent' (the Broadleaf class).

For your problem, you should be able to simply annotate that allProducts list with @AdminPresentationCollection:

Code: Select all

public class MyStructuredContent extends StructuredContentImpl {
   @
ManyToMany(targetEntity ProductImpl.class)
    @
JoinTable(name "MY_SC_PRODUCT_XREF"joinColumns = @JoinColumn(name "SC_ID"referencedColumnName "SC_ID"), inverseJoinColumns = @JoinColumn(name "PRODUCT_ID"referencedColumnName "PRODUCT_ID"))
    @
BatchSize(size 50)
    @
AdminPresentationCollection(friendlyName="Products"addType=AddMethodType.LOOKUP)
    protected List<
ProductallProduct = new ArrayList<Product>();

}
 


In the code above I changed the @ManyToMany(targetEntity=ProductImpl.class) (it was just 'Product.class' which wouldn't have worked).

This @AdminPresentationCollection annotation should build a list grid on the StructuredContent section with the list of Products that are associated to a particular piece of StructuredContent. Also, because the 'addType=AddMethodType.LOOKUP', when you hit the 'Add' button on that list grid it will bring up a search dialog for you to associate a pre-existing Product to that StructuredContent.

Let me know if any of that is unclear or didn't work. Thanks!

Re: Extend StructuredContentImpl

Posted: Tue Apr 09, 2013 8:28 am
by pbechu
Thank for your answer !
I tried many things to solve this issue but I couldn't show the "locale" field for an instance of MyStructuredContent.
Base StructuredContent : Image
MyStructuredContent : Image

I had to do a bad thing but I didn't see an other way. Our website will use only one "locale", so I just added this locale ("fr_FR") in the constructor of MyStructuredContent.

Code: Select all

   public MyStructuredContent() {
      super();
      Locale locale = new LocaleImpl();
      locale.setLocaleCode("fr_FR");
      this.setLocale(locale);      
   }


Now, it works fine and I can attach products to MyStructuredContent, with the help of your last answer ;) !

Bye,
Pierre-Baptiste.

Re: Extend StructuredContentImpl

Posted: Tue Apr 09, 2013 11:57 am
by pbechu
Hi !
Badly with my solution, we must have a bi-directional ManyToMany (cf http://forum.broadleafcommerce.org/viewtopic.php?f=13&t=1624&p=4259&hilit=relationship#p4259).

Is there an other solution without a bi-directional ManyToMany ?
Thank you for your help,

Pierre-Baptiste.