Hi
I noticed a significant improvement in Template in 6.4RC1 compared to RC. I am now trying to use some power of this new functionality.
I have started designing a template by copying from existing one. Seems like you have used markup language but I’m not sure as I am not a frequent user of that. I have some questions and need help to improve the template.
- Noticed that the template is located inside the project, can this be moved to a common place where the Studio can reuse it for any project?
- How can migrate the template from one version to new version, do I need to copy manually?
I have few more questions regarding coding of the template, focusing the controller.
3. How can I get the composite entity name
4. how can i get the field name of the composite entity
Question focusing the screen XML:
5. How can i use specific component e.g. use CssLayout for individual fields instead of one fieldGroup and set the Datasource properties to those fields? The objective is to make it Responsive (knowing we have to using CSS in theme)
Thank you .
Here is copy of the template. I also have attached the test project and feel free to use it for illustration if you want.
<%
if (copyright) {
println '/*'
println " * ${copyright.replace('\n', '\n * ')}"
println ' */'
} else {
print ""
}
%>package ${packageName};
import com.haulmont.cuba.gui.components.AbstractEditor;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.gui.components.Table;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.LookupPickerField;
import ${entity.fqn};
import javax.inject.Inject;
import javax.inject.Named;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
<%if (classComment) {%>
${classComment}<%}%>
public class ${controllerName} extends AbstractEditor<${entity.className}> {
@Inject
private Metadata metadata;
@Inject
private Table<${entity.className}> ${entity.className};
@Inject
private ComponentsFactory componentsFactory;
@Override
public void init(Map<String, Object> params) {
initComboColums();
initTableColumnListeners();
}
@Override
protected void initNewItem(${entity.className} item) {
item.setStatus(OrderStatus.NEW);
Date date = new Date();
item.setDocDate(date);
}
public void onAdd(Component source) {
SalesOrderLine line = metadata.create(SalesOrderLine.class);
line.set${entity.className}(salesOrderDs.getItem());
salesOrderLinesDs.addItem(line);
//creating lineNumber
int max = 0;
Integer lastNum = salesOrderLinesDs.getItems().stream()
.map(SalesOrderLine::getEntryNumber)
.max(Integer::compareTo)
.orElse(0);
line.setEntryNumber(lastNum+1);
salesOrderLineDs.addItem(line);
// set focus on the first cell of the added row
salesOrderLineTable.scrollTo(line);
// set focus on the first cell of the added row
salesOrderLineTable.setSelected(line);
salesOrderLineTable.requestFocus(line, "product");
}
public void onRemove(Component source) {
if (salesOrderLinesDs.getItem() != null) {
salesOrderLinesDs.removeItem(salesOrderLinesDs.getItem());
}
}
public void onSave() {
if (validateAll()) {
getDsContext().commit();
showNotification(getMessage("changesSaved"), NotificationType.HUMANIZED);
}
}
private void initComboColums() {
salesOrderLineTable.addGeneratedColumn("product", client -> {
LookupPickerField field = componentsFactory.createComponent(LookupPickerField.class);
field.setWidth("100%");
field.setOptionsDatasource(productsDs);
field.setDatasource(salesOrderLineTable.getItemDatasource(client), "product");
field.addLookupAction();
return field;
});
}
private void initTableColumnListeners(){
salesOrderLineDs.addItemPropertyChangeListener(e -> {
if ("product".equals(e.getProperty())) {
}
}
}
}
testtemplate.zip (69.8K)