Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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
Jsf 从复合组件获取bean类_Jsf_Jsf 2_Facelets_Composite Component - Fatal编程技术网

Jsf 从复合组件获取bean类

Jsf 从复合组件获取bean类,jsf,jsf-2,facelets,composite-component,Jsf,Jsf 2,Facelets,Composite Component,我有复合组件: <my:component value="#{bean.property1.property2}/> 这工作得很好,但如果我使用facelet中的my:component并通过ui:param将bean作为参数传递,这将不起作用,因为bean无法解析 可能我应该使用FaceletContext作为ELContext,而不是FacesContext.getCurrentInstance.getELContext: 但这在EncodeBeagin方法的RENDER_响应

我有复合组件:

<my:component value="#{bean.property1.property2}/>
这工作得很好,但如果我使用facelet中的my:component并通过ui:param将bean作为参数传递,这将不起作用,因为bean无法解析

可能我应该使用FaceletContext作为ELContext,而不是FacesContext.getCurrentInstance.getELContext:

但这在EncodeBeagin方法的RENDER_响应阶段不起作用。它返回上一次使用的ELContext,而不是实际的上下文。我不感到惊讶:

目标是从my:组件获取{bean.property1}类。我该怎么做?

使用RichFaces很容易:

这对我来说没问题


javax.faces.validator包中还有ValueExpressionAnalyzer,但它是包私有的,不能使用。

您可以将bean作为参数传递给组件

1如果使用复合组件,请在组件接口文件中声明属性:

<my:component value="#{bean.property1.property2}/>

3在jsf页面上设置属性:

4在组件的渲染类中,将UIComponent强制转换为myComponentClass

@凌驾 public void encodeBeginFaceContext pContext,UIComponent pComponent 抛出IOException{ myComponentClass myComponent=myComponentClass pComponent; myComponent.getYourAttribute; }
JSF自己的ValueExpressionAnalyzer是一个包私有类,因此很遗憾不能公开使用。OmniFaces还有一个org.OmniFaces.el.expressionSpector用于此目的。它甚至支持从a.o..@BalusC中使用的EL表达式中提取方法参数。关于包私有,您是对的。我已经编辑了我的答案。我应该看看OmniFaces。它与RichFaces兼容吗?几个OmniFaces工件已经用RF 4.5进行了测试。至少,它应该像PrimeFaces一样并排运行。OmniFaces旨在与任何JSF组件库兼容。如果您发现最新RF版本存在任何兼容性问题,请务必报告。谢谢您的回答。很遗憾,我无法向现有组件添加新属性。有相当多的页面使用这个组件,我不应该改变。
FaceletContext faceletElContext = (FaceletContext) FacesContext.getCurrentInstance().getAttributes()
                    .get("javax.faces.FACELET_CONTEXT");
    ValueExpressionAnalayser analyser = new ValueExpressionAnalayserImpl();
    ValueDescriptor valueDescriptor = analyser.getPropertyDescriptor(context, valueExpression);
    Class<?> beanClass = valueDescriptor.getBeanType();
<cc:interface componentType="myComponentClass">
    <cc:attribute name="myBean" preferred="true"/>
    ..others attributes
<cc:interface>