传递inputtext值作为参数 [英] Passing inputtext value as parameter
问题描述
我想将用户输入作为参数传递给另一个页面.这是我的代码:
I want to pass user input to another page as a parameter. Here is my code:
<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中读取inputtext值,但无法将其发送到word.xhtml.
Well, this is not working. I can read the inputtext value in my backing bean but I can't send it to word.xhtml.
这是我尝试过的另一种方法:
Here is another approach I tried:
<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>
这也不起作用.
那么,我在做什么错了?
So, what am I doing wrong?
推荐答案
您的具体问题是由于在请求带有表单的页面时而不是在提交表单时对<f:param>
进行评估而引起的.因此,它保持与初始请求相同的值.
Your concrete problem is caused because the <f:param>
is evaluated when the page with the form is requested, not when the form is submitted. So it remains the same value as on the initial request.
具体的功能要求尚不完全清楚,但是特定的功能要求基本上可以通过两种方式解决:
The concrete functional requirement is not exactly clear, but the particular functional requirement can be solved in basically two ways:
-
使用纯HTML.
Use plain HTML.
<form action="word.xhtml">
<input type="text" name="word" />
<input type="submit" value="Ara" />
</form>
发送重定向方法.
Send a redirect in action method.
<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");
}
这篇关于传递inputtext值作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!