Search in sources :

Example 1 with HtmlSelectOneMenu

use of javax.faces.component.html.HtmlSelectOneMenu in project gdmatrix by gdmatrix.

the class QueryInstanceBean method addParameterComponent.

private void addParameterComponent(Query.Parameter parameter, String expression, HtmlPanelGroup exprPanelGroup) {
    FacesContext context = FacesContext.getCurrentInstance();
    String sql = parameter.getSql();
    if (StringUtils.isBlank(sql)) {
        String format = parameter.getFormat();
        ValueBinding valueBinding;
        if (Query.Parameter.DATE.equals(format)) {
            HtmlCalendar calendar = new HtmlCalendar();
            calendar.setId("input_" + id);
            String expr = "#{queryInstanceBean." + expression + "['" + parameter.getName() + "']}";
            valueBinding = context.getApplication().createValueBinding(expr);
            calendar.setValueBinding("value", valueBinding);
            calendar.setStyleClass("input_value date");
            exprPanelGroup.getChildren().add(calendar);
        } else {
            HtmlInputText inputText = new HtmlInputText();
            inputText.setId("input_" + id);
            String expr = "#{queryInstanceBean." + expression + "['" + parameter.getName() + "']}";
            valueBinding = context.getApplication().createValueBinding(expr);
            inputText.setValueBinding("value", valueBinding);
            inputText.setStyleClass("input_value");
            String title = parameter.getDescription() == null ? parameter.getName() : parameter.getDescription();
            inputText.setTitle(title);
            inputText.setAlt(title);
            inputText.setSize(parameter.getSize());
            if (Query.Parameter.NUMBER.equals(format)) {
                Application application = context.getApplication();
                MethodBinding method = application.createMethodBinding("#{queryInstanceBean.validateNumber}", new Class[] { FacesContext.class, UIComponent.class, Object.class });
                inputText.setValidator(method);
            }
            exprPanelGroup.getChildren().add(inputText);
        }
        Object value = valueBinding.getValue(context);
        if (value == null) {
            String defaultValue = parameter.getDefaultValue();
            if (!StringUtils.isBlank(defaultValue)) {
                valueBinding.setValue(context, String.valueOf(defaultValue));
            }
        }
    } else // selectOneMenu
    {
        HtmlSelectOneMenu selectOneMenu = new HtmlSelectOneMenu();
        selectOneMenu.setId("input_" + id);
        String expr = "#{queryInstanceBean." + expression + "['" + parameter.getName() + "']}";
        ValueBinding valueBinding = context.getApplication().createValueBinding(expr);
        selectOneMenu.setValueBinding("value", valueBinding);
        selectOneMenu.setStyleClass("input_value select");
        id++;
        UISelectItems uiSelectItems = new UISelectItems();
        uiSelectItems.setId("items_" + id);
        expr = "#{queryInstanceBean.parameterSelectItemsMap['" + parameter.getName() + "']}";
        ValueBinding itemsValue = context.getApplication().createValueBinding(expr);
        uiSelectItems.setValueBinding("value", itemsValue);
        selectOneMenu.getChildren().add(uiSelectItems);
        exprPanelGroup.getChildren().add(selectOneMenu);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) UISelectItems(javax.faces.component.UISelectItems) ValueBinding(javax.faces.el.ValueBinding) HtmlInputText(javax.faces.component.html.HtmlInputText) MethodBinding(javax.faces.el.MethodBinding) HtmlSelectOneMenu(javax.faces.component.html.HtmlSelectOneMenu) HtmlCalendar(org.santfeliu.faces.component.jqueryui.HtmlCalendar) Application(javax.faces.application.Application)

Example 2 with HtmlSelectOneMenu

use of javax.faces.component.html.HtmlSelectOneMenu in project gdmatrix by gdmatrix.

the class QueryInstanceBean method addOperatorComponents.

private void addOperatorComponents(Operator operator, HtmlPanelGroup exprPanelGroup) {
    FacesContext context = FacesContext.getCurrentInstance();
    Application application = context.getApplication();
    ValueBinding valueBinding = context.getApplication().createValueBinding("expression #{queryInstanceBean.expressions['" + operator.getId() + "'].type}");
    exprPanelGroup.setValueBinding("styleClass", valueBinding);
    if (operator.getType().equals(Operator.ROOT)) {
        addLabelComponents(selectedInstance.getQuery().getLabel(), "selectedInstance.globalParameterValuesMap", selectedInstance.getQuery().getGlobalParameters(), exprPanelGroup);
    } else // other operators: and, or, nor
    {
        // add operator select box
        id++;
        HtmlSelectOneMenu selectMenu = new HtmlSelectOneMenu();
        selectMenu.setId(operator.getType() + "_" + id);
        selectMenu.setStyleClass("operator");
        selectMenu.setOnchange("submit();");
        String valueExpr = "#{queryInstanceBean.expressions['" + operator.getId() + "'].type}";
        valueBinding = context.getApplication().createValueBinding(valueExpr);
        selectMenu.setValueBinding("value", valueBinding);
        ArrayList list = new ArrayList();
        SelectItem item1 = new SelectItem();
        item1.setDescription(Operator.AND);
        item1.setValue(Operator.AND);
        item1.setLabel(getQueryLabel(Operator.AND));
        list.add(item1);
        SelectItem item2 = new SelectItem();
        item2.setDescription(Operator.OR);
        item2.setValue(Operator.OR);
        item2.setLabel(getQueryLabel(Operator.OR));
        list.add(item2);
        SelectItem item3 = new SelectItem();
        item3.setDescription(Operator.NOR);
        item3.setValue(Operator.NOR);
        item3.setLabel(getQueryLabel(Operator.NOR));
        list.add(item3);
        id++;
        UISelectItems selectItems = new UISelectItems();
        selectItems.setId("si_" + id);
        selectItems.setValue(list);
        selectMenu.getChildren().add(selectItems);
        exprPanelGroup.getChildren().add(selectMenu);
        id++;
        HtmlCommandButton button = new HtmlCommandButton();
        button.setId("button_" + id);
        MethodBinding method = application.createMethodBinding("#{queryInstanceBean.expressionWrappers['" + operator.getId() + "'].removeExpression}", new Class[0]);
        button.setAction(method);
        button.setImage("/common/misc/images/remove_expr.png");
        button.setStyleClass("expr_button remove");
        exprPanelGroup.getChildren().add(button);
    }
    id++;
    HtmlPanelGroup subPanelGroup = new HtmlPanelGroup();
    subPanelGroup.setId("comp_" + id);
    subPanelGroup.setStyleClass("op_children");
    exprPanelGroup.getChildren().add(subPanelGroup);
    for (Expression expr : operator.getArguments()) {
        addExpressionComponents(expr, subPanelGroup);
        if (!operator.getType().equals(Operator.ROOT)) {
            id++;
            HtmlOutputText linkText = new HtmlOutputText();
            linkText.setId("link_" + id);
            valueBinding = application.createValueBinding("#{queryInstanceBean.expressionWrappers['" + operator.getId() + "'].linkLabel}");
            linkText.setValueBinding("value", valueBinding);
            linkText.setStyleClass("operator_link");
            subPanelGroup.getChildren().add(linkText);
        }
    }
    if (operator.equals(selectedExpression)) {
        addExpressionList(context, subPanelGroup);
    } else {
        id++;
        HtmlCommandButton button = new HtmlCommandButton();
        button.setId("button_" + id);
        MethodBinding method = application.createMethodBinding("#{queryInstanceBean.expressionWrappers['" + operator.getId() + "'].selectExpression}", new Class[0]);
        button.setAction(method);
        button.setImage("/common/misc/images/add_expr.png");
        button.setStyleClass("expr_button add");
        ValueBinding value = application.createValueBinding("#{queryInstanceBean.expressionWrappers['" + operator.getId() + "'].addButtonRendered}");
        button.setValueBinding("rendered", value);
        subPanelGroup.getChildren().add(button);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) UISelectItems(javax.faces.component.UISelectItems) ValueBinding(javax.faces.el.ValueBinding) ArrayList(java.util.ArrayList) HtmlSelectOneMenu(javax.faces.component.html.HtmlSelectOneMenu) HtmlCommandButton(javax.faces.component.html.HtmlCommandButton) Expression(org.santfeliu.misc.query.QueryInstance.Expression) SelectItem(javax.faces.model.SelectItem) MethodBinding(javax.faces.el.MethodBinding) HtmlPanelGroup(org.apache.myfaces.component.html.ext.HtmlPanelGroup) HtmlOutputText(javax.faces.component.html.HtmlOutputText) Application(javax.faces.application.Application)

Aggregations

Application (javax.faces.application.Application)2 UISelectItems (javax.faces.component.UISelectItems)2 HtmlSelectOneMenu (javax.faces.component.html.HtmlSelectOneMenu)2 FacesContext (javax.faces.context.FacesContext)2 MethodBinding (javax.faces.el.MethodBinding)2 ValueBinding (javax.faces.el.ValueBinding)2 ArrayList (java.util.ArrayList)1 HtmlCommandButton (javax.faces.component.html.HtmlCommandButton)1 HtmlInputText (javax.faces.component.html.HtmlInputText)1 HtmlOutputText (javax.faces.component.html.HtmlOutputText)1 SelectItem (javax.faces.model.SelectItem)1 HtmlPanelGroup (org.apache.myfaces.component.html.ext.HtmlPanelGroup)1 HtmlCalendar (org.santfeliu.faces.component.jqueryui.HtmlCalendar)1 Expression (org.santfeliu.misc.query.QueryInstance.Expression)1