Hi Guys,
I have a metaproperty that will return the calculated manhours.
Do you have any idea how to update fieldgroup property for manhours?
Thank you.
Hi Guys,
I have a metaproperty that will return the calculated manhours.
Do you have any idea how to update fieldgroup property for manhours?
Thank you.
Hello, @Earl02
Do you mean how to use a result of the getCalcmanhrs()
method in FieldGroup?
Regards,
Daniil.
HI @tsarev,
I want to persist the result of getCalcmanhrs either to the datasource manhrs field or on the fieldgroup manhrs. But i have no idea how to do it. Do you have any idea? Can you share it
It seems that you just should make the calcmanhrs
field not transient and use it in FieldGroup.
Hi @tsarev,
I already have a manhrs field for it. So i need the result of calcmanhrs to be pass on manhrs field.
I’ve realized what you want to do and here is a solution.
First of all, you don’t need your transient calcmanhrs
field.
The only thing you should do to solve your problem is to add ValueChangeListener
's for the startTime
and endTime
fields in entity editor screen, calculate a value and update the manhrs
field:
@Named("fieldGroup.startTime")
private TextField startTimeField;
@Named("fieldGroup.endTime")
private TextField endTimeField;
@Override
public void ready() {
startTimeField.addValueChangeListener(this::updateManHours);
endTimeField.addValueChangeListener(this::updateManHours);
}
// method parameter is added to be able to use this method as ValueChangeListeners for the time fields
private void updateManHours(ValueChangeEvent ignored) {
if (startTimeField.getValue() == null || endTimeField.getValue() == null) {
return;
}
Double startTime = startTimeField.getValue();
Double endTime = endTimeField.getValue();
getItem().setManHours(endTime - startTime);
}
Here is a small demo project for your case:
manhours.zip (74.9 KB)
Regards,
Daniil.
You should use the @MetaPropety
annotation when you want to declare that some transient field or method should be included into entity metadata to use it later, for example, in FieldGroup
or Table
.
I tried to follow your code but it shows compile error. It shows “Unable to find the symbol TimeField”. I think I miss importing a package for “TimeField”. Could you share the name of the package? Thank you.
Hi,
Thank you. This works well but my case is a little bit different.
Well in your case you should get the time from your timestamp & put it into another variable for you to be able manipulate it.
Hi,
I tried to get the start date , start time , end date and end time like below but it shows error.
IllegalArgumentException: Can not set com.haulmont.cuba.gui.components.TimeField field com.tupperware.wocompletion.web.ccswo.CcsWoEdit.endTimeField to com.haulmont.cuba.web.gui.components.WebDateField
@Named("fieldGroup.begintime")
private TimeField startTimeField;
@Named("fieldGroup.endtime")
private TimeField endTimeField;
@Named("fieldGroup.begintime")
private DateField startDateField;
@Named("fieldGroup.endtime")
private DateField endDateField;