我知道以下示例有效。 id属性将传递给 h:link 组件,并用于构建网址(例如:/ model / {id})。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:cc="http://xmlns.jcp.org/jsf/composite"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<cc:interface>
<cc:attribute name="outcome" type="java.lang.String" />
<cc:attribute name="href" type="java.lang.String" />
<cc:attribute name="value" type="java.lang.String" />
<cc:attribute name="icon" type="java.lang.String" />
</cc:interface>
<cc:implementation>
<li class="#{prettyHelper.comparePrettyMappingIds(prettyContext.currentMapping.id, cc.attrs.outcome) ? 'active' : ''}">
<h:link outcome="#{cc.attrs.outcome}" href="#{cc.attrs.href}" title="#{cc.attrs.value}">
<f:passThroughAttribute name="data-tooltip" value="tooltip" />
<f:passThroughAttribute name="data-placement" value="right" />
<c:if test="${cc.attrs.icon != null}">
<i class="#{cc.attrs.icon}"></i>
</c:if>
<c:if test="${cc.attrs.value != null}">
<span><h:outputText value="#{cc.attrs.value}" /></span>
</c:if>
<cc:insertChildren />
</h:link>
</li>
</cc:implementation>
</html>
<...:link outcome="pretty:detail" icon="fa fa-pencil" value="Detail">
<f:param name="id" value="#{bean.id}" />
</...:link>
但是这个例子不起作用。的为什么吗
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:cc="http://xmlns.jcp.org/jsf/composite"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<cc:interface>
<cc:attribute name="id" type="java.lang.String" />
<cc:attribute name="value" type="java.lang.String" />
<cc:attribute name="style" type="java.lang.String" />
<cc:attribute name="styleClass" default="form-control form-control-sm" type="java.lang.String" />
<cc:attribute name="required" default="false" type="boolean" />
</cc:interface>
<cc:implementation>
<h:inputText id="#{cc.attrs.id}" value="#{cc.attrs.value}"
required="#{cc.attrs.required}"
styleClass="#{cc.attrs.styleClass} #{ component.valid ? '' : 'is-invalid'}"
style="#{cc.attrs.style}">
<cc:insertChildren />
</h:inputText>
</cc:implementation>
</html>
<...:simpleInput id="name" label="Name:"
value="#{bean.name}">
<f:passThroughAttribute name="autofocus" value="autofocus" />
<f:passThroughAttribute name="placeholder"
value="Name..." />
</...:simpleInput>
在第一个示例中, f:param 属性传递给 h:link 组件。在第二个示例中, f:passThroughAttribute 属性不会传递给h:inputText组件。我通过 simpleInput ( f:passThroughAttributes )传递属性地图创建了一种解决方法。设置属性映射(在bean内部)并通过 simpleInput 组件传递它们似乎真的很脏。
public Map<String, Object> attributes() {
return MapUtils.asMap(MapUtils.entry("placeholder", "Name..."));
}
<...:simpleInput id="name" label="Name:"
value="#{bean.name}" passThroughAttribute="#{bean.attributes}">
</...:simpleInput>
是否没有其他解决方案?