【问题标题】:rich suggestions - why input is null? (seam framework)丰富的建议 - 为什么输入为空? (接缝框架)
【发布时间】:2010-06-11 14:12:57
【问题描述】:

我正在尝试构建丰富的建议,但我不明白为什么输入值为空... 我的意思是,为什么当我输入一些东西时没有使用 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为空,suggestList总是为空... 为什么输入的值没有发布?

【问题讨论】:

    标签: java jsf richfaces seam


    【解决方案1】:

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

    也许对其他人有用:)

    【讨论】:

      【解决方案2】:

      我不确定这是否有效,但 Java 使用 getter 和 setter 来用 JSP 封装它的字段。由于您尝试在 xhtml 文件中使用 Java,我想这就是您正在做的事情。

      注意到你#{suggestion.input} 的样子了吗?在 JSP 中,这将产生一个 suggestion.getInput(),这是您创建的 getter。

      以同样的方式,您可以拨打suggestion.SimilarSpacePaths

      当 JSP 无法正确评估值时,它默认为 null 或空字符串(我不确定是哪个)。不过,有针对 JSP 的调试插件,因此您无需在网页上编译和检查即可知道这一点。

      有帮助吗?

      【讨论】:

      • 不幸的是,不是。方法名称没问题,因为在调试模式下该方法已成功“捕获”。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2017-09-30
      • 1970-01-01
      相关资源
      最近更新 更多