无法访问JSF控制器中的某些(大写)字段? [英] Cant access some (Capitalized) fields in JSF controller?

查看:87
本文介绍了无法访问JSF控制器中的某些(大写)字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法访问控制器中的某些(大写)字段
例如

I Cant access some (Capitalized) fields in controllers
For Example

我的控制器(* .java)

My controller (*.java)

package com.co.controller;

public class MyController {
    // fields
    private String FIELD;
    private String F1;

    // .... Controller code

    // Setters and Getters
    public String getFIELD() {
        return FIELD;
    }
    public void setFIELD(String fIELD) {
        FIELD = fIELD;
    }
    public String getF1() {
        return F1;
    }
    public void setF1(String f1) {
        F1 = f1;
    }
}

我的屏幕(* .xhtml)
当我尝试使用

My Screen (*.xhtml)
When i try to use

<h:panelGrid>
    <h:outputText value="#{myController.FIELD}" />
    <h:outputText value="#{myController.F1}" />
</h:panelGrid>

结果是
F1字段:可可访问
但是
FIELD字段:可访问

The result is
F1 field: is NOT Accessible
HOWEVER
FIELD field : is Accessible

错误出现

Property 'F1' not found on type com.co.controller.MyController 

也是我尝试使用

<h:panelGrid>
    <h:outputText value="#{myController.fIELD}" />
    <h:outputText value="#{myController.f1}" />
</h:panelGrid>

结果是
F1字段:可访问
但是
FIELD字段:不能可访问

The result is
F1 field: is Accessible
HOWEVER
FIELD field : is NOT Accessible

为什么?

推荐答案

将您的EL表达式转换为财产访问权的BeanELResolver遵守

The BeanELResolver that translates your EL-Expressions to property access adheres to the JavaBean specification. It states (in Section 8.8):

因此,当我们从现有Java名称的中间提取属性或事件名称时, 通常将第一个字符转换为小写.但是,为了支持偶尔使用所有大写名称,我们会检查名称的前两个字符是否均为大写,是否保留为大写.

Thus when we extract a property or event name from the middle of an existing Java name, we normally convert the first character to lower case. However to support the occasional use of all upper-case names, we check if the first two characters of the name are both upper case and if so leave it alone.

解析器通过反射您的实际班级来工作.它会生成 FeatureDesriptor 实例的列表,使它们与您的表情匹配.因此,解析程序从您的bean中看到的是:

The resolver works by reflection on your actual class. It produces a list of FeatureDesriptor instances and matches those to your expression. So what the resolver sees from your bean is:

  1. 属性FIELD,可读且可写
  2. 临时属性f1,可读可写
  3. 未暴露的财产F1
  1. Property FIELD, both read- and writable
  2. Transient property f1, read- and writable
  3. Unexposed property F1

由于您要访问的F1(根据JavaBeans规范没有getter和setter的),因此解析程序将抛出PropertyNotFoundException.

Since you're trying to access F1, which has no getters and setters according to the JavaBeans specification, the resolver throws a PropertyNotFoundException.

要解决此问题,请遵循常规的camelCase约定和/或使用更长的名称.

To fix this, adhere to the normal camelCase convention and/or use longer names.

另请参见:在哪里?是否定义了JavaBean属性命名约定?

这篇关于无法访问JSF控制器中的某些(大写)字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆