Skip to content

Commit

Permalink
1) fix for ListView models on the search panel (500 errors occurred d…
Browse files Browse the repository at this point in the history
…ue to incorrect ListView model initialization)

from javadoc for ListView.getListItemModel:
The default ListItemModel works fine with mostly static lists where index remains valid. In cases where the underlying list changes a lot (many users using the application), it may not longer be appropriate. In that case your own ListItemModel implementation should use an id (e.g. the database' record id) to identify and load the list item model object.
2) removed search autorefresh after some search item values change (e.g. indirect, scope)
3) fix for type change on the members panel
4) object reference search item npe fix
  • Loading branch information
KaterynaHonchar committed Oct 20, 2022
1 parent 4c96aac commit f826094
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* Popupable panel with listed items which can be searched and selected
* The component can be used as More button popup or saved searches popup on search panel
*/
public abstract class SelectableItemListPopoverPanel<T> extends BasePanel<List<T>> {
public abstract class SelectableItemListPopoverPanel<T extends AbstractSearchItemWrapper> extends BasePanel<List<T>> {

private static final long serialVersionUID = 1L;
private static final String ID_POPOVER = "popover";
Expand Down Expand Up @@ -157,7 +157,7 @@ public String getDataPlacement() {
help.add(new VisibleBehaviour(() -> StringUtils.isNotEmpty(helpText)));
item.add(help);

item.add(new VisibleBehaviour(() -> isPropertyItemVisible(getItemName(item.getModelObject()), searchTextModel.getObject())));
item.add(new VisibleBehaviour(() -> !item.getModelObject().isVisible() && isPropertyItemVisible(getItemName(item.getModelObject()), searchTextModel.getObject())));
}

private boolean isPropertyItemVisible(String itemName, String propertySearchText) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ public Object getDisplayValue(Boolean val) {
}
}, false);
inputPanel.getBaseFormComponent().add(new EnableBehaviour(() -> getModelObject().getSearchConfig().isSearchScope(SearchBoxScopeType.SUBTREE)));
inputPanel.getBaseFormComponent().add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;

@Override
protected void onUpdate(AjaxRequestTarget target) {
searchPerformed(target);
}
});
return inputPanel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ protected Component initSearchItemField() {
DropDownChoicePanel inputPanel = new DropDownChoicePanel(ID_SEARCH_ITEM_FIELD,
new PropertyModel(getModel(), ScopeSearchItemWrapper.F_SEARCH_CONFIG + "." + SearchConfigurationWrapper.F_SCOPE),
Model.of(Arrays.asList(SearchBoxScopeType.values())), new EnumChoiceRenderer(), false);
inputPanel.getBaseFormComponent().add(new OnChangeAjaxBehavior() {

private static final long serialVersionUID = 1L;

@Override
protected void onUpdate(AjaxRequestTarget target) {
SearchPanel panel = findParent(SearchPanel.class);
panel.searchPerformed(target);
}
});
// inputPanel.getBaseFormComponent().add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
// inputPanel.getBaseFormComponent().add(AttributeAppender.append("style", "width: 88px; max-width: 400px !important;"));
inputPanel.setOutputMarkupId(true);
return inputPanel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public abstract class SearchPanel<C extends Containerable> extends BasePanel<Sea
private static final String ID_FULL_TEXT_FIELD = "fullTextField";
private static final String ID_OID_ITEM = "oidItem";

private LoadableModel<List<AbstractSearchItemWrapper>> basicSearchItemsModel;
private LoadableModel<List<AbstractSearchItemWrapper>> morePopupModel;
private LoadableDetachableModel<List<AbstractSearchItemWrapper>> basicSearchItemsModel;
private LoadableDetachableModel<List<AbstractSearchItemWrapper>> morePopupModel;
private LoadableDetachableModel<List<InlineMenuItem>> savedSearchListModel;
private static final Trace LOG = TraceManager.getTrace(SearchPanel.class);

Expand All @@ -142,30 +142,29 @@ protected void onInitialize() {
}

private void initBasicSearchItemsModel() {
basicSearchItemsModel = new LoadableModel<List<AbstractSearchItemWrapper>>(true) {
basicSearchItemsModel = new LoadableDetachableModel<List<AbstractSearchItemWrapper>>() {
private static final long serialVersionUID = 1L;
@Override
protected List<AbstractSearchItemWrapper> load() {
return getModelObject().getItems().stream().filter(item
-> !(item instanceof OidSearchItemWrapper) && item.isVisible())
return getModelObject().getItems()
.stream().filter(item
-> !(item instanceof OidSearchItemWrapper))
.collect(Collectors.toList());
}
};
}

private void initMorePopupModel() {
morePopupModel = new LoadableModel<List<AbstractSearchItemWrapper>>() {
morePopupModel = new LoadableDetachableModel<List<AbstractSearchItemWrapper>>() {
@Override
protected List<AbstractSearchItemWrapper> load() {
return getModelObject().getItems().stream().filter(item
-> !item.isVisible())
.collect(Collectors.toList());
return getModelObject().getItems();
}
};
}

public void displayedSearchItemsModelReset() {
basicSearchItemsModel.reset();
basicSearchItemsModel.detach();
}

private <S extends AbstractSearchItemWrapper, T extends Serializable> void initLayout() {
Expand Down Expand Up @@ -608,7 +607,7 @@ private void addItemPerformed(List<AbstractSearchItemWrapper> itemList, AjaxRequ

void refreshSearchForm(AjaxRequestTarget target) {
displayedSearchItemsModelReset();
morePopupModel.reset();
morePopupModel.detach();
target.add(get(ID_FORM));
saveSearch(getModelObject(), target);
}
Expand Down Expand Up @@ -794,6 +793,7 @@ private <T extends Serializable> void initBasicSearchLayout() {
@Override
protected void populateItem(ListItem<AbstractSearchItemWrapper> item) {
AbstractSearchItemPanel searchItemPanel = createSearchItemPanel(ID_ITEM, item.getModel());
searchItemPanel.add(new VisibleBehaviour(() -> item.getModelObject().isVisible()));
item.add(searchItemPanel);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,11 @@ private <AH extends AssignmentHolderType> Search<AH> createMemberSearch(Class<AH
return SearchFactory.createMemberPanelSearch(new SearchConfigurationWrapper<>(type, getPageBase()), getPageBase());
}

if (memberPanelStorage.getSearch() != null) {
if (memberPanelStorage.getSearch() != null && type.equals(memberPanelStorage.getSearch().getSearchConfigurationWrapper().getTypeClass())) {
return memberPanelStorage.getSearch();
}

Search<AH> search = SearchFactory.createMemberPanelSearch(createSearchConfigWrapper(getDefaultObjectType()), getPageBase());
Search<AH> search = SearchFactory.createMemberPanelSearch(createSearchConfigWrapper(type), getPageBase());
memberPanelStorage.setSearch(search);
return search;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void updateModel(ObjectReferenceType ref, MidpointForm<?> midpointForm,
if (ref == null) {
return;
}
if (getModelObject().getOid() != null && PolyStringUtils.isEmpty(ref.getTargetName()) && ref.getObject() == null){
if (getModelObject() != null && getModelObject().getOid() != null && PolyStringUtils.isEmpty(ref.getTargetName()) && ref.getObject() == null){
ref.setOid(getModelObject().getOid());
}
if (PolyStringUtils.isEmpty(ref.getTargetName())) {
Expand Down

0 comments on commit f826094

Please sign in to comment.