2015-10-15 25 views
0

我有一个现在应该得到一个新属性的现有JSF复合组件。这个新属性应该是一个列表,用户可以在浏览器中选择每个鼠标的x/y坐标。填充列表,这是每个JavaScript的JSF复合接口的属性

<composite:interface componentType="myComponent"> 
    ... 
    <composite:attribute name="selectedPositions" type="java.util.ArrayList" /> 
</composite:interface> 
<composite:implementation> 
    //TODO: fill selectedPositions with values 
</composite:implementation> 

使用该组件的开发者应该提供无论是预填充列表或在他们的支持豆空单:

<myns:mycomponent id="myComponent" selectedPositions="#{backingBean.prefilledList}" ... /> 

如果列表预填充,然后我将呈现这些值。但用户应该能够通过拖放来更改浏览器中的渲染值。当他/她提交表格时,更新值或新值应位于列表selectedPositions内。

目前我不知道如何从我的JavaScript代码中获取值到列表中?

回答

0

同时我找到了答案。在组件实现我可以访问传递进来的属性列表decode()

@Override 
public void decode(FacesContext facesContext) { 
    ... 
    ELContext elContext = facesContext.getELContext(); 
    ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory(); 
    ValueExpression valueExpLandmarks = expressionFactory.createValueExpression(elContext, "#{cc.attrs.selectedPositions}", List.class); 
    Object value = valueExpLandmarks.getValue(elContext); 
    if (value instanceof List) { 
     this.selectedPositions = (List) value; 
    } 
    ... 
} 

当我提交使用另一个隐藏的输入框中输入新的位置,那么我可以在组件实现填充值列表,我从隐藏的输入字段中获取。