I created custom method for accepting changes in editor.
Now when I accept changes return to “browse” tab which shows data as it was before editing.
Is there a way to get access datasource that belongs to “browse” tab or some other way to force refreshing data on “browse” tab?
public class TodoEdit extends AbstractEditor<Todo>{
public void onAccept(Component source) {
getItem().setTrusted(newSecurityDs.getItem());
commit();
close("",true);
}
...
p.s. In my example “trusted” property is not shown on “browse” and I fiter out entities that have that property not null
select e from sdata$Todo e where e.trusted is null
The right place of refreshing the browser datasource is the action in the browser that invokes the editor screen.
Assuming that you open the editor via “edit” action, you should add the following code to the browser:
public class TodoBrowse extends AbstractLookup {
@Named("todosTable.edit")
private EditAction todosTableEdit;
@Inject
private CollectionDatasource<Todo, UUID> todosDs;
@Override
public void init(Map<String, Object> params) {
todosTableEdit.setAfterCommitHandler(entity -> todosDs.refresh());
}
}
This “after commit” handler will be invoked if the editor returns Window.COMMIT_ACTION_ID when closed. So you should use this string identifier when calling close() in the editor, or use the special commitAndClose() method:
public class TodoEdit extends AbstractEditor<Todo> {
@Inject
private Datasource<Todo> todoDs;
public void onClosebtnClick(Component source) {
todoDs.getItem().setStatus(1);
commitAndClose();
}
}
assumes that your table has “todosTable” name, the datasource is “todosDs” and you open the editor by clicking on the button connected to “edit” action defined for the table.
Probably you have to adjust the code to use your components.
BTW if you are using IntelliJ, you can easily inject components into controller by pressing Alt+Insert (Generate) and select “Inject”.
I would like to do the same thing but with a different acction like “quickEdit” … because this is not an EditAction it does not know setAfterCommitHandler method… how can I make it inherit EditAction?
java.lang.NullPointerException
at ro.gsdata.arhidoc.web.pa.PaA01aEdit$1.actionPerform(PaA01aEdit.java:84)
at com.haulmont.cuba.web.gui.components.WebButton.performAction(WebButton.java:45)
at com.haulmont.cuba.web.gui.components.WebButton.lambda$new$61446b05$1(WebButton.java:37)
at sun.reflect.GeneratedMethodAccessor181.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:200)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:163)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1037)
at com.vaadin.ui.Button.fireClick(Button.java:377)
at com.haulmont.cuba.web.toolkit.ui.CubaButton.fireClick(CubaButton.java:54)
at com.vaadin.ui.Button$1.click(Button.java:54)
Well, I cannot see what is in your PaA01aEdit.java:84 line which throws the exception. Try to debug your code step-by-step in IDE, you’ll see what variable is not initialized.
I thought that in the controller I can inject any datasource from the application. In fact my datasource was not defined in this particular screen so I had to pass it as a window parameter and it works.
2nd question-
I have called the preCommit method to do some updates (auto-number, status etc) before commit and create a new. It works, is that a right approach?
I understand we have to call commitAndClose in the Editor controller. When I am using a button I can invoke it from that button. My question is, how can I invoke this method when I am using standard window action buttons?
I’m overriding preCommit to set the auto number. If I don’t call it the auto number is not updated. Is there any suggested alternative?
public void save() {
if(preCommit()==true) {
commitAndClose();
}
}
However, I don’t want to close the editor screen after create, rather want the to continue creating more transactions. To achieve that I am using following codes but when I close the screen by clicking close button, the browser it is not refreshed with newly added entries.
calling close_Action in close button action to enable the commitHandler in browser.
public void closeWindow(){
close(CLOSE_ACTION_ID, true);
}
Here I am not using commitAndClose in saveAndCreateNew but using CLOSE_ACTION_ID in close button, isn’t not enough? It’s not refreshed when I go back to browser screen. Thanks for the help.