1

In the search box, the user type a word, like "iPhone", and click "Search", the system performs backend search and return all information for "iPhone". In the end, it also output a related word "iPod" through wordController.related variable. If the user clicks "iPod" link, the system needs to pass iPod as another word to perform search, and return results again. My question, how can I pass "iPod" (the "related" variable) as another search variable and perform backend search? This time, it is not through h:inputText and h:commandButton, since it's not user entered value.

Thank you for your help!

<h:form id="wordForm">
        <h:panelGrid columns="3">
            <h:outputLabel for="word">Enter a word:</h:outputLabel>
            <h:inputText id="word"
                value="#{wordController.word}" />
            <h:message for="word" />
        </h:panelGrid>
        <h:commandButton id="search" value="Search!"
            action="#{wordController.info}" />
    </h:form>
    <br />
    <h:outputText value="#{wordController.wordInfo}"
        rendered="#{not empty wordController.wordInfo}" />

    <h:link value="#{wordController.related}" />
Tiny
  • 27,221
  • 105
  • 339
  • 599
marlon
  • 6,029
  • 8
  • 42
  • 76
  • I don't think your question title describes very well what you are trying to achieve. As the question seems to be more about ways to handle passed parameter on the server side to perform a search action. Am I right, or you are satisfied with User404's answer? – Aleksandr Erokhin May 23 '15 at 15:45
  • @Alex, sorry, I didn't quite get it. Please see below. – marlon May 23 '15 at 18:49
  • Is this acceptable as dupe? http://stackoverflow.com/questions/30280379/passing-get-parameters-doesnt-work-parameter-not-visible-in-the-link – BalusC May 23 '15 at 19:41
  • Not really. Related words are a linked elements, and when user click it, it needs to pass this linked element as a parameter and perform another search. – marlon May 24 '15 at 06:26

1 Answers1

8
<h:link value="This is a link" outcome="login" >
    <f:param name="firstname" value="Matt" />
</h:link>

HTML output

<a href="......./faces/login.xhtml?firstname=Matt">This is a link</a>
User404
  • 2,152
  • 2
  • 27
  • 35
  • firstname is a variable, but Matt is a value. How can you put a value into value=""? In my case, the value comes from wordController.related variable. Then I need a way to pass the value represented by 'related' variable for the backend to perform a search, executed by wordController.info() function. – marlon May 23 '15 at 18:49
  • 1
    just use '#{wordController.related}' like you would do in other cases – User404 May 25 '15 at 14:54