JSF中的method和get方法有什么区别?

时间:2018-06-19 07:02:40

标签: jsf

如果您尝试使用带有jsp/jstl/core标记的c来获取值,则可以使用isget方法,如下所示。

public boolean isField() {
    return field;
}

public boolean getField() {
    return field;
}

例如

的index.xhtml:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <c:if test="#{evaluationController.field}">
            This will be displayed.
        </c:if>
    </h:body>
</html>

EvaluationController.java:

@Named(value = "evaluationController")
@RequestScoped
public class EvaluationController {

    private boolean field = true;

    public EvaluationController() {
    }

    public boolean isField() { // this line can be replaced with getField
        return field;
    }

}

这些方法在某些方面有所不同吗? 有一种优先的方式吗?

0 个答案:

没有答案