Hello everyone! Doing my project I found one problem - I cannot understand how to extend base action for groupTable. Because using annotation @Subscribe overrides base action
But I wanna to save both base action and add something my own
I’ll be very grateful for every you feedback?
Hello @olegmps2014,
Below are the steps to create action that contains base and custom logic:
For example, we will complement the Remove Action
by calling the notification before deletion.
- CustomRemoveAction class
package com.company.sample.web.actions;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.gui.ComponentsHelper;
import com.haulmont.cuba.gui.Notifications;
import com.haulmont.cuba.gui.actions.list.RemoveAction;
import com.haulmont.cuba.gui.components.ActionType;
import com.haulmont.cuba.gui.components.Component;
@ActionType("customRemove")
public class CustomRemoveAction<E extends Entity> extends RemoveAction<E> {
public CustomRemoveAction(String id) {
super(id);
}
@Override
public void actionPerform(Component component) {
Notifications notifications = ComponentsHelper.getScreenContext(target).getNotifications();
notifications.create(Notifications.NotificationType.TRAY)
.withCaption("Custom Remove Action")
.show();
super.actionPerform(component);
}
}
- In the
web-spring.xml
file, add<gui:actions>
element with thebase-packages
attribute pointing to a package where to find your annotated actions:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:gui="http://schemas.haulmont.com/cuba/spring/cuba-gui.xsd">
<!-- ... -->
<gui:actions base-packages="com.company.sample.web.actions"/>
</beans>
- Replace
remove
action withcustomeRemove
action in XML descriptor:
<groupTable id="customersTable">
<actions>
<action id="customRemove" type="customRemove"/>
</actions>
<columns>
<!-- ... -->
</columns>
<buttonsPanel>
<button action="customersTable.customRemove"/>
</buttonsPanel>
</groupTable>
Our documentation contains an example of overriding a standard action link.
Regards,
Gleb
@durygin
Thank you for your answer, but I meet one more problem - I can’t extend edit action
here the my attempts to do the same thing in my project:
import com.haulmont.cuba.gui.ComponentsHelper;
import com.haulmont.cuba.gui.Notifications;
import com.haulmont.cuba.gui.components.ActionType;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.ListComponent;
import com.haulmont.cuba.gui.components.actions.EditAction;
@ActionType(“customEdit”)
public class CustomEdit extends EditAction {
public CustomEdit(ListComponent target) {
super(target);
}
@Override
public void actionPerform(Component component) {
Notifications notification = ComponentsHelper.getScreenContext(target).getNotifications();
notification.create(Notifications.NotificationType.TRAY)
.withCaption("Edited")
.show();
but it throws
NoSuchMethodException: com.mypackage.myproject.actions.CustomEdit .“init” (java.lang.String)
Hi @olegmps2014,
You are trying to overwrite legacy EditAction
. In platform versions 7+ we have new standard actions. You can import new EditAction
by the following path: com/haulmont/cuba/gui/actions/list/EditAction.java
.
Regards,
Gleb
Hello, @durygin
I have one more question and it is about how to add ```
urlrouting into class of extention of some action?
I tried to do it with a such way:
private UrlRouting urlRouting = AppBeans.get(UrlRouting.class);
but it throws such error:
Hello @olegmps2014,
You can use the following code:
UrlRouting urlRouting = ComponentsHelper.getScreenContext(target).getUrlRouting();
Regards,
Gleb