EventHandler doesn't work

75 views
Skip to first unread message

Leonardo Antunes

unread,
Sep 9, 2016, 10:05:02 AM9/9/16
to iDempiere
Hello,

I have to do a simple customization validation for the field PriceList in the order line table. If the field be equal 0, the client can't save the record. So, I create a new EventHandler as you can see in the code below, but the system never execute my class:

public class CompanyEventHandler extends AbstractEventHandler
{
   
private static CLogger log = CLogger.getCLogger(CompanyEventHandler.class);
 
    //constants
 
   public static final String MESSAGE_PRICELIST_ZERO = "O valor do preço de lista não pode ser 0";

    protected void initialize()
    {
   
    registerEvent(IEventTopics.AFTER_LOGIN);

   
    registerTableEvent(IEventTopics.PO_BEFORE_CHANGE, MOrderLine.Table_Name);
   
    registerTableEvent(IEventTopics.PO_BEFORE_NEW, MOrderLine.Table_Name);
    }

    protected void doHandleEvent(Event event)
    {

 
      log.info("starting.. Topic :" + event.getTopic());

        if (event.getTopic().equals(IEventTopics.AFTER_LOGIN))
        {
   
        return;
        }


        PO po = getPO(event);

        if (po instanceof MOrderLine
            && (event.getTopic().equals(IEventTopics.PO_BEFORE_CHANGE) ||
                event.getTopic().equals(IEventTopics.PO_BEFORE_NEW)))
        {
   
        MOrderLine mOrderLine = (MOrderLine) po;
   
        if (mOrderLine.getPriceList().equals(new BigDecimal(0)))
   
        {
       
        throw new AdempiereException(MESSAGE_PRICELIST_ZERO);
   
        }
        }
    }
}


I put breakpoints in the beginning of the two methods and the system never execute the class. I follow the instructions of this tutorial https://www.youtube.com/watch?v=zc_Ye8WZ-jc without sucess. I would be greatful if someone can help me.

Nicolas Micoud

unread,
Sep 9, 2016, 10:34:57 AM9/9/16
to iDempiere
Hi,

Do you also create the Component Definition file (xml) ?
See: http://wiki.idempiere.org/en/Developing_Plug-Ins_-_Model_Events

Regards,

Nicolas

Leonardo Antunes

unread,
Sep 9, 2016, 12:56:40 PM9/9/16
to iDempiere
Thank you Nicolas,

The article helped me solve the problem. I forgot to tick the flag "Activate this plug-in when one of its classes is loaded" on the file MANIFEST.MF. After this, the problem was solved.
Reply all
Reply to author
Forward
0 new messages