Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我可以告诉JSF,f:属性应用于复合组件的某些部分吗?_Java_Jsf 2_Attributes_Composite Component - Fatal编程技术网

Java 我可以告诉JSF,f:属性应用于复合组件的某些部分吗?

Java 我可以告诉JSF,f:属性应用于复合组件的某些部分吗?,java,jsf-2,attributes,composite-component,Java,Jsf 2,Attributes,Composite Component,在下面的示例中,我是否可以告诉JSF一个应用于某个特定组件,就像我可以在和中使用for=“…” …如本文顶部所示,与一起使用,将验证器绑定到myparent:myinputtext,但属性绑定到myparent 解决办法: 委员会: 向与最近的父UIComponent自定义操作关联的UIComponent添加属性 鉴于此,以下复合构件也能按预期工作: <composite:attribute name="item" .../> <composite:attribute nam

在下面的示例中,我是否可以告诉JSF一个
应用于某个特定组件,就像我可以在
中使用
for=“…”

…如本文顶部所示,与
一起使用,将验证器绑定到
myparent:myinputtext
,但属性绑定到
myparent


解决办法:

委员会:

向与最近的父UIComponent自定义操作关联的UIComponent添加属性

鉴于此,以下复合构件也能按预期工作:

<composite:attribute name="item" .../>
<composite:attribute name="min" .../>
<composite:attribute name="max" .../>
:
<h:inputText id="myinput" value="#{cc.attrs.item}">
    <f:convertNumber minFractionDigits="2"/>
    <f:validator validatorId="bindableDoubleRangeValidator"/>
    <f:attribute name="minimum" value="#{cc.attrs.min}"/>
    <f:attribute name="maximum" value="#{cc.attrs.max}"/>
</h:inputText>

不过:还有更好的解决办法吗?

这确实令人讨厌。
确实是最接近的父级
ui组件所特有的。如果将其嵌套在复合中,则它将特定于复合组件本身。一种方法是将属性从组合复制到相关的输入组件:


这样问题中的第一个代码片段就可以工作了

至于您的上一个代码段,更简单的方法是通过获取复合组件父级

毕竟,我会选择一个新的组合,如果有必要,在
的帮助下使用与原始组合相同的模板。复合材料旨在尽量减少重复的样板



这确实令人讨厌。
确实是最接近的父级
ui组件所特有的。如果将其嵌套在复合中,则它将特定于复合组件本身。一种方法是将属性从组合复制到相关的输入组件:


这样问题中的第一个代码片段就可以工作了

至于您的上一个代码段,更简单的方法是通过获取复合组件父级

毕竟,我会选择一个新的组合,如果有必要,在
的帮助下使用与原始组合相同的模板。复合材料旨在尽量减少重复的样板



<composite:attribute name="item" .../>
<composite:editableValueHolder name="myinput" targets="myinputtext"/>        
:
<h:inputText id="myinputtext" value="#{cc.attrs.item}">
    <!-- <composite:insertChildren /> doesn't change anything -->
</h:inputText>
<composite:attribute name="item" .../>
<composite:attribute name="min" .../>
<composite:attribute name="max" .../>
:
<h:inputText id="myinput" value="#{cc.attrs.item}">
    <f:convertNumber minFractionDigits="2"/>
    <f:validator validatorId="bindableDoubleRangeValidator"/>
    <f:attribute name="minimum" value="#{cc.attrs.min}"/>
    <f:attribute name="maximum" value="#{cc.attrs.max}"/>
</h:inputText>
<mytags:myCcInputWithValidator 
   item="#{myBean.myDouble}" min="#{30.00}" max="#{39.99}"/>
Object getAttribute(FacesContext c, UIComponent component, String name) {
    Object result = component.getAttributes().get(name);
    if (result == null && component.getParent() != null) {
        result = getAttribute(c, component.getParent(), name);
    }
    return result;
}
Object getCompositeParentAttribute(UIComponent component, String name) {
    UIComponent composite = UIComponent.getCompositeComponentParent(component);
    return composite.getAttributes().get(name);
}