fragment如何主动传值给父页面,父页面被动接收做逻辑,像Listener一样
看了英文论坛,使用这种方法实现了
Fragment
public Subscription addChangeListener(Consumer<FragmentChangeEvent> listener) {
return getEventHub().subscribe(FragmentChangeEvent.class, listener);
}
public static class FragmentChangeEvent extends EventObject {
private BusinessHoursDTO businessHoursDTO;
/**
* Constructs a prototypical Event.
*
* @param source the object on which the Event initially occurred
* @throws IllegalArgumentException if source is null
*/
public FragmentChangeEvent(Object source, BusinessHoursDTO businessHoursDTO) {
super(source);
this.businessHoursDTO = businessHoursDTO;
}
public BusinessHoursDTO getBusinessHoursDTO() {
return businessHoursDTO;
}
}
@Subscribe("businessHour")
public void onBusinessHourValueChange(final HasValue.ValueChangeEvent event) {
fireEvent(FragmentChangeEvent.class, new FragmentChangeEvent(this, businessHoursDTO));
}
父页面
@Subscribe(id = "businesshoursFragment", target = Target.CONTROLLER)
protected void onBusinessHourValueChange(BusinessHoursFragment.FragmentChangeEvent event) {
// 营业时间组件值变更
// getEditedEntity().setFdBussinessTimeType();
BusinessHoursDTO businessHoursDTO = event.getBusinessHoursDTO();
getEditedEntity().setFdBusinesshours(businessHoursDTO.getBusinessTimeType().getId());
getEditedEntity().setFdBusinesshours(businessHoursDTO.getValue());
}
您这个全局事件功能,我后面学习下。
这样写之后发现,hotdeploy无效了。
每次都要重启才行,大佬帮看一下是不是个BUG?