Noticed after migrating to platform version 7.2.1 that one of my editor screen (Journal) is not throwing an exception when I want to create or edit from browser. Here is the error:
java.lang.NullPointerException
at com.haulmont.cuba.gui.xml.layout.loaders.AbstractTableLoader.loadComponent(AbstractTableLoader.java:174)
at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponents(ContainerLoader.java:38)
at com.haulmont.cuba.gui.xml.layout.loaders.SplitPanelLoader.loadComponent(SplitPanelLoader.java:78)
at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponents(ContainerLoader.java:38)
at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponentsAndExpand(ContainerLoader.java:76)
at com.haulmont.cuba.gui.xml.layout.loaders.AbstractBoxLoader.loadComponent(AbstractBoxLoader.java:50)
at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponents(ContainerLoader.java:38)
at com.haulmont.cuba.gui.xml.layout.loaders.TabSheetLoader.loadComponent(TabSheetLoader.java:93)
at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponents(ContainerLoader.java:38)
at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponentsAndExpand(ContainerLoader.java:76)
at com.haulmont.cuba.gui.xml.layout.loaders.GroupBoxLayoutLoader.loadComponent(GroupBoxLayoutLoader.java:67)
at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponents(ContainerLoader.java:38)
at com.haulmont.cuba.gui.xml.layout.loaders.ScrollBoxLayoutLoader.loadComponent(ScrollBoxLayoutLoader.java:63)
at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponents(ContainerLoader.java:38)
at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponentsAndExpand(ContainerLoader.java:76)
at com.haulmont.cuba.gui.xml.layout.loaders.WindowLoader.loadComponent(WindowLoader.java:94)
at com.haulmont.cuba.web.sys.WebScreens.loadWindowFromXml(WebScreens.java:366)
at com.haulmont.cuba.web.sys.WebScreens.createScreen(WebScreens.java:233)
at com.haulmont.cuba.web.sys.WebScreens.create(WebScreens.java:175)
at com.haulmont.cuba.gui.builders.EditorBuilderProcessor.createScreen(EditorBuilderProcessor.java:285)
at com.haulmont.cuba.gui.builders.EditorBuilderProcessor.buildEditor(EditorBuilderProcessor.java:87)
at com.haulmont.cuba.gui.builders.EditorBuilder.build(EditorBuilder.java:359)
at com.haulmont.cuba.gui.actions.list.EditAction.execute(EditAction.java:301)
at com.haulmont.cuba.gui.actions.list.EditAction.actionPerform(EditAction.java:267)
at com.haulmont.cuba.web.gui.components.WebButton.buttonClicked(WebButton.java:67)
at com.haulmont.cuba.web.widgets.CubaButton.fireClick(CubaButton.java:76)
at com.vaadin.ui.Button$1.click(Button.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:153)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:115)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:431)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:396)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:260)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:82)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1578)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:425)
at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:329)
at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:215)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:108)
at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:74)
at com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:93)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
It seems something wrong with dsContext. Could you share the screen descriptor and controller? Or if it is possible, please share a small demo project with your problem.
@UiController("erp$Journal.edit")
@UiDescriptor("journal-edit.xml")
@EditedEntityContainer("journalDc")
@LoadDataBeforeShow
public class JournalEdit extends StandardEditor<Journal> {
@Inject
private InteaccUtilService inteaccUtilService;
@Inject
private UserSessionSource userSessionSource;
@Inject
private NumberGenerationService numberGenerationService;
@Inject
private AccountsService accountsService;
@Inject
private TimeSource timeSource;
@Inject
private UiComponents uiComponents;
@Inject
private Notifications notifications;
@Inject
private InstanceContainer<Journal> journalDc;
@Inject
private Table<JournalLine> journalLineTable;
@Inject
private LookupPickerField<Company> companyField;
@Inject
private CollectionPropertyContainer<JournalLine> journalLineDc;
@Inject
private CollectionContainer<AccountSub> accountSubsDc;
@Inject
private CollectionContainer<CostCentre> costCentresDc;
@Inject
private CollectionLoader<Account> accountsDl;
@Inject
private CollectionContainer<Account> accountsDc;
@Inject
private CollectionContainer<FinancialYear> financialYearsDc;
@Inject
private CollectionPropertyContainer<JournalAttachment> journalAttachmentDc;
@Inject
private Image imageView;
@Inject
private Embedded pdfView;
@Inject
private Table journalAttachmentsTable;
@Inject
private DataContext dataContext;
@Subscribe
private void onAfterInit(AfterInitEvent event) {
initTableColumnListeners();
initComboColums();
}
@Subscribe
public void onAfterShow(AfterShowEvent event) {
Company defaultCompany = userSessionSource.getUserSession().getAttribute("defaultCompany");
if (defaultCompany != null) {
getEditedEntity().setCompany(defaultCompany);
getEditedEntity().setCurrency(userSessionSource.getUserSession().getAttribute("defaultCurrency"));
getEditedEntity().setFinancialYear(inteaccUtilService.getFinancialYearFromCurrentDate(defaultCompany));
getEditedEntity().setFinancialPeriod(inteaccUtilService.getFinancialPeriodFromCurrentDate(defaultCompany));
}
if (PersistenceHelper.isNew(getEditedEntity())) {
getEditedEntity().setCompany(defaultCompany);
getEditedEntity().setCurrency(getEditedEntity().getCompany().getBaseCurrency());
}
//companyField.setEditable(true);
getEditedEntity().setTransactionStatus(TransactionStatus.NEW);
getEditedEntity().setDocDate(timeSource.currentTimestamp());
//sortLines();
if (getEditedEntity().getCompany() != null) {
loadChartOfAccount();
loadFinancialYearList();
}
}
@Subscribe("docDateField")
public void onDocDateFieldValueChange(HasValue.ValueChangeEvent<Date> event) {
if(getEditedEntity().getDocDate()!=null)
showFinancialYear();
}
@Subscribe
protected void onBeforeCommit(BeforeCommitChangesEvent event) {
calculateAmount();
}
private void sortLines() {
// bankTranLineTable.sortBy(bankTranLineDs.getMetaClass().getPropertyPath("entryNumber"), true);
}
@Subscribe("journalLineTable.create")
private void onJournalLineTableCreate(Action.ActionPerformedEvent event) {
addNewRow(null);
}
@Override
protected void validateAdditionalRules(ValidationErrors errors) {
if(getEditedEntity().getJournalLine()==null){
errors.add("Sorry, there was no detail transactions found in the table, can't Save..");
}else {
BigDecimal received = BigDecimal.ZERO;
BigDecimal paid = BigDecimal.ZERO;
//deleting empty row
if (journalLineDc.getMutableItems().size() > 0) {
List<JournalLine> toRemove = new ArrayList<>();
Iterator<JournalLine> iteratorLineList = getEditedEntity().getJournalLine().iterator();
while (iteratorLineList.hasNext()) {
JournalLine line = iteratorLineList.next();
if (((line.getDebit() == null) || (line.getCredit() == BigDecimal.ZERO)) && ((line.getCredit() == null) || (line.getCredit() == BigDecimal.ZERO))) {
toRemove.add(line);
}
}
for (JournalLine line : toRemove) {
journalLineDc.getMutableItems().remove(line);
dataContext.remove(line);
}
}
for (JournalLine line : getEditedEntity().getJournalLine()) {
if (line.getAccount() == null) {
errors.add("Invalid Account");
}
if (line.getAccount().getHavingSubAccount() == true)
if (line.getAccountSub() == null)
errors.add("Sorry, Sub-account field is empty");
}
}
}
private void calculateAmount() {
//Calculate total
getEditedEntity().setTotalDebit(getEditedEntity().getJournalLine().stream().map(JournalLine::getDebit)
.reduce(BigDecimal.ZERO, BigDecimal::add));
getEditedEntity().setTotalCredit(getEditedEntity().getJournalLine().stream().map(JournalLine::getCredit)
.reduce(BigDecimal.ZERO, BigDecimal::add));
}
private void proposeDebitOrCreditAmount() {
if (journalLineDc.getMutableItems().size() > 1) {
//Calculate the total of Debit and Credit
/*
BigDecimal dr = BigDecimal.ZERO;
BigDecimal cr = BigDecimal.ZERO;
for (JournalLine line : journalLineDs.getItems()) {
if(line.getDebit() != null) {
dr = dr.add(line.getDebit());
}
if(line.getCredit() !=null) {
cr = cr.add(line.getCredit());
}
}
*/
BigDecimal dr = getEditedEntity().getJournalLine().stream().map(JournalLine::getDebit)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal cr = getEditedEntity().getJournalLine().stream().map(JournalLine::getCredit)
.reduce(BigDecimal.ZERO, BigDecimal::add);
JournalLine i = Iterables.getLast(journalLineDc.getItems());
if (((i.getDebit() == null) || (i.getCredit() == BigDecimal.ZERO)) && ((i.getCredit() == null) || (i.getCredit() == BigDecimal.ZERO))) {
BigDecimal net = BigDecimal.ZERO;
if (dr.doubleValue() >= cr.doubleValue()) {
dr = dr.subtract(cr);
journalLineDc.getItem().setCredit(dr);
} else {
cr = cr.subtract(dr);
journalLineDc.getItem().setDebit(cr);
}
}
if (i.getAccount().getAccountSub().size() > 0) {
i.setAccountSub(null);
//accountSubsDl.load();
// set focus on the first cell of the added row
journalLineTable.requestFocus(i, "accountSub");
} else {
//i.setCostCentre(null);
//costCentresDs.refresh();
journalLineTable.requestFocus(i, "costCentre");
}
}
}
private void addNewRow(CostCentre costCentre) {
if (okToCreate()) {
JournalLine line = dataContext.create(JournalLine.class);
line.setJournal(getEditedEntity());
line.setCostCentre(costCentre);
line.setDebit(BigDecimal.ZERO);
line.setCredit(BigDecimal.ZERO);
line.setDebitFc(BigDecimal.ZERO);
line.setCreditFc(BigDecimal.ZERO);
//creating lineNumber
int max = 0;
Integer lastNum = journalLineDc.getItems().stream()
.map(JournalLine::getLineNumber)
.max(Integer::compareTo)
.orElse(0);
line.setLineNumber(lastNum + 1);
journalLineDc.getMutableItems().add(line);
journalLineTable.setSelected(line);
// sortLines();
// set focus on the first cell of the added row
journalLineTable.requestFocus(line, "account");
journalLineTable.scrollTo(line);
} else {
notifications.create(Notifications.NotificationType.HUMANIZED).withDescription("Please select the company first").show();
}
}
private boolean okToCreate() {
boolean ok = true;
if (getEditedEntity().getCompany() == null) ok = false;
if (getEditedEntity().getDocDate() == null) ok = false;
if (getEditedEntity().getFinancialYear() == null) ok = false;
if (ok == false)
notifications.create(Notifications.NotificationType.WARNING).withDescription("Sorry, please update the required fields before inserting a row").show();
return ok;
}
private void fixEntryNumbers() {
int num = 1;
for (JournalLine line : journalLineDc.getItems()) {
line.setLineNumber(num++);
}
}
private void initComboColums() {
journalLineTable.addGeneratedColumn("accountSub", entity -> {
if (entity.getAccount() != null) {
if (entity.getAccount().getHavingSubAccount() == true) {
LookupField<AccountSub> lookupField = uiComponents.create(LookupField.of(AccountSub.class));
lookupField.setWidth("100%");
lookupField.setOptions(new ContainerOptions<>(accountSubsDc));
lookupField.setValue(entity.getAccountSub());
lookupField.addValueChangeListener(e -> entity.setAccountSub((e.getValue())));
return lookupField;
} else {
return null;
}
} else {
return null;
}
});
}
private void initTableColumnListeners() {
journalLineDc.addItemPropertyChangeListener(e -> {
if ("account".equals(e.getProperty())) {
/*
if (e.getItem().getAccount().getAccountSub().size() > 0) {
e.getItem().setAccountSub(null);
//accountSubsDl.load();
// set focus on the first cell of the added row
journalLineTable.requestFocus(e.getItem(), "accountSub");
} else {
e.getItem().setCostCentre(null);
//costCentresDs.refresh();
journalLineTable.requestFocus(e.getItem(), "costCentre");
}
*/
proposeDebitOrCreditAmount();
/*
} else if ("accountSub".equals(e.getProperty())) {
if (e.getItem().getAccount().getHavingSubAccount() == Boolean.TRUE) {
if (e.getItem().getAccountSub() == null) {
notifications.create(Notifications.NotificationType.WARNING).withDescription("Incorrect Data entry, Please select the sub-account").show();
}
}
*/
}else if ("costCentre".equals(e.getProperty())) {
journalLineTable.requestFocus(e.getItem(), "reference");
}else if ("accountSub".equals(e.getProperty())) {
journalLineTable.requestFocus(e.getItem(), "costCentre");
} else if ("debit".equals(e.getProperty())) {
if (e.getItem().getDebit().longValue() > 0) {
e.getItem().setCredit(new BigDecimal(0));
//if (Iterables.getLast(journalLineDs.getItemIds()) == e.getItem().getId()) {
JournalLine i = Iterables.getLast(journalLineDc.getItems());
if (i.getId() == e.getItem().getId()) {
CostCentre costCentre = null;
if( e.getItem().getCostCentre()!=null)
costCentre = e.getItem().getCostCentre();
addNewRow(costCentre);
}
} else {
//get the balanance of Credit
BigDecimal d = getEditedEntity().getTotalDebit();
BigDecimal c = getEditedEntity().getTotalCredit();
e.getItem().setCredit(getEditedEntity().getTotalDebit().subtract(getEditedEntity().getTotalCredit()));
}
} else if ("credit".equals(e.getProperty())) {
if (e.getItem().getCredit().longValue() > 0) {
e.getItem().setDebit(new BigDecimal(0));
JournalLine i = Iterables.getLast(journalLineDc.getItems());
if (i.getId() == e.getItem().getId()) {
//if (Iterables.getLast(journalLineDc.getItemIds()) == e.getItem().getId()) {
CostCentre costCentre = null;
if( e.getItem().getCostCentre()!=null)
costCentre = e.getItem().getCostCentre();
addNewRow(costCentre);
}
}
}
});
}
private void loadChartOfAccount() {
accountsDc.getMutableItems().clear();
//load chart of account of the selected company
//Company company = getEditedEntity().getCompany();
List<Account> accountList = accountsService.getAccountListFromCompany(getEditedEntity().getCompany(), "accountSub-view");
accountsDc.setItems(accountList);
// for (Account account : accountList) {
// accountsDc.getMutableItems().add(account);
// }
//ToDO
/*select e from erp$Account e
where e.accountHeader = FALSE and e in (select line.account from erp$ChartOfAccountLine line
where line.chartOfAccount = :coa)
*/
// accountsService.getChartOfAccount();
// accountsDl.setParameter("coa", getEditedEntity().getCompany().getChartOfAccount().getId());
// accountsDl.load();
}
private void loadFinancialYearList() {
financialYearsDc.getMutableItems().clear();
//load chart of account of the selected company
Company company = getEditedEntity().getCompany();
List<FinancialYear> financialYearAllList = accountsService.getFinancialYearAllList(company, "financialYear-view");
for (FinancialYear financialYear : financialYearAllList) {
financialYearsDc.getMutableItems().add(financialYear);
}
}
private void showFinancialYear() {
Date date = getEditedEntity().getDocDate();
Company company = getEditedEntity().getCompany();
if (date != null) {
if (company != null) {
FinancialYear financialYear = inteaccUtilService.getFinancialYearFromDate(company, date);
if (financialYear != null) {
getEditedEntity().setFinancialYear(financialYear);
getEditedEntity().setFinancialPeriod(inteaccUtilService.getFinancialPeriodFromDate(company, date));
} else {
notifications.create(Notifications.NotificationType.WARNING).withDescription("Sorry, the date is invalid, no financial year exists").show();
getEditedEntity().setDocDate(null);
getEditedEntity().setFinancialYear(null);
}
}
}
}
public void onRemoveFile(Component source) {
if (journalAttachmentDc.getItem() != null) {
journalAttachmentDc.getMutableItems().remove(journalAttachmentDc.getItem());
}
}
public void onDownloadButtonClick(Component source) {
//FileDescriptor fd = journalAttachmentsTable.getSingleSelected().getAttachment();
JournalAttachment journalAttachment = (JournalAttachment) journalAttachmentsTable.getSingleSelected();
FileDescriptor fd = journalAttachment.getAttachment();
if (fd!=null){
// AppConfig.createExportDisplay(JournalEdit.this).show(fd,null);
}
}
public void onShowButtonClick(Component source) {
//FileDescriptor fd = journalAttachmentsTable.getSingleSelected().getAttachment();
JournalAttachment journalAttachment = (JournalAttachment) journalAttachmentsTable.getSingleSelected();
FileDescriptor fd = journalAttachment.getAttachment();
if (fd != null) {
if (fd.getExtension().equalsIgnoreCase("pdf")) {
/*
pdfView.setSource(String.format("%s.pdf", fd.getUuid()), new FileDataProvider(fd));
pdfView.setType(Embedded.Type.BROWSER);
*/
imageView.setVisible(false);
pdfView.setVisible(true);
pdfView.setSource(String.format("pdf-preview%s.pdf", UUID.randomUUID()),
new FileDataProvider(fd));
} else {
imageView.setSource(FileDescriptorResource.class).setFileDescriptor(fd);
pdfView.setVisible(false);
imageView.setVisible(true);
}
}
}
I have reproduced it when I create the screen in Studio 13 & platform 7.2.x from the Entity I have created in older version of the platform i.e. Entity like erp$Journal vs. erp_Journal