【问题标题】:rich:suggestionbox error - this.element is null丰富:建议框错误 - this.element 为空
【发布时间】:2010-08-18 14:49:52
【问题描述】:

我正在尝试使用rich:suggestionbox。我浏览了 Richfaces 提供的教程。重要的是我使用的是 Richfaces 3.1.4 JAR。在建议框中,我只是想在开始时填充一些默认数据,但建议框根本没有呈现。当我尝试在 Firefox 中查看错误控制台时,会显示以下错误消息:

Error: this.element is null Source File: http://localhost:9080/sample/a4j_3_1_4.GAorg/richfaces/renderkit/html/scripts/suggestionbox.js.faces Line: 2

JSF 代码

<a4j:region selfRendered="true" id="region1">
    <h:inputText id="fx" />
    <rich:suggestionbox width="50" height="50" for="fx" nothingLabel="HI"
        suggestionAction="#{basic.inputData}" fetchValue="#{basic.selectedData}"
        var="result" id="suggestion">
        <h:column>
            <h:outputText value="#{result.value}" />
        </h:column>
    </rich:suggestionbox>
    <h:commandButton id="submit" value="show data"
        action="#{basic.submit}"></h:commandButton>
</a4j:region>

管理豆

enter code here
    private List<SelectedList> inputData; // Setter
    private String selectedData;   // Getter and Setter

    public List<SelectedList> getInputData() {          //Getter
    if(inputData!=null){
        inputData = new ArrayList<SelectedList>();
        inputData.add(new SelectedList("1","equal"));
        inputData.add(new SelectedList("2","not equal"));
        inputData.add(new SelectedList("3","greater"));
        inputData.add(new SelectedList("4","lesser"));
    }
    return inputData;
}

如果您愿意,请提供帮助。

【问题讨论】:

  • 你用的是哪个jsf版本?

标签: jsf richfaces


【解决方案1】:

已编辑:更改代码后:

像这样改变inputData的方法:

(当然,我相信你需要根据建议的字符串调整输入数据..)

public List<Capital> inputData(Object suggest) {
        String pref = (String)suggest;
        //if (suggest...) - add this! to complete according the word
        ArrayList<SelectedList> inputData = new ArrayList<SelectedList>();

        inputData.add(new SelectedList("1","equal"));
        inputData.add(new SelectedList("2","not equal"));
        inputData.add(new SelectedList("3","greater"));
        inputData.add(new SelectedList("4","lesser"));

        return inputData;
    }

对于:

fetchValue="#{basic.selectedData}"

您需要将其更改为:fetchValue="#{result.value}" 其中 value 是在 SelectedList 中有一个 getter 方法。

如果你错过了它就不会显示..

查看Suggestion Box Demo的示例

【讨论】:

  • 抱歉,这是一个拼写错误,而不是我在 JSF 代码中输入的 inputData。我有默认生成的getter和setter方法,这就是我在代码本身中提到Getter和Setter以减少空间的原因。
  • 在SuggestAction中你需要一个动作来填充选中的项目。你不需要 getter 和 setter。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-31
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多