2015-10-15 31 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; 
    } 
    ... 
} 

當我提交使用另一個隱藏的輸入框中輸入新的位置,那麼我可以在組件實現填充值列表,我從隱藏的輸入字段中獲取。