Search in sources :

Example 1 with Form

use of org.santfeliu.form.Form in project gdmatrix by gdmatrix.

the class HtmlFormRenderer method decode.

@Override
public void decode(FacesContext context, UIComponent component) {
    DynamicForm dynamicForm = (DynamicForm) component;
    Form form = dynamicForm.getForm();
    if (form == null)
        return;
    Map<String, String[]> submittedData = new HashMap<>();
    dynamicForm.setSubmittedValue(submittedData);
    Map parameters = context.getExternalContext().getRequestParameterValuesMap();
    String clientId = component.getClientId(context);
    for (Field field : form.getFields()) {
        String name = field.getReference();
        String[] stringValues = (String[]) parameters.get(getFieldId(clientId, name));
        View view = form.getView(name);
        if (view != null && View.BUTTON.equals(view.getViewType())) {
            submittedData.put(name, stringValues);
            if (stringValues != null) {
                // button pressed
                ActionEvent event = new ActionEvent(component);
                event.setPhaseId(PhaseId.INVOKE_APPLICATION);
                component.queueEvent(event);
            }
        } else if (stringValues != null) {
            submittedData.put(name, stringValues);
        }
    // else if (Field.BOOLEAN.equals(field.getType()))
    // {
    // // special case: checkboxes don't send fieldValue when not checked.
    // // put 'false' fieldValue in this case
    // if (stringValues == null) submittedData.put(name, new String[]{"false"});
    // }
    }
    // All submitted values are String[], conversion takes place in next phase
    System.out.println("\nSUBMITTED DATA================================== ");
    printMap(submittedData);
}
Also used : Field(org.santfeliu.form.Field) Form(org.santfeliu.form.Form) DynamicForm(org.santfeliu.faces.dynamicform.DynamicForm) HtmlForm(org.santfeliu.form.type.html.HtmlForm) HashMap(java.util.HashMap) ActionEvent(javax.faces.event.ActionEvent) DynamicForm(org.santfeliu.faces.dynamicform.DynamicForm) HashMap(java.util.HashMap) Map(java.util.Map) HtmlView(org.santfeliu.form.type.html.HtmlView) View(org.santfeliu.form.View)

Example 2 with Form

use of org.santfeliu.form.Form in project gdmatrix by gdmatrix.

the class URLFormBuilder method getForm.

public Form getForm(String selector) {
    Form form = null;
    URL url = getURL(selector);
    if (url != null) {
        Class formClass = getFormClass(url.getFile());
        if (formClass == null) {
            try {
                URLConnection conn = url.openConnection();
                String contentType = conn.getContentType();
                if (contentType.indexOf("html") != -1) {
                    formClass = HtmlForm.class;
                }
            } catch (Exception ex) {
            }
        }
        if (formClass != null) {
            try {
                form = (Form) formClass.newInstance();
                form.read(url.openStream());
                setup(form);
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    }
    return form;
}
Also used : Form(org.santfeliu.form.Form) HtmlForm(org.santfeliu.form.type.html.HtmlForm) URL(java.net.URL) URLConnection(java.net.URLConnection) MalformedURLException(java.net.MalformedURLException)

Example 3 with Form

use of org.santfeliu.form.Form in project gdmatrix by gdmatrix.

the class FormTestBean method getFormEntryClass.

public String getFormEntryClass() {
    FormFactory.Entry entry = (FormFactory.Entry) getValue("#{row}");
    Form form = entry.getForm();
    return form.getClass().getName();
}
Also used : Form(org.santfeliu.form.Form) FormFactory(org.santfeliu.form.FormFactory)

Example 4 with Form

use of org.santfeliu.form.Form in project gdmatrix by gdmatrix.

the class FormTestBean method getFormFields.

public List getFormFields() {
    Form form = getForm();
    if (form == null)
        return Collections.EMPTY_LIST;
    List list = new ArrayList();
    list.addAll(form.getFields());
    return list;
}
Also used : Form(org.santfeliu.form.Form) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with Form

use of org.santfeliu.form.Form in project gdmatrix by gdmatrix.

the class PathFormBuilder method getForm.

public Form getForm(String selector) {
    Form form = null;
    File file = getFile(selector);
    if (file != null && file.isFile()) {
        Class formClass = getFormClass(file.getName());
        if (formClass != null) {
            try {
                form = (Form) formClass.newInstance();
                form.read(new FileInputStream(file));
                setup(form);
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    }
    return form;
}
Also used : Form(org.santfeliu.form.Form) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

Form (org.santfeliu.form.Form)14 Map (java.util.Map)7 HashMap (java.util.HashMap)5 HtmlForm (org.santfeliu.form.type.html.HtmlForm)5 DynamicForm (org.santfeliu.faces.dynamicform.DynamicForm)4 ArrayList (java.util.ArrayList)3 Field (org.santfeliu.form.Field)3 FormFactory (org.santfeliu.form.FormFactory)3 List (java.util.List)2 HtmlView (org.santfeliu.form.type.html.HtmlView)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 Locale (java.util.Locale)1 ValueExpression (javax.el.ValueExpression)1