I have a use case where a modal dialog has three set of Addresses of checkbox (Address A, Address B, Other Address) divided in separate divs for each address type for the user to select one address.
Each address type has their own set of TextFields for showing Name, House no, Street, City, Postal code and country.
So far so good. I was able to handle the selection of Address and pass the textfield values to the model. The model is getting reflected with the selected address.
On click of the "OK" button of Modal Window, (AjaxLink), there is a sub-panel (under another main panel, having all the address readonly textfields in it) which has to display the selected address type. But it isnt getting refresh. But the textfields model is having the updated values. (I have found this during debug)
Have tried everything on this site: - using LoadableDetachableModel, setDefaultModel(), creating new instance of the Panel etc. but nothing is of use
i have also pasted the relevant code parts here. Request anyone who can guide me here as to what is going wrong and where I need to correct to get the sub-panel text fields refreshed on click of "OK' button of the modal.
thanks in advance
--ShipmentAddressSelectedPanel constructor Code
public ShipmentAddressSelectedPanel(String id, IModel<OrderDTO> orderDTOIModel) {
super(id, orderDTOIModel);
name = orderDTOIModel.getObject().getDeliveryAddress().getName();
streetAddress = subOrderDTOIModel.getObject().getDeliveryAddress().getStreet();
floor = orderDTOIModel.getObject().getDeliveryAddress().getFloor();
postalNumber = orderDTOIModel.getObject().getDeliveryAddress().getZipCode();
city = orderDTOIModel.getObject().getDeliveryAddress().getCity();
add(new TextField<>("name", new LoadableDetachableModel<String>() {
@Override
protected String load() {
return "" + name;
}
}));
add(new TextField<>("streetAddress", new LoadableDetachableModel<String>() {
@Override
protected String load() {
return "" + streetAddress;
}
}));
add(new TextField<>("floor", new LoadableDetachableModel<String>() {
@Override
protected String load() {
return "" + floor;
}
}));
//floor
add(new TextField<>("postalNumber", new LoadableDetachableModel<String>() {
@Override
protected String load() {
return "" + postalNumber;
}
}));
//postalNumber
add(new TextField<>("city", new LoadableDetachableModel<String>() {
@Override
protected String load() {
return "" + city;
}
}));
}
--code of onClick of AjaxLink ("Ok") button
add(new AjaxLink("saveAddress") {
@Override
public void onClick(final AjaxRequestTarget target) {
if (addressA.getValue().equals("true"))
{
onSaveAddress(target, getShipmentAddressModelFromDeliveryAddress(addressAModel.getObject()));
}
--Code of onSaveAddress where the logic refresh Panel is called from the main panel
@Override
public void onSaveAddress(AjaxRequestTarget target, ShipmentAddressModel shipmentAddressModel) {
ShipmentAddressSelectedPanel newShipmentAddressSelectedPanel = new ShipmentAddressSelectedPanel("showShipmentAddressSelected", orderDTOIModel);
newShipmentAddressSelectedPanel.setOutputMarkupId(true);
//newShipmentAddressSelectedPanel.setDefaultModelObject(orderDTOIModel);
target.add(newShipmentAddressSelectedPanel);
showAddressModal.close(target);
}
You're creating a new ShipmentAddressSelectedPanel, but it doesn't get added to the component tree. Note that AjaxRequestTarget skips components, which are not inside the current page. You should have a log entry:
"Component .. with markupid: .. not rendered because it was already removed from page"
Note your usage of LDM is wrong, it should be:
//name = orderDTOIModel.getObject().getDeliveryAddress().getName();
add(new TextField<>("name", new LoadableDetachableModel<String>() {
@Override
protected String load() {
return orderDTOIModel.getObject().getDeliveryAddress().getName();
}
}));
Otherwise you'll pull out the name once only and never update when the model has changed.