public void createRegJS( EditorComponent editor, String editorId, UIForm form, FacesContext context, Schema schema, StringBuffer regJS) throws IOException { regJS.append("new RecordEditorDropdowns("); regJS.append("'").append(getName()).append("'"); regJS.append(", ["); for (int i = 0; i < listIds.length; i++) { if (i > 0) regJS.append(", "); regJS .append("'") .append(FieldValueDropdowns.getHtmlSelectName(editor, context, getName(), i)) .append("'"); } regJS.append("], ["); for (int i = 0; i < listIds.length; i++) { if (i > 0) regJS.append(", "); regJS.append("'").append(listIds[i]).append("'"); } regJS.append("])"); }
public void encode( EditorComponent editor, String editorId, UIForm form, FacesContext context, Schema schema, FieldValue value) throws IOException { // type check if (!(value instanceof FieldValueDropdowns)) throw new RuntimeException("FieldSchemaDropdowns expected FieldValueDropdowns"); // cast FieldValueDropdowns valueDropdowns = (FieldValueDropdowns) value; // get writer ResponseWriter writer = context.getResponseWriter(); // number of lists int listCount = listIds != null ? listIds.length : 0; // hidden field with the number of lists String countFieldName = FieldValueDropdowns.getHtmlCountHiddenFieldName(editor, context, getName()); JsfUtils.encodeHiddenInput(editor, writer, countFieldName, String.valueOf(listCount)); // selects String parentValue = null; for (int i = 0; i < listCount; i++) { String selectName = FieldValueDropdowns.getHtmlSelectName(editor, context, getName(), i); ListItem[] list = schema.getListById(listIds[i]); String selectedValue = valueDropdowns.getValue(i); String onChange = "RecordEditorGlobals.dropdownValueChanged(" + "'" + editorId + "'," + "'" + getName() + "'," + +i + ")"; writer.startElement("div", editor); writer.startElement("select", editor); writer.writeAttribute("name", selectName, null); writer.writeAttribute("onchange", onChange, null); if (!StringUtils.isNullOrEmpty(cssClass)) writer.writeAttribute("class", cssClass, null); for (int j = 0; j < list.length; j++) { ListItem item = list[j]; if (i == 0 || (item.getParentValue() == null) || (parentValue == null && item.getValue() == null) || (parentValue != null && parentValue.equals(item.getParentValue()))) { writer.startElement("option", editor); if (StringUtils.compareStrings(item.getValue(), selectedValue)) writer.writeAttribute("selected", "selected", null); writer.writeAttribute("value", item.getValue(), null); writer.write(StringUtils.coalesce(item.getText(), "")); writer.endElement("option"); } } writer.endElement("select"); writer.endElement("div"); parentValue = selectedValue; } }