gpt4 book ai didi

java - 丰富的建议 - 为什么输入为空? (接缝框架)

转载 作者:行者123 更新时间:2023-11-30 05:12:08 25 4
gpt4 key购买 nike

我正在尝试构建丰富的建议,但我不明白为什么输入值为空...我的意思是,为什么当我输入某些内容时不获取 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>

和 Action 类:

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

}

因此,输入为空,建议列表始终为空...为什么输入的值没有发布?

最佳答案

嗯,关键是要使用带参数的方法来获得丰富的建议!该参数实际上是用户在该 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>

也许对其他人有用:)

关于java - 丰富的建议 - 为什么输入为空? (接缝框架),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3023469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com