/** * @return the original String, wrapped in #{...}. If the original String was already wrapped, * returns the original String */ public static String wrapExpression( String value ) { if ( isExpression( value ) ) { return value; } return EXPRESSION_START + unwrapExpression( value ) + EXPRESSION_END; }
/** * Return <code>true</code> if the specified value conforms to the syntax requirements of a * value binding expression. * <p> * This method is a mirror of the one in <code>UIComponentTag.isValueReference</code>, but that * one is deprecated so may be removed in the future. * * @param value * The value to evaluate * @throws NullPointerException * if <code>value</code> is <code>null</code> */ public static boolean isExpression( String value ) { return matchExpression( value ).matches(); }
@Override public void initNestedMetawidget( StaticMetawidget nestedMetawidget, Map<String, String> attributes ) { super.initNestedMetawidget( nestedMetawidget, attributes ); if ( ( (StaticUIMetawidget) nestedMetawidget ).getValue() == null ) { String valueExpression = getValue(); valueExpression = StaticFacesUtils.unwrapExpression( valueExpression ); valueExpression += StringUtils.SEPARATOR_DOT_CHAR + attributes.get( NAME ); valueExpression = StaticFacesUtils.wrapExpression( valueExpression ); ( (StaticUIMetawidget) nestedMetawidget ).setValue( valueExpression ); } } }
super.addColumnComponent(dataTable, tableAttributes, elementName, columnAttributes, metawidget); List<StaticWidget> columns = dataTable.getChildren(); HtmlColumn column = (HtmlColumn) columns.get(columns.size() - 1); HtmlOutcomeTargetLink link = new HtmlOutcomeTargetLink(); String outcome = getTargetDir(); if (!outcome.isEmpty() && !outcome.startsWith("/")) link.putAttribute("outcome", outcome + "/" + controllerName + "/view"); Param param = new Param(); param.putAttribute("name", "id"); param.putAttribute( "value", StaticFacesUtils.wrapExpression(dataTable.getAttribute("var") + StringUtils.SEPARATOR_DOT_CHAR + primaryKeyName)); link.getChildren().add(param); link.getChildren().add(column.getChildren().remove(1)); if (columnAttributes.containsKey(FACES_LOOKUP) && columnAttributes.containsKey(REVERSE_PRIMARY_KEY)) StaticHtmlMetawidget output = (StaticHtmlMetawidget) link.getChildren().get(1); String displayExpression = dataTable.getAttribute("var") + StringUtils.SEPARATOR_DOT_CHAR + StringUtils.decapitalize(columnAttributes.get(NAME)); output.setValue(StaticFacesUtils.wrapExpression(displayExpression)); String valueExpression = dataTable.getAttribute("var") + StringUtils.SEPARATOR_DOT_CHAR + tableAttributes.get(PARAMETERIZED_TYPE_PATH) + StringUtils.SEPARATOR_DOT_CHAR + StringUtils.decapitalize(columnAttributes.get(NAME));
HtmlOutcomeTargetLink link = new HtmlOutcomeTargetLink(); link.putAttribute("outcome", getTargetDir() + "/" + controllerName + "/view"); bindingProcessor.processWidget(link, elementName, attributes, (StaticUIMetawidget) metawidget); Param param = new Param(); param.putAttribute("name", "id"); param.putAttribute( "value", StaticFacesUtils.wrapExpression(StaticFacesUtils.unwrapExpression(link.getValue()) + StringUtils.SEPARATOR_DOT_CHAR + reverseKey)); link.getChildren().add(param); HtmlOutputText outputText = new HtmlOutputText(); StandardBindingProcessor bindingProcessor = metawidget .getWidgetProcessor(StandardBindingProcessor.class); bindingProcessor.processWidget(outputText, elementName, attributes, (StaticUIMetawidget) metawidget); String styleClassEl = StaticFacesUtils.unwrapExpression(outputText.getValue()) + " ? 'boolean-true' : 'boolean-false'"; outputText.putAttribute("styleClass", StaticFacesUtils.wrapExpression(styleClassEl)); outputText.setValue(""); HtmlSelectOneMenu select = new HtmlSelectOneMenu(); addSelectItems( select, facesLookup, attributes ); return select;
StaticXmlWidget dataTable = super.createDataTableComponent(elementName, attributes, metawidget); dataTable.putAttribute("styleClass", "data-table"); bindingProcessor.processWidget(dataTable, elementName, attributes, (StaticUIMetawidget) metawidget); readableIdProcessor.processWidget(dataTable, elementName, attributes, metawidget); String tableValueExpression = valueHolderTable.getValue(); String asListValueExpression = "forgeview:asList(" + StaticFacesUtils.unwrapExpression(tableValueExpression) + ")"; valueHolderTable.setValue(StaticFacesUtils.wrapExpression(asListValueExpression)); ((BaseStaticXmlWidget) dataTable).putAdditionalNamespaceURI("forgeview", "http://jboss.org/forge/view"); HtmlPanelGroup panelGroup = new HtmlPanelGroup(); FaceletsParam param = new FaceletsParam(); param.putAttribute("name", COLLECTION_VAR); param.putAttribute("value", tableValueExpression); panelGroup.getChildren().add(param); valueHolderTable.setValue(StaticFacesUtils.wrapExpression("forgeview:asList(" + COLLECTION_VAR + ")")); valueHolderTable.setValue(StaticFacesUtils.wrapExpression(COLLECTION_VAR)); panelGroup.getChildren().add(dataTable); HtmlPanelGrid panelGrid = new HtmlPanelGrid(); panelGrid.putAttribute("styleClass", "data-table-footer");
super.addColumnComponents(dataTable, attributes, elements, metawidget); if (dataTable.getChildren().isEmpty()) HtmlCommandLink removeLink = new HtmlCommandLink(); removeLink.putAttribute("styleClass", "remove-button"); String removeExpression = COLLECTION_VAR + ".remove(" + dataTable.getAttribute("var") + ")"; removeLink.putAttribute("action", StaticFacesUtils.wrapExpression(removeExpression)); HtmlColumn column = new HtmlColumn(); column.putAttribute("headerClass", "remove-column"); column.putAttribute("footerClass", "remove-column"); column.getChildren().add(removeLink); dataTable.getChildren().add(column); HtmlCommandLink addLink = new HtmlCommandLink(); addLink.putAttribute("styleClass", "add-button"); String addExpression = COLLECTION_VAR + ".add(" + controllerName + "Bean.added)"; addLink.putAttribute("action", StaticFacesUtils.wrapExpression(addExpression)); setPropertyActionListener.putAttribute( "target", StaticFacesUtils.wrapExpression(controllerName + "Bean.add." + inverseRelationship)); StandardBindingProcessor bindingProcessor = metawidget.getWidgetProcessor(StandardBindingProcessor.class); bindingProcessor.processWidget(setPropertyActionListener, ENTITY, attributes, (StaticUIMetawidget) metawidget); addLink.getChildren().add(setPropertyActionListener);
HtmlColumn column = new HtmlColumn(); StaticXmlWidget columnContents; columnContents = new HtmlOutputText(); columnContents.putAttribute( "value", StaticFacesUtils.wrapExpression( dataTable.getAttribute( "var" ) ) ); } else { columnContents = new StaticHtmlMetawidget(); String valueExpression = dataTable.getAttribute( "var" ) + StringUtils.SEPARATOR_DOT_CHAR + StringUtils.decapitalize( columnAttributes.get( NAME ) ); columnContents.putAttribute( "value", StaticFacesUtils.wrapExpression( valueExpression ) ); columnMetawidget.setPath( WidgetBuilderUtils.getComponentType( tableAttributes ) + StringUtils.SEPARATOR_FORWARD_SLASH_CHAR + columnAttributes.get( NAME ) ); metawidget.initNestedMetawidget( columnMetawidget, columnAttributes ); columnMetawidget.setLayout( new SimpleLayout() ); columnMetawidget.setReadOnly( true ); column.getChildren().add( columnContents ); HtmlOutputText headerText = new HtmlOutputText(); headerText.putAttribute( "value", metawidget.getLabelString( columnAttributes ) ); Facet headerFacet = new Facet(); headerFacet.putAttribute( "name", "header" ); headerFacet.getChildren().add( headerText ); column.getChildren().add( 0, headerFacet ); dataTable.getChildren().add( column );
this.entityMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + "." + ccEntity)); this.entityMetawidget.setPath(entity.getQualifiedName()); this.entityMetawidget.setReadOnly(false); this.entityMetawidget.setStyle(null); this.entityMetawidget.setReadOnly(true); writeEntityMetawidget(context, this.viewTemplateEntityMetawidgetIndent, this.viewTemplateNamespaces); this.searchMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".example")); this.searchMetawidget.setPath(entity.getQualifiedName()); this.beanMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".pageItems")); this.beanMetawidget.setPath(viewBean.getQualifiedName() + "/pageItems"); writeSearchAndBeanMetawidget(context, this.searchTemplateSearchMetawidgetIndent, this.searchTemplateBeanMetawidgetIndent, this.searchTemplateNamespaces);
/** * Overrriden to enhance the default f:selectItem widget with more suitable item labels */ @Override protected void addSelectItems(HtmlSelectOneMenu select, String valueExpression, Map<String, String> attributes) { // Empty option // // Note: a 'null' value (rather than an empty String') renders an <f:selectItem/> rather // than an <f:selectItem itemValue=""/>. This works out better if the HtmlSelectOneMenu has // a converter, because the empty String may not be a compatible value if (WidgetBuilderUtils.needsEmptyLookupItem(attributes)) { addSelectItem(select, null, null); } // Add the select items SelectItems selectItems = new SelectItems(); selectItems.putAttribute("value", valueExpression); // For each item to be displayed, set the label to the reverse primary key value if (attributes.containsKey(REVERSE_PRIMARY_KEY)) { selectItems.putAttribute("var", SELECT_ITEM); selectItems.putAttribute("itemValue", StaticFacesUtils.wrapExpression(SELECT_ITEM)); String displayExpression = "forgeview:display(_item)"; ((BaseStaticXmlWidget) selectItems).putAdditionalNamespaceURI("forgeview", "http://jboss.org/forge/view"); selectItems.putAttribute("itemLabel", StaticFacesUtils.wrapExpression(displayExpression)); } select.getChildren().add(selectItems); }
if ( valueHolder.getValue() == null ) { String valueExpression = metawidget.getValue(); valueExpression = StaticFacesUtils.unwrapExpression( valueExpression ); valueExpression += StringUtils.SEPARATOR_DOT_CHAR; valueExpression = StaticFacesUtils.wrapExpression( valueExpression ); valueHolder.setValue( valueExpression );
public StaticXmlWidget processWidget( StaticXmlWidget widget, String elementName, Map<String, String> attributes, StaticXmlMetawidget metawidget ) { if ( widget instanceof ValueHolder ) { // (do not overwrite existing, if any) if ( widget.getAttribute( "id" ) == null ) { ValueHolder valueWidget = (ValueHolder) widget; String valueExpression = valueWidget.getValue(); if ( valueExpression != null && !"".equals( valueExpression )) { valueExpression = StaticFacesUtils.unwrapExpression( valueExpression ); widget.putAttribute( "id", StringUtils.camelCase( valueExpression, StringUtils.SEPARATOR_DOT_CHAR ) ); } } } return widget; } }
attributes .put(FACES_LOOKUP, StaticFacesUtils.wrapExpression(StringUtils.decapitalize(ClassUtils.getSimpleName(property .getType())) + "Bean.all")); StaticFacesUtils.wrapExpression(StringUtils.decapitalize(ClassUtils.getSimpleName(property .getType())) + "Bean.converter"));
super.addColumnComponent(dataTable, tableAttributes, elementName, columnAttributes, metawidget); List<StaticWidget> columns = dataTable.getChildren(); HtmlColumn column = (HtmlColumn) columns.get(columns.size() - 1); HtmlOutcomeTargetLink link = new HtmlOutcomeTargetLink(); link.putAttribute("outcome", getTargetDir() + "/" + controllerName + "/view"); Param param = new Param(); param.putAttribute("name", "id"); param.putAttribute( "value", StaticFacesUtils.wrapExpression(dataTable.getAttribute("var") + StringUtils.SEPARATOR_DOT_CHAR + primaryKeyName)); link.getChildren().add(param); link.getChildren().add(column.getChildren().remove(1)); if(columnAttributes.containsKey(FACES_LOOKUP) && columnAttributes.containsKey(REVERSE_PRIMARY_KEY)) StaticHtmlMetawidget output = (StaticHtmlMetawidget) link.getChildren().get(1); String displayExpression = "forgeview:display(" + dataTable.getAttribute("var") + StringUtils.SEPARATOR_DOT_CHAR + StringUtils.decapitalize(columnAttributes.get(NAME)) + ")"; ((BaseStaticXmlWidget) link).putAdditionalNamespaceURI("forgeview", "http://jboss.org/forge/view"); output.setValue(StaticFacesUtils.wrapExpression(displayExpression)); String valueExpression = dataTable.getAttribute("var") + StringUtils.SEPARATOR_DOT_CHAR + tableAttributes.get(PARAMETERIZED_TYPE_PATH) + StringUtils.SEPARATOR_DOT_CHAR + StringUtils.decapitalize(columnAttributes.get(NAME)); StaticHtmlMetawidget output = (StaticHtmlMetawidget) link.getChildren().get(1);
HtmlOutcomeTargetLink link = new HtmlOutcomeTargetLink(); String outcome = getTargetDir(); if (!outcome.isEmpty() && !outcome.startsWith("/")) link.putAttribute("outcome", outcome + "/" + controllerName + "/view"); bindingProcessor.processWidget(link, elementName, attributes, (StaticUIMetawidget) metawidget); link.putAttribute("rendered", StaticFacesUtils.wrapExpression("!empty " + StaticFacesUtils.unwrapExpression(link.getValue()))); Param param = new Param(); param.putAttribute("name", "id"); param.putAttribute( "value", StaticFacesUtils.wrapExpression(StaticFacesUtils.unwrapExpression(link.getValue()) + StringUtils.SEPARATOR_DOT_CHAR + reverseKey)); link.getChildren().add(param); HtmlOutputText outputText = new HtmlOutputText(); StandardBindingProcessor bindingProcessor = metawidget .getWidgetProcessor(StandardBindingProcessor.class); bindingProcessor.processWidget(outputText, elementName, attributes, (StaticUIMetawidget) metawidget); String styleClassEl = StaticFacesUtils.unwrapExpression(outputText.getValue()) + " ? 'boolean-true' : 'boolean-false'";
StaticXmlWidget dataTable = super.createDataTableComponent(elementName, attributes, metawidget); dataTable.putAttribute("styleClass", "data-table"); bindingProcessor.processWidget(dataTable, elementName, attributes, (StaticUIMetawidget) metawidget); readableIdProcessor.processWidget(dataTable, elementName, attributes, metawidget); String tableValueExpression = valueHolderTable.getValue(); String asListValueExpression = "forgeview:asList(" + StaticFacesUtils.unwrapExpression(tableValueExpression) + ")"; valueHolderTable.setValue(StaticFacesUtils.wrapExpression(asListValueExpression)); ((BaseStaticXmlWidget) dataTable).putAdditionalNamespaceURI("forgeview", "http://jboss.org/forge/view"); HtmlPanelGroup panelGroup = new HtmlPanelGroup(); FaceletsParam param = new FaceletsParam(); param.putAttribute("name", COLLECTION_VAR); param.putAttribute("value", tableValueExpression); panelGroup.getChildren().add(param); valueHolderTable.setValue(StaticFacesUtils.wrapExpression("forgeview:asList(" + COLLECTION_VAR + ")")); valueHolderTable.setValue(StaticFacesUtils.wrapExpression(COLLECTION_VAR)); panelGroup.getChildren().add(dataTable); HtmlPanelGrid panelGrid = new HtmlPanelGrid(); panelGrid.putAttribute("styleClass", "data-table-footer");
super.addColumnComponents(dataTable, attributes, elements, metawidget); if (dataTable.getChildren().isEmpty()) HtmlCommandLink removeLink = new HtmlCommandLink(); removeLink.putAttribute("styleClass", "remove-button"); String removeExpression = COLLECTION_VAR + ".remove(" + dataTable.getAttribute("var") + ")"; removeLink.putAttribute("action", StaticFacesUtils.wrapExpression(removeExpression)); HtmlColumn column = new HtmlColumn(); column.putAttribute("headerClass", "remove-column"); column.putAttribute("footerClass", "remove-column"); column.getChildren().add(removeLink); dataTable.getChildren().add(column); HtmlCommandLink addLink = new HtmlCommandLink(); addLink.putAttribute("styleClass", "add-button"); String addExpression = COLLECTION_VAR + ".add(" + controllerName + "Bean.added)"; addLink.putAttribute("action", StaticFacesUtils.wrapExpression(addExpression)); setPropertyActionListener.putAttribute( "target", StaticFacesUtils.wrapExpression(controllerName + "Bean.add." + inverseRelationship)); StandardBindingProcessor bindingProcessor = metawidget.getWidgetProcessor(StandardBindingProcessor.class); bindingProcessor.processWidget(setPropertyActionListener, ENTITY, attributes, (StaticUIMetawidget) metawidget); addLink.getChildren().add(setPropertyActionListener);
this.entityMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + "." + ccEntity)); this.entityMetawidget.setPath(entity.getQualifiedName()); this.entityMetawidget.setReadOnly(false); this.entityMetawidget.setStyle(null); this.entityMetawidget.setReadOnly(true); writeEntityMetawidget(context, this.viewTemplateEntityMetawidgetIndent, this.viewTemplateNamespaces); this.searchMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".example")); this.searchMetawidget.setPath(entity.getQualifiedName()); this.beanMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".pageItems")); this.beanMetawidget.setPath(viewBean.getQualifiedName() + "/pageItems"); writeSearchAndBeanMetawidget(context, this.searchTemplateSearchMetawidgetIndent, this.searchTemplateBeanMetawidgetIndent, this.searchTemplateNamespaces);
/** * Overrriden to enhance the default f:selectItem widget with more suitable item labels */ @Override protected void addSelectItems( HtmlSelectOneMenu select, String valueExpression, Map<String, String> attributes ) { // Empty option // // Note: a 'null' value (rather than an empty String') renders an <f:selectItem/> rather // than an <f:selectItem itemValue=""/>. This works out better if the HtmlSelectOneMenu has // a converter, because the empty String may not be a compatible value if ( WidgetBuilderUtils.needsEmptyLookupItem( attributes ) ) { addSelectItem( select, null, null ); } // Add the select items SelectItems selectItems = new SelectItems(); selectItems.putAttribute("value", valueExpression); // For each item to be displayed, set the label to the reverse primary key value if (attributes.containsKey(REVERSE_PRIMARY_KEY)) { selectItems.putAttribute("var", SELECT_ITEM); selectItems.putAttribute("itemValue", StaticFacesUtils.wrapExpression(SELECT_ITEM)); String displayExpression = "forgeview:display(_item)"; ((BaseStaticXmlWidget) selectItems).putAdditionalNamespaceURI("forgeview", "http://jboss.org/forge/view"); selectItems.putAttribute("itemLabel", StaticFacesUtils.wrapExpression(displayExpression)); } select.getChildren().add( selectItems ); }
attributes .put(FACES_LOOKUP, StaticFacesUtils.wrapExpression(StringUtils.decapitalize(ClassUtils.getSimpleName(property .getType())) + "Bean.all")); StaticFacesUtils.wrapExpression(StringUtils.decapitalize(ClassUtils.getSimpleName(property .getType())) + "Bean.converter"));