Page 1 of 1

Non Persistant Fields on Entities In admin

Posted: Mon Jun 30, 2014 2:11 pm
by retaildev
Hi,

I would like to have some non persistant field on entities in Admin section. Which i like to display on UI but didn't persist into db but rather do some calculation based on the input.

I am using 3.0 currently.

I see this piece of Code:
Class: PersistencePackageFactoryImpl
Method: public PersistencePackage create(PersistencePackageRequest request)
Code:
persistencePerspective.setAdditionalNonPersistentProperties(new String[] {});

This gets used in the flow to fetch the proeprties and set it into the merged properties.

Also, i made some changes to DynamicEntityDaoImpl to get the correct presentationAttribute instead of hardcoded one.

But my question is, which is the best way to populate these fields in persistenceperspective by reading it from annotation as create method just takes the PersistencePackageRequest object.

Is there any hook to do it ?

Thanks
Dev

Re: Non Persistant Fields on Entities In admin

Posted: Wed Jul 02, 2014 3:12 pm
by RapidTransit
org.broadleafcommerce.openadmin.server.service.persistence.module.provider.FieldPersistenceProvider does the trick

Re: Non Persistant Fields on Entities In admin

Posted: Fri Jul 04, 2014 1:04 am
by retaildev
Hi,

Not able to understand your response fully..
It will be grateful if you could point me to an example or something..

Thanks
Dev

Re: Non Persistant Fields on Entities In admin

Posted: Sat Jul 05, 2014 9:24 am
by RapidTransit
Just take note, that this was a hacky workaround, because JRebel wasn't updating my class, I thought HANDLED_BREAK wasn't working and I didn't have time to update it. See here viewtopic.php?f=13&t=3137

Code: Select all

@Component("blOrderItemsProvider")
@Scope("prototype")
public class OrderItemsCustomProvider extends FieldPersistenceProviderAdapter {

    @Override
    public FieldProviderResponse extractValue(ExtractValueRequest extractValueRequest, Property property) {
        String entity = extractValueRequest.getEntity().getClass().getName();
        String clazz = DiscreteOrderItemImpl.class.getName();

        if(entity.equals(clazz)){
                DiscreteOrderItem orderItem = (DiscreteOrderItem) extractValueRequest.getEntity();
                String name = orderItem.getProduct().getDefaultCategory().getName() + " " + orderItem.getProduct().getName() + " " + orderItem.getName();
                List<Property> props = extractValueRequest.getProps();

                for(int i =0; i < props.size(); i++){
                    if(props.get(i).getName().equals("name")){
                        props.get(i).setValue(name);
                        break;
                    }
                }
                return FieldProviderResponse.HANDLED;
        }
        return FieldProviderResponse.NOT_HANDLED;
    }

    @Override
    public int getOrder() {
        return 1000;
    }
}

Re: Non Persistant Fields on Entities In admin

Posted: Wed Jul 09, 2014 3:54 pm
by retaildev
Hi,

Thanks @RapidTransit, it helped my case.

Thanks
Dev