2

最終ユーザーが独自のフォームを作成して(チェックボックス、inputTextsなどをドロップ)そのフォームを保存できるようにするアプリケーションを実行する必要があります。その後、ユーザーはフォームを開いてフォームの要素に値を書き込み、フォームを印刷できます。私はicefacesで作業していて、マネージドBeanで何かをしていました。

javax.faces.component.UIViewRoot root = FacesContext.getCurrentInstance().getViewRoot();
            // find the form with its clientId.
            UIComponent a = root.findComponent("a");
            UIComponent b = a.findComponent("form");
            UIComponent form = b.findComponent("formulario");
            List children = form.getChildren();

if (tipo.equalsIgnoreCase("text")) {
                HtmlInputText inputText = new HtmlInputText();
                inputText.setId("text" + nro + (indice + 1));
                indice++;
                inputText.setValue("");
                inputText.setSize(tamanio);
                children.add(inputText);
                elemento = new Elemento(tipo, inputText.getId(), inputText.getValue().toString(), inputText.getSize());
            } else if (tipo.equalsIgnoreCase("textarea")) {
                HtmlInputTextarea inputTextArea = new HtmlInputTextarea();
                inputTextArea.setId("textarea" + nro + (indice + 1));
                indice++;
                inputTextArea.setValue("");
                inputTextArea.setCols(ancho);
                inputTextArea.setRows(alto);
                children.add(inputTextArea);
                elemento = new Elemento(tipo, inputTextArea.getId(), inputTextArea.getValue().toString(), (inputTextArea.getRows() * 10) + inputTextArea.getCols());
            } else if (tipo.equalsIgnoreCase("outputText")) {
                HtmlOutputText outputText = new HtmlOutputText();
                outputText.setId("outputText" + nro + (indice + 1));
                indice++;
                outputText.setValue(valor);
                children.add(outputText);
                elemento = new Elemento(tipo, outputText.getId(), outputText.getValue().toString(), 0);
            } else if (tipo.equalsIgnoreCase("table")) {
                HtmlDataTable table = new HtmlDataTable();
                table.setId("table" + nro + (indice + 1));
                indice++;
                // for (int k = 0; k < filas; k++) {
                for (int j = 0; j < columnas; j++) {
                    HtmlColumn column = new HtmlColumn();
                    column.setId("c" + j);
                    for (int i = 0; i < filas; i++) {
                        HtmlInputText inputColumn = new HtmlInputText();
                        inputColumn.setId("f" + i);
                        inputColumn.setValue("");
                        column.getChildren().add(inputColumn);
                    }
                    table.getChildren().add(column);
                }
                // }

                table.setValue("");
                table.setRows(filas);
                table.setColNumber(columnas);
                table.setResizable(true);
                children.add(table);
                elemento = new Elemento(tipo, table.getId(), table.getValue().toString(), (table.getRows() * 10 + table.getColNumber()));
            } else if (tipo.equalsIgnoreCase("checkbox")) {
                HtmlSelectBooleanCheckbox checkbox = new HtmlSelectBooleanCheckbox();
                checkbox.setId("checkbox" + nro + (indice + 1));
                indice++;
                checkbox.setValue("ON");
                children.add(checkbox);
                elemento = new Elemento(tipo, checkbox.getId(), checkbox.getValue().toString(), 0);
            } else if (tipo.equalsIgnoreCase("radio")) {
                HtmlSelectOneRadio radio = new HtmlSelectOneRadio();
                radio.setId("radio" + nro + (indice + 1));
                indice++;
                UISelectItems items = new UISelectItems();
                ArrayList arr = new ArrayList();
                HtmlInputText inputRadio = new HtmlInputText();
                inputRadio.setValue(" ");
                arr.add(new SelectItem(new Integer(0), inputRadio.getValue().toString()));
                items.setValue(arr);
                radio.setValue("ON");
                radio.getChildren().add(items);
                children.add(radio);
                elemento = new Elemento(tipo, radio.getId(), radio.getValue().toString(), 0);
            } else if (tipo.equalsIgnoreCase("panel")) {
                HtmlPanelGrid panel = new HtmlPanelGrid();
                panel.setId("panel" + nro + (indice + 1));
                indice++;
                children.add(panel);
                elemento = new Elemento(tipo, panel.getId(), "", 0);
            }
            elementosFormulario.add(elemento);

フォームに要素を追加してからDBに保存してからフォームを再作成できますが、すべての要素から送信された値を取得する方法がわかりません。

4

1 に答える 1

2

Map<String, Object>値をプロパティにバインドします。

例えば

private Map<String, Object> values = new HashMap<String, Object>(); // +getter

inputText.setValueExpression("value", createValueExpression("#{bean.values['" + field.getName() + "']}", String.class));

その後、 によってアクション メソッドで送信された値を取得できますvalues.get(field.getName())

以下も参照してください。

于 2011-02-18T15:49:19.940 に答える