List of usage examples for org.apache.wicket.markup.repeater RepeatingView setEscapeModelStrings
public final Component setEscapeModelStrings(final boolean escapeMarkup)
From source file:org.sakaiproject.sitestats.tool.wicket.pages.ReportsEditPage.java
License:Educational Community License
@SuppressWarnings("serial") private void renderWhoUI(Form form) { List<String> groups = getGroups(); final RepeatingView selectOptionsRV = new RepeatingView("selectOptionsRV"); final Select whoUserIds = new MultipleSelect("reportParams.whoUserIds"); // who //w w w .j a v a2 s.c o m List<String> whoOptions = new ArrayList<String>(); whoOptions.add(ReportManager.WHO_ALL); whoOptions.add(ReportManager.WHO_ROLE); whoOptions.add(ReportManager.WHO_CUSTOM); whoOptions.add(ReportManager.WHO_NONE); if (groups.size() > 0) { whoOptions.add(2, ReportManager.WHO_GROUPS); } IChoiceRenderer whoChoiceRenderer = new IChoiceRenderer() { public Object getDisplayValue(Object object) { if (ReportManager.WHO_ALL.equals(object)) { return new ResourceModel("report_who_all").getObject(); } if (ReportManager.WHO_ROLE.equals(object)) { return new ResourceModel("report_who_role").getObject(); } if (ReportManager.WHO_GROUPS.equals(object)) { return new ResourceModel("report_who_group").getObject(); } if (ReportManager.WHO_CUSTOM.equals(object)) { return new ResourceModel("report_who_custom").getObject(); } if (ReportManager.WHO_NONE.equals(object)) { return new ResourceModel("report_who_none").getObject(); } return object; } public String getIdValue(Object object, int index) { return (String) object; } }; final IndicatingAjaxDropDownChoice who = new IndicatingAjaxDropDownChoice("reportParams.who", whoOptions, whoChoiceRenderer); who.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { if (ReportManager.WHO_CUSTOM.equals(getReportParams().getWho())) { addUsers(selectOptionsRV); whoUserIds.add(new AttributeModifier("style", new Model("width: 300px"))); who.remove(this); whoUserIds.add(new AttributeModifier("onchange", new Model("checkWhoSelection();"))); target.add(who); target.add(whoUserIds); } target.appendJavaScript("checkWhoSelection();"); } @Override public CharSequence getCallbackScript() { CharSequence ajaxScript = super.getCallbackScript(); StringBuilder b = new StringBuilder(); b.append("checkWhoSelection();"); b.append("if(jQuery('#who').val() == 'who-custom') {;"); b.append(ajaxScript); b.append("}"); return b.toString(); } }); who.setMarkupId("who"); who.setOutputMarkupId(true); form.add(who); // users selectOptionsRV.setRenderBodyOnly(true); selectOptionsRV.setEscapeModelStrings(true); whoUserIds.add(selectOptionsRV); whoUserIds.add(new AttributeModifier("title", new ResourceModel("report_multiple_sel_instruction"))); whoUserIds.setOutputMarkupId(true); whoUserIds.setOutputMarkupPlaceholderTag(true); whoUserIds.setEscapeModelStrings(true); form.add(whoUserIds); boolean preloadData = ReportManager.WHO_CUSTOM.equals(getReportParams().getWho()); if (preloadData) { addUsers(selectOptionsRV); } // roles List<String> roles = getRoles(); IChoiceRenderer rolesRenderer = new IChoiceRenderer() { public Object getDisplayValue(Object object) { return (String) object; } public String getIdValue(Object object, int index) { return (String) object; } }; Collections.sort(roles, getChoiceRendererComparator(collator, rolesRenderer)); DropDownChoice whoRoleId = new DropDownChoice("reportParams.whoRoleId", roles, rolesRenderer); whoRoleId.setEnabled(roles.size() > 0); if (getReportParams().getWhoRoleId() == null) { if (roles.size() > 0) { getReportParams().setWhoRoleId(roles.get(0)); } else { getReportParams().setWhoRoleId(""); } } form.add(whoRoleId); // groups WebMarkupContainer whoGroupTr = new WebMarkupContainer("who-groups-tr"); form.add(whoGroupTr); IChoiceRenderer groupsRenderer = new IChoiceRenderer() { public Object getDisplayValue(Object object) { try { return Locator.getFacade().getSiteService().getSite(siteId).getGroup((String) object) .getTitle(); } catch (IdUnusedException e) { return (String) object; } } public String getIdValue(Object object, int index) { return (String) object; } }; Collections.sort(groups, getChoiceRendererComparator(collator, groupsRenderer)); DropDownChoice whoGroupId = new DropDownChoice("reportParams.whoGroupId", groups, groupsRenderer); if (groups.size() == 0) { whoGroupTr.setVisible(false); } else { if (getReportParams().getWhoGroupId() == null) { if (groups.size() > 0) { getReportParams().setWhoGroupId(groups.get(0)); } else { getReportParams().setWhoGroupId(""); } } } whoGroupTr.add(whoGroupId); }