Passing input text 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> 

Well, that doesn't work. I can read the value of the input text in my bean support, but I can not send it to word.xhtml.

Here is another approach of mine:

 <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> 

This also does not work.

So what am I doing wrong?

+4
source share
1 answer

Your specific problem is caused by the fact that <f:param> is evaluated when a page with a form is requested, and not when a form is submitted. Thus, it remains the same value as in the initial request.

The specific functional requirement is not entirely clear, but the specific functional requirement can be solved mainly in two ways:

  • Use plain HTML.

     <form action="word.xhtml"> <input type="text" name="word" /> <input type="submit" value="Ara" /> </form> 
  • Send a redirect in an action method.

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

    with

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

Source: https://habr.com/ru/post/1439501/


All Articles