2012-10-12 39 views
4

我想将用户输入作为参数传递给另一页。这里是我的代码:将输入文本值作为参数传入

<h:form> 
    <h:inputText value="#{indexBean.word}"/> 
    <h:commandLink value="Ara" action="word.xhtml"> 
      <f:param value="#{indexBean.word}" name="word"/> 
    </h:commandLink> 
</h:form> 

嗯,这是行不通的。我可以读取我的支持bean中的输入文本值,但我无法将其发送到word.xhtml。

这里是另一种方法我试过:

<h:form> 
    <h:inputText binding="#{indexBean.textInput}"/> 
    <h:commandLink value="Ara" action="word.xhtml"> 
      <f:param value="#{indexBean.textInput.value}" name="word"/> 
    </h:commandLink> 
</h:form> 

这也不能正常工作。

那么,我做错了什么?

回答

2

您的具体问题是由于<f:param>在请求带有表单的页面时进行评估而不是在提交表单时评估的。所以它和最初的请求保持一样的价值。

具体功能要求是不完全清楚,但具体的功能要求可在基本上有两种方式解决:

  1. 使用普通的HTML。

    <form action="word.xhtml"> 
        <input type="text" name="word" /> 
        <input type="submit" value="Ara" /> 
    </form> 
    
  2. 发送操作中的重定向方法。

    <h:form> 
        <h:inputText value="#{bean.word}" /> 
        <h:commandButton value="Ara" action="#{bean.ara}" /> 
    </h:form> 
    

    public String ara() { 
        return "word.xhtml?faces-redirect=true&word=" + URLEncoder.encode(word, "UTF-8"); 
    } 
    
+0

是啊,这对我的作品!我也尝试使用flashScope,它也在工作。谢谢你的帮助! – ozubaba

相关问题