Hello,
I have a method and an if condition in order to disable a Refresh Button action.
I don’t want the Refresh Button to make invisible, just do nothing when is pressed (when the if condition is true).
How can I do that?
Regards,
-n
Hello,
I have a method and an if condition in order to disable a Refresh Button action.
I don’t want the Refresh Button to make invisible, just do nothing when is pressed (when the if condition is true).
How can I do that?
Regards,
-n
Hi @neutrino,
The RefreshAction
has a setEnabled(boolean enabled)
method to disable/enable action.
Add a refreshAction.setEnabled(condition)
call in your method.
Regards,
Gleb
Hi Gleb,
I knew this option and that was the reason that I said “I don’t want the Refresh Button to make invisible, just do nothing when is pressed”.
The problem with this option is that before Disable take place
the Refresh button start to perform its functiononce
, which is not ok.
@Subscribe("refreshBtn")
public void onRefreshBtnClick(Button.ClickEvent event) {
refreshMethod();
}
private void refreshMethod(){
if(condition1){
//press Refresh button - no action
}
if(condition2){
press Refresh button - ok
}
}
Regards,
-n
@neutrino In case the Refresh
action is to be performed, do you want to use the base implementation of the Refresh
action or your own implementation?
Hi,
I didn’t think about it. I use base implementation.
I can use a custom implementation as well, np.
Best Regards,
-n
@neutrino you can overwrite RefreshAction
and put your logic in CustomRefreshAction.actionPerform(Component component)
function:
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.RefreshAction;
import com.haulmont.cuba.gui.components.ActionType;
import com.haulmont.cuba.gui.components.Component;
@ActionType("customRefresh")
public class CustomRefreshAction extends RefreshAction {
public CustomRefreshAction(String id) {
super(id);
}
@Override
public void actionPerform(Component component) {
if (condition1) {
//press Refresh button - no action
}
if (condition2) {
//press Refresh button - ok
super.actionPerform(component);
}
}
}
web-spring.xml
file, add <gui:actions>
element with the base-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>
refresh
action with customRefresh
action in XML descriptor:<groupTable id="customersTable">
<actions>
<action id="customRefresh" type="customRefresh"/>
</actions>
<columns>
<!-- ... -->
</columns>
<buttonsPanel>
<button action="customersTable.customRefresh"/>
</buttonsPanel>
</groupTable>
Please, see this topic, where you can find an another example of overwriting a standard action and see our documentation, which explains how to customize standard action.
In addition, in new CUBA 7.2 you can parameterize standard actions without overriding their behavior, see https://doc.cuba-platform.com/manual-7.2/standard_actions.html .
Would be great if you try the 7.2 BETA version and give us some feedback.
Regards,
Gleb
In order to do that I created a new package actions in com.company.sample.web and a new class CustomRefresh Action.
The problem is that here I don’'t have access to browse view elements so I cannot put the condition (ex. dateField.getValue()==null
).
Regards,
-n