我正在实现一个复合组件,我发现了一个我找不到解决方案的问题.
我指定了页面作者可以传递或不传递的属性,但我无法指定方法属性(Action的方法表达式),如果未传递,则复合组件不使用method属性在composite:implementation标签中.
这是我的代码:
<composite:interface>
<composite:attribute name="namePrompt" required="true"/>
<composite:attribute name="actionMethod" method-signature="java.lang.String action()" required="false"/>
<composite:attribute name="showComponent" default="false"/>
</composite:interface>
<composite:implementation>
<div>
<p:commandLink actionListener="#{cc.attrs.actionMethod}"
rendered="#{cc.attrs.showComponent}"
>
<h:outputText value="#{cc.attrs.namePrompt}"/>
</p:commandLink>
</div>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)
使用它时,我没有指定"actionMethod"属性.像这样:
<util:foo namePrompt="SomeName" showComponent="true"/>
Run Code Online (Sandbox Code Playgroud)
但我收到错误消息:
javax.faces.FacesException: Unable to resolve composite component from using page using EL expression '#{cc.attrs.actionMethod}'
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我正在研究Java认证1Z0-803,我对垃圾收集存在疑问:
import java.util.*;
class X {
List<String> list = new ArrayList<>();
}
public class TestGC {
// Is an Object eligible for GC even if its instance variable is references to another variable
public static void main(String[] args){
X x = new X(); // 1
List<String> list = x.list;
x = null; // 2, Is X object reference eligible for garbage collection here?
list.add("a");
list.add("b");
list.add("c");
for(String item : list) {
System.out.println(item);
}
list = null;// 3, Or X object …Run Code Online (Sandbox Code Playgroud)