[英]Method not called on object in ViewController ( = ViewScoped ManagedBean)
Simple enough question... inside a commandLink's action attribute, can I call a method on an object provided by a viewController? 足够简单的问题...在commandLink的action属性中,我可以在viewController提供的对象上调用方法吗? I can't get the following setup to work, and I don't know what the problem is - I don't get errors, there's just nothing happening.
我无法使用以下设置来工作,而且我不知道问题出在哪里-我没有收到错误,什么也没发生。
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"/>
EDIT: Sorry, forgot to mention it: I tried to call testMethod()
and also viewController.getTestObject().testMethod()
to no avail. 编辑:对不起,忘了提一下:我试图调用
testMethod()
以及viewController.getTestObject().testMethod()
也无济于事。
I think the problem is, that the action
parameter expects a method, not a object property. 我认为问题在于,
action
参数需要一种方法,而不是对象属性。 Try to call: 尝试致电:
<h:commandLink action="#{viewController.testObject.testMethod()}" value="On internal Object"/>
Then the property testObject
from the viewController
gets received and testMethod()
get invoked. 然后,
testObject
来自viewController
的属性testObject
并调用testMethod()
。
尝试这个:
<h:commandLink action="#{viewController.testObject.testMethod()}" value="On internal Object"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.