2010-08-18 48 views
0

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

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 CODE

<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> 

Managed Bean的

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; 
} 

请帮助,如果你愿意。

+0

的例子吗? – Dejell 2010-08-18 14:52:57

+0

我正在使用JSF 1.1。 – Hariharbalaji 2010-08-18 15:14:17

回答

0

EDITED

变化的方法inputData这样的:改变你的代码后,

(当然,我相信,你需要根据提示的字符串来调整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}"其中值在SelectedList中有一个获取方法。

如果缺少它,它不会显示..

查看哪些JSF版本您使用的Suggestion Box Demo

+0

对不起,这是一个输入错误而不是输入数据,我输入为填充在JSF代码中。我有getter和setter方法默认生成,这就是我在代码中提到Getter和Setter以减少空间的原因。 – Hariharbalaji 2010-08-18 15:26:42

+0

在建议行动中,您需要采取措施来填充选定的项目。 你不需要getter和setter。 – Dejell 2010-08-18 15:29:27

+0

我现在编辑了我的答案。 – Dejell 2010-08-18 15:33:56