在我的复合组件中,我迭代了一个list<list<javaDetailClass>>
. 我<h:commandButon>
通过像#{iterator.value}
. 但问题来自属性action
,其中 action 只接受method expression
。而我只能在那里分配值表达式,导致MethodNotFoundException
<cc:interface>
<cc:attribute name="formElements" />
</cc:interface>
<cc:implementation>
<c:forEach items="#{cc.attrs.formElements}" var="element">
<c:forEach items="#{element}" var="iterator">
<h:commandButton id="#{iterator.id}"
value="#{iterator.value}"
action="#{iterator.action}">
</h:commandButton>
</c:forEach>
</c:forEach>
</cc:implementation>
谁能帮我解决这个问题?提前致谢。
更新
这将是我的情况下的详细课程,
package com.stackoverflow.test;
public class TestData {
/*Properties based on the implementation of your composite.
Change type where it is needed*/
private String id;
private String value;
private String attributeName;
private String action;
public TestData() {
}
/*Getters and setters omitted*/
}
Bean.java 简单地保存了一个 ArrayList 的 ArrayList。构造函数简单地创建了五个 TestData 对象并为其属性分配了一些默认值。
package com.stackoverflow.test;
import java.util.ArrayList;
import javax.faces.bean.*;
@ManagedBean
@RequestScoped
public class Bean {
private ArrayList<ArrayList<TestData>> list = new ArrayList<ArrayList<TestData>>();
public Bean() {
ArrayList<TestData> testDataList = new ArrayList<TestData>();
TestData data;
for(int i = 0; i < 5; i++) {
data = new TestData();
data.setId("ID" + i);
data.setValue("VALUE" + i);
data.setAttributeName("ATTRIBUTE" + i);
/**this sets the action attribute of TestData with a API from some other managed bean**/
data.setAction("someOtherManagedbean.someactionAPI");
testDataList.add(data);
}
list.add(testDataList);
}
public ArrayList<ArrayList<TestData>> getList() {
return list;
}
public void setList(ArrayList<ArrayList<TestData>> list) {
this.list = list;
}
}
index.html 通过将 "#{bean.list} 的值分配给 name 属性来简单地调用组合