Page 1 of 1
Admin - Adding fields to Admin UI (AdminPresentation)
Posted: Tue Dec 10, 2013 1:11 am
by maaristi
Hi.
I´ve searched how to add my own fields to Admin UI but I haven't been able to do so.
Tried creating my own entity and adding AdminPresentation annotations:
Code: Select all
@Entity
@Table(name = "BLC_MYENTITY")
@AdminPresentationClass(friendlyName = "myentity")
public class myentity implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(name = "MY_TYPE")
@AdminPresentation(friendlyName="My Type")
protected String customType;
@Column(name = "SALE_PRICE_MYENTITY", precision = 19, scale = 5)
@AdminPresentation(friendlyName = "SkuImpl_Sku_Sale_Price_Myentity", order = 2000,
group = ProductImpl.Presentation.Group.Name.Price, groupOrder = ProductImpl.Presentation.Group.Order.Price,
prominent = true, gridOrder = 9,
fieldType = SupportedFieldType.MONEY)
protected BigDecimal salePriceMyentity;
@Column(name = "AVAILABLE_FLAG")
@AdminPresentation(friendlyName = "SkuImpl_Sku_Available_Myentity", order = 2200,
tab = ProductImpl.Presentation.Tab.Name.Inventory, tabOrder = ProductImpl.Presentation.Tab.Order.Inventory,
group = ProductImpl.Presentation.Group.Name.Inventory, groupOrder = ProductImpl.Presentation.Group.Order.Inventory)
protected Character availableMyentity;
}
am I missing something? Should I configure my own entity in applicationContext-entity? Or should I insert permissions for the new fields and entity in Admin UI in some of these tables: BLC_ADMIN_MODULE, BLC_ADMIN_PERMISSION, BLC_ADMIN_PERMISSION_ENTITY?
Thanks in advance for your help!
Re: Admin - Adding fields to Admin UI (AdminPresentation)
Posted: Tue Dec 10, 2013 7:54 am
by maaristi
I'm using Broadleaf 3.0.6
Re: Admin - Adding fields to Admin UI (AdminPresentation)
Posted: Tue Dec 10, 2013 11:09 am
by phillipuniverse
If this is a brand new entity and not a subclass of an existing entity (looks like it is) then you need to create a new AdminSection for it so that it will show up in the navigation sidebar on the left. One of the properties in AdminSection is the fully qualified classname which you want to set to your entity.
And yes, you will have to have permissions in BLC_ADMIN_PERMISSIONS for your new entity. This is an example of permissions for the CRUD operations on Category:
Code: Select all
INSERT INTO BLC_ADMIN_PERMISSION (ADMIN_PERMISSION_ID, DESCRIPTION, NAME, PERMISSION_TYPE) VALUES (-2,'Create Category','PERMISSION_CREATE_CATEGORY', 'CREATE');
INSERT INTO BLC_ADMIN_PERMISSION (ADMIN_PERMISSION_ID, DESCRIPTION, NAME, PERMISSION_TYPE) VALUES (-3,'Update Category','PERMISSION_UPDATE_CATEGORY', 'UPDATE');
INSERT INTO BLC_ADMIN_PERMISSION (ADMIN_PERMISSION_ID, DESCRIPTION, NAME, PERMISSION_TYPE) VALUES (-4,'Delete Category','PERMISSION_DELETE_CATEGORY', 'DELETE');
INSERT INTO BLC_ADMIN_PERMISSION (ADMIN_PERMISSION_ID, DESCRIPTION, NAME, PERMISSION_TYPE) VALUES (-5,'Read Category','PERMISSION_READ_CATEGORY', 'READ');
INSERT INTO BLC_ADMIN_PERMISSION (ADMIN_PERMISSION_ID, DESCRIPTION, NAME, PERMISSION_TYPE) VALUES (-6,'All Category','PERMISSION_ALL_CATEGORY', 'ALL');
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-1, 'org.broadleafcommerce.core.catalog.domain.Category', -2);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-2, 'org.broadleafcommerce.core.catalog.domain.Category', -3);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-4, 'org.broadleafcommerce.core.catalog.domain.Category', -4);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-6, 'org.broadleafcommerce.core.catalog.domain.Category', -5);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-7, 'org.broadleafcommerce.core.catalog.domain.Category', -6);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-8, 'org.broadleafcommerce.core.catalog.domain.CategoryAttribute', -2);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-9, 'org.broadleafcommerce.core.catalog.domain.CategoryAttribute', -3);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-10, 'org.broadleafcommerce.core.catalog.domain.CategoryAttribute', -4);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-11, 'org.broadleafcommerce.core.catalog.domain.CategoryAttribute', -5);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-12, 'org.broadleafcommerce.core.catalog.domain.CategoryAttribute', -6);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-13, 'org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl', -2);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-14, 'org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl', -3);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-15, 'org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl', -4);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-16, 'org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl', -5);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-17, 'org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl', -6);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-18, 'org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl', -2);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-19, 'org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl', -3);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-20, 'org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl', -4);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-21, 'org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl', -5);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-22, 'org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl', -6);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-23, 'org.broadleafcommerce.core.catalog.domain.FeaturedProductImpl', -2);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-24, 'org.broadleafcommerce.core.catalog.domain.FeaturedProductImpl', -3);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-25, 'org.broadleafcommerce.core.catalog.domain.FeaturedProductImpl', -4);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-26, 'org.broadleafcommerce.core.catalog.domain.FeaturedProductImpl', -5);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-27, 'org.broadleafcommerce.core.catalog.domain.FeaturedProductImpl', -6);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-28, 'org.broadleafcommerce.core.catalog.domain.CrossSaleProductImpl', -2);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-29, 'org.broadleafcommerce.core.catalog.domain.CrossSaleProductImpl', -3);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-30, 'org.broadleafcommerce.core.catalog.domain.CrossSaleProductImpl', -4);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-31, 'org.broadleafcommerce.core.catalog.domain.CrossSaleProductImpl', -5);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-32, 'org.broadleafcommerce.core.catalog.domain.CrossSaleProductImpl', -6);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-33, 'org.broadleafcommerce.core.catalog.domain.UpSaleProductImpl', -2);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-34, 'org.broadleafcommerce.core.catalog.domain.UpSaleProductImpl', -3);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-35, 'org.broadleafcommerce.core.catalog.domain.UpSaleProductImpl', -4);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-36, 'org.broadleafcommerce.core.catalog.domain.UpSaleProductImpl', -5);
INSERT INTO BLC_ADMIN_PERMISSION_ENTITY (ADMIN_PERMISSION_ENTITY_ID, CEILING_ENTITY, ADMIN_PERMISSION_ID) VALUES (-37, 'org.broadleafcommerce.core.catalog.domain.UpSaleProductImpl', -6);
So basically, you need the fully qualified classname for your entity as well as any entities that relate to that entity so that you can properly fetch all of them in the admin. Then, you can hook up the BLC_ADMIN_PERMISSION entries to a role, which you can then assign to an admin user. If you do not want to be fine-grained about each individual CRUD operation, you can use the 'PERMISSION_ALL' one.
Re: Admin - Adding fields to Admin UI (AdminPresentation)
Posted: Tue Dec 10, 2013 12:54 pm
by maaristi
Thanks Phillip.
What if I really want to add another field to an existing Section (Product in my case)?
What I need is something similar to basic inventory module does: Create a class and map an attribute from this class to a new field in the Product Section.
(From:
https://github.com/BroadleafCommerce/ba ... rImpl.java )
Code: Select all
package org.broadleafcommerce.inventory.basic.domain.ext;
import org.broadleafcommerce.common.presentation.AdminPresentation;
import org.broadleafcommerce.core.catalog.domain.ProductImpl;
import javax.persistence.Column;
public class BasicInventoryContainerImpl implements BasicInventoryContainer {
@Column(name = "BASIC_INVENTORY_QTY_AVAIL")
@AdminPresentation(friendlyName = "SkuImpl_Sku_BasicInventoryAvailable",
order = 1010,
tab = ProductImpl.Presentation.Tab.Name.Inventory,
tabOrder = ProductImpl.Presentation.Tab.Order.Inventory,
group = ProductImpl.Presentation.Group.Name.Inventory,
groupOrder = ProductImpl.Presentation.Group.Order.Inventory)
protected Integer basicQuantityAvailable = 0;
@Override
public void setQuantityAvailable(Integer quantityAvailable) {
this.basicQuantityAvailable = quantityAvailable;
}
@Override
public Integer getQuantityAvailable() {
return this.basicQuantityAvailable;
}
}
Note that the class maps the basicQuantityAvailable attribute to Product Section in Admin UI.
I'm trying this goal with my own class but the field doesn't show up.
I looked into BLC_ADMIN_PERMISSIONS but it seems like this manages section-level permissions, not field-levels permissions.
What do I need to do in order to map an attribute from my own class to an existing section in the Admin UI?
Thanks!
Re: Admin - Adding fields to Admin UI (AdminPresentation)
Posted: Tue Dec 10, 2013 1:06 pm
by phillipuniverse
In that inventory module those properties are weaved into a Sku with this configuration:
https://github.com/BroadleafCommerce/ba ... ontext.xml.
In order to get this to work you will need to have spring-instrument.jar hooked up.
However, if you are doing this is in your own application, simply extend SkuImpl and add your custom property to it. No need to mess around with load time weaving. We have docs for this at
http://docs.broadleafcommerce.org/core/ ... g-entities and
http://docs.broadleafcommerce.org/core/ ... s-tutorial.
Re: Admin - Adding fields to Admin UI (AdminPresentation)
Posted: Wed Dec 11, 2013 7:01 pm
by maaristi
Thank yo so much!
I already have basic inventory working. The new field isn't visible in admin UI if the Sku doesn't have any value in the new table of my new entity, but when Sku have a value in my new entity, the field is visible. The new field is also visible when adding new product.
Thanks!
Re: Admin - Adding fields to Admin UI (AdminPresentation)
Posted: Mon Jan 13, 2014 7:11 am
by chal4oye
Should I configure my own entity in applicationContext-entity? Or should I insert permissions for the new fields and entity in Admin UI in some of these tables: BLC_ADMIN_MODULE, BLC_ADMIN_PERMISSION, BLC_ADMIN_PERMISSION_ENTITY?
Re: Admin - Adding fields to Admin UI (AdminPresentation)
Posted: Mon Jan 13, 2014 1:40 pm
by phillipuniverse
No, no need to add something to applicationContext-entity. That file is so that Broadleaf knows what type of entity to instantiate. For instance, when Broadleaf goes to instantiate an Order, you might want to tell Broadleaf to instantiate some extended class or OrderImpl.
You should just be able to populate those permission tables that you referenced.