10.3 Web Metawidgets

10.3.1 I put <m:metawidget > in my page but nothing appears

View the source of the final Web page that is produced. If m:metawidget appears in it, the tag is not being processed. Check you have correctly declared the m: namespace at the top of your JSP/Facelets page. Also check you have correctly deployed metawidget-all.jar into WEB-INF/lib.

If m:metawidget does not appear in the final Web page, the tag is successfully being procesed. Check whether a 'blank' Metawidget is being produced (i.e. an empty table if you are using a table-based layout, some empty divs if you are using a div-based layout). In so, check the value expression is returning a non-null value. For example, if your JSF tag is <m:metawidget value="#{foo.bar}"/>, check that #{foo.bar} does not return null. Equally, if your JSP tag is <m:metawidget value="foo"/>, check you have put foo into the scope.

10.3.2 Java Server Faces

I have annotated my getter, but Metawidget is ignoring my annotations

If your getter code is...

public class Foo {

	private String mBar = "Hello";
	
	@UiLabel( "My Bar" )
	public String getBar() {
	
		return mBar;
	}
}

...and your code JSP/Facelets code is...

<m:metawidget value="#{foo.bar}"/>

Then by default the @UiLabel annotation will be ignored. This is because the EL expression #{foo.bar} evaluates directly to an object (in this case a String) so Metawidget will not consider any parent objects or their getter methods. There are two options:

  • Change the EL expression to <m:metawidget value="#{foo}"/> and let Metawidget traverse the child property

  • Use <m:metawidget value="#{foo.bar}" inspectFromParent="true"/> to force Metawidget to unpack the EL expression and evaluate the 'parent' #{foo}

Note that if #{foo.bar} evaluates to null then Metawidget will unpack and check the parent automatically, but this is simply a niceity.

My parameterized List renders as a single column

If your getter code is...

public class Foo {

	public List<Bar> getBars() {
	
		return mBars;
	}
}

...and your code JSP/Facelets code is...

<m:metawidget value="#{foo.bars}"/>

Then by default the <Bar> parameterized type will be ignored. This is because the EL expression #{foo.bars} evaluates directly to the Collection. Metawidget will not consider any parent objects or their getter methods. There are two options:

  • Change the EL expression to <m:metawidget value="#{foo}"/> and let Metawidget traverse the child property

  • Use <m:metawidget value="#{foo.bars}" inspectFromParent="true"/> to force Metawidget to unpack the EL expression and evaluate the 'parent' #{foo}

Note that if #{foo.bars} evaluates to null then Metawidget will unpack and check the parent automatically, but this is simply a niceity.

I get "View could not be restored"

Depending on your environment and JSF implementation, you may encounter problems restoring the ViewState after POSTback. If this happens, try setting...

<context-param>
	<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
	<param-value>client</param-value>
</context-param>

...in your web.xml.

I get "The class ... does not have a readable property"

Depending on your environment, you may encounter problems with proxies introducing additional properties into your objects. These additional properties cannot be read by JSF. For example a @RequestScoped Weld object may get wrapped with a WeldClientProxy that introduces a handler property. If this happens, try setting...

<propertyTypeInspector xmlns="java:org.metawidget.inspector.propertytype"
				config="org.metawidget.inspector.impl.BaseObjectInspectorConfig">
	<propertyStyle>
		<javaBeanPropertyStyle xmlns="java:org.metawidget.inspector.impl.propertystyle.javabean"
				config="JavaBeanPropertyStyleConfig">
			<excludeName>
				<array>
					<string>handler</string>
				</array>
			</excludeName>
		</javaBeanPropertyStyle>
	</propertyStyle>
</propertyTypeInspector>

...in your metawidget.xml. This will ignore properties named handler. You may find the refId convention useful for making this declaration less verbose, see Section 2.7.5, “Understanding Immutability”.

10.3.3 Struts

I get "Cannot find bean org.apache.struts.taglib.html.BEAN in any scope"

StrutsMetawidgetTag creates native Struts widgets, such as <html:text>, but does not create the surrounding Struts form. Make sure your Metawidget tag is enclosed in a <html:form> tag and the Struts HTML taglib is included at the top of the page.

I see "MultipartRequestHandler", "ServletWrapper" and other weird names

If you use PropertyTypeInspector to inspect your ActionForm-based classes, by default it will discover properties from the org.apache.struts.action.ActionForm base class, such as getMultipartRequestHandler. To prevent this, configure metawidget.xml:

<propertyTypeInspector xmlns="java:org.metawidget.inspector.propertytype"
	config="org.metawidget.inspector.impl.BaseObjectInspectorConfig">
	<propertyStyle>
		<javaBeanPropertyStyle xmlns="java:org.metawidget.inspector.impl.propertystyle.javabean"
			config="org.metawidget.inspector.impl.propertystyle.BasePropertyStyleConfig">
			<excludeBaseType>
				<pattern>^(java|javax|org\.apache\.struts)\..*$</pattern>
			</excludeBaseType>
		</javaBeanPropertyStyle>
	</propertyStyle>
</propertyTypeInspector>