简单问题...在commandLink的action属性中,我可以在viewController提供的对象上调用方法吗?我不能让以下设置工作,我不知道问题是什么 - 我没有得到错误,没有发生任何事情。
public class TestObject {
public void testMethod() {
System.out.println("This is a test method");
}
}
@ManagedBean
@ViewScoped
public class ViewController {
private TestObject testObject = new TestObject();
public TestObject getTestObject() {
return testObject;
}
public void testMethod() {
testObject.testMethod();
}
}
<!-- This does not work -->
<h:commandLink action="#{viewController.testObject.testMethod}" value="On internal Object"/>
<!-- This works -->
<h:commandLink action="#{viewController.testMethod}" value="On ViewController"/>
编辑:抱歉,忘了提及:我试图致电testMethod()
,viewController.getTestObject().testMethod()
也无济于事。
答案 0 :(得分:0)
我认为问题是,action
参数需要一个方法,而不是一个对象属性。
试着打电话:
<h:commandLink action="#{viewController.testObject.testMethod()}" value="On internal Object"/>
然后收到来自testObject
的属性viewController
并调用testMethod()
。
答案 1 :(得分:0)
试试这个:
<h:commandLink action="#{viewController.testObject.testMethod()}" value="On internal Object"/>