I am working on a database to track packages received and packages shipped. A package is received, the contents are processed and inspected, and then the package is shipped out again. When a user is receiving a package, he will create an instance on the ‘package’ entity. The user only needs to see a subset of the attributes in ‘package’ (‘date received’, ‘receiving user’, ‘package number’). The same is true when the package is being shipped out (the user only needs to see/edit ‘date shipped’ and shipping user’ attributes).
So far I have figured out how to selectively make individual fields visible and invisible with the pistInit() function in the controller. But it seems clumsy. Surely there must be a way to have multiple edit screens for the same entity, right?
Sure. When creating a screen for an entity in Studio, it will show a dialog if the screen with the same id, descriptor or controller already exists. Just change the conflicting value for the new screen (ID at least), and you will have multiple edit screens for the same entity.
In order to use an edit screen with non-standard ID (not conforming to “entityName.edit” pattern), you have to specify the ID for the CreateAction and EditAction using their setWindowId() method (see Standard Actions over Collection - CUBA Platform. Developer’s Manual), or use openEditor() method directly in a custom action or a handler method which is set in the “invoke” attribute of a button.
I am trying to do just this. Where studio do I implement setWindowId() ?
I have two different edit screens for the same entity, but I can’t seem to locate the field in studio where I set the ID of the screen I would like the second “EDIT” button to open.
Hello, I assume I would do that in the Browse Screen controller.
Is there anywhere where I can see an example of the syntax of this being done? The documentation doesn’t show an example of setWindowId() being used. What I am trying to do is have a button that opens up a separate edit screen that only applies to a couple of fields in the entity.
Thank you in advance.
package com.company.kellygroupapp.web.listing;
import com.haulmont.cuba.gui.components.AbstractLookup;
public class ListingBrowse extends AbstractLookup {
}
Thank you, I think I am getting warmer.
I seem to get 1 compile error.
Error:
:app-web:compileJavaC:\Users\tmeacham\studio-projects\kellygroupapp\modules\web\src\com\company\kellygroupapp\web\listing\ListingBrowse.java:19: error: cannot find symbol
ListingsTableEdit.setWindowId("kellygroupapp$Listing.edit.cl");
^
symbol: variable ListingsTableEdit
location: class ListingBrowse
1 error
FAILED
Code in controller.
package com.company.kellygroupapp.web.listing;
import com.haulmont.cuba.gui.components.AbstractLookup;
//added lines of code [start]
import com.haulmont.cuba.gui.components.actions.EditAction;
import java.util.Map;
import javax.inject.Named;
//added lines of code [end]
public class ListingBrowse extends AbstractLookup {
//added from forum example [start]
@Named("ListingsTable.closeListing")
private EditAction ListingTableEdit;
@Override
public void init(Map<String, Object> params) {
ListingsTableEdit.setWindowId("kellygroupapp$Listing.edit.cl");
}
//added from forum example [end]
}
Is the provided example changing the screen that the default edit action opens or creating a NEW action for an edit button to open a different edit screen.
I am trying to have multiple “edit” buttons that each open a different screen of the same entity.
In the case above I am attempting to have both the original edit button that behaves as normal, and a second edit button (Close Listing) that opens a different screen with a different set of attributes exposed on the screen.
Of course, I am not sure if I am approaching this correctly.
You declare ListingTableEdit variable but reference it as ListingsTableEdit (see extra s).
Please use an IDE to write code, it will save you from silly mistakes.
Thanks for spotting that. I was pretty sure everything matched the example, however now it now compiles but throws an error when opening the browse screen. IDE is not throwing any errors.
Error: IllegalArgumentException: Can not set com.haulmont.cuba.gui.components.actions.EditAction field com.company.kellygroupapp.web.listing.ListingBrowse.ListingsTableCloseListing to com.haulmont.cuba.gui.xml.DeclarativeAction
Browse Controller
package com.company.kellygroupapp.web.listing;
import com.haulmont.cuba.gui.components.AbstractLookup;
//added lines of code [start]
//
import com.haulmont.cuba.gui.components.actions.EditAction;
import java.util.Map;
import javax.inject.Named;
//
//added lines of code [end]
public class ListingBrowse extends AbstractLookup {
//added from forum example [start]
@Named("listingsTable.closeListing")
private EditAction ListingsTableCloseListing;
@Override
public void init(Map<String, Object> params) {
ListingsTableCloseListing.setWindowId("kellygroupapp$Listing.edit_close");
}
//added from forum example [end]
}
The problem is that there is only a generic ‘action’ XML element and the framework deduce the standard action type by the action’s id (‘edit’ for EditAction). So when you name it differently (to provide id uniqueness), the framework creates a generic action that cannot be used as an edit action.
The workaround is to create the second EditAction programmatically. For example, having the following table:
One question. This only seems to work if I use the GUI module as opposed to the WEB module.
If I use the WEB module clicking the “edit 1” button returns an error.
Is that because this is only possible with the GUI module, or would there be some different code required to accomplish this with the WEB module?
The only difference seems to be which package I call.
Thanks again, I was spinning my wheels on how to achieve this.
package com.company.kellygroupapp.gui.listing;
import com.company.kellygroupapp.entity.Listing;
import com.haulmont.cuba.gui.components.AbstractLookup;
//added imports
import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.components.Table;
import com.haulmont.cuba.gui.components.actions.EditAction;
import javax.inject.Inject;
import java.util.Map;
//end added imports
public class ListingBrowse extends AbstractLookup {
//code from forum
@Inject
private Table < Listing > listingsTable;
@Override
public void init(Map < String, Object > params) {
EditAction editAction1 = new EditAction(listingsTable, WindowManager.OpenType.DIALOG, "edit_1");
editAction1.setWindowId("kellygroupapp$Listing.edit_1");
editAction1.setCaption("Edit 1");
listingsTable.addAction(editAction1);
}
//end code from forum
}