2010-06-11 23 views
1

我试图建立一个丰富的建议,我不明白为什么输入值为空... 我的意思是,为什么我输入的东西时不会采取inputText值。丰富的建议 - 为什么输入为空? (缝框架)

的.xhtml代码:

<h:inputText value="#{suggestion.input}" id="text"> 
</h:inputText> 
<rich:suggestionbox id="suggestionBoxId" for="text" tokens=",[]" 
        suggestionAction="#{suggestion.getSimilarSpacePaths()}" var="result" 
        fetchValue="#{result.path}" 
        first="0" 
        minChars="2" 
        nothingLabel="No similar space paths found" 
        columnClasses="center" 
     > 
    <h:column> 
     <h:outputText value="#{result.path}" style="font-style:italic"/> 
    </h:column> 
</rich:suggestionbox> 

和动作类:

@Name("suggestion") 
@Scope(ScopeType.CONVERSATION) 
public class Suggestion { 
@In 
protected EntityManager entityManager; 

private String input; 

public String getInput() { 
    return input; 
} 

public void setInput(final String input) { 
    this.input = input; 
} 

public List<Space> getSimilarSpacePaths() { 
    List<Space> suggestionsList = new ArrayList<Space>(); 
    if (!StringUtils.isEmpty(input) && !input.equals("/")) { 
     final Query query = entityManager.createNamedQuery("SpaceByPathLike"); 
     query.setParameter("path", input + '%'); 
     suggestionsList = (List<Space>) query.getResultList(); 
    } 
    return suggestionsList; 
} 

}

所以,输入beeing空,suggestionList总是空... 为什么输入的值没有发布?

回答

2

那么, 关键是要使用带有参数的方法来提供丰富的建议!这个参数居然是如此,而不是上面的类应该是什么类型的用户在inputText的....:

@Name("suggestion") 
public class Suggestion { 


@In 
protected EntityManager entityManager; 

public List<String> getSimilarSpacePaths(final Object input) { 
    //prepare the list with the strings 
     //... 
    return suggestionsList; 
    } 
    } 

和.xhtml:

<h:inputText id="text" size="80" value="#{accountHome.instance.creationPath}"> 
</h:inputText> 
<rich:suggestionbox id="suggestionBoxId" for="text" tokens=",[]" 
    suggestionAction="#{suggestion.getSimilarSpacePaths}" var="result" 
    fetchValue="#{result}" 
    first="0" 
    minChars="2" 
    nothingLabel="No similar space paths found" 
    columnClasses="center" 
    width="350" 
    > 
<h:column> 
    <h:outputText value="#{result}" style="font-style:italic"/> 
</h:column> 
<a:support ajaxSingle="true" event="onselect"> 
    <f:setPropertyActionListener value="#{result}" target="#{accountHome.instance.creationPath}"/> 
</a:support> 
</rich:suggestionbox> 

也许将是有益的其他:)

0

我不确定这是否有效,但Java使用getter和setter来使用JSP封装它的字段。既然你试图在一个xhtml文件中使用Java,我想这就是你正在做的。

注意你怎么样#{suggestion.input}?在JSP中,这将导致suggestion.getInput(),这是您创建的getter。您可以拨打suggestion.SimilarSpacePaths

当它无法正确评估值时,JSP默认为null或空字符串(我不确定是哪个)。虽然有JSP的调试插件,所以你可以告诉它,而不必编译和检查网页。

这有帮助吗?

+0

不幸的是,没有。该方法名称是可以的,因为在调试模式下,该方法成功地被“捕获”。 – 2010-06-14 08:00:58