0

I am struggling in trying to send some information from a textfield to a bean-method and process the input there. My code looks like that:

<h:form id="form2">
    <p:inputText id="casTextBox" value="#{TsneDAODB.getNearestNeighborsAsJSON('blubb2')}" /> 
    <br/>
    <p:commandButton id="nearestNeighborsSubmit" type="post"  action="#{TsneDAODB.getNearestNeighborsAsJSON('blubb')}" value="Surrounding substances">

    </p:commandButton>

    </h:form>

I would like to send the input in the textfield to the method nearestneighborsAsJSON(String) of the bean TsneDAODB but i can't figure out how i access the content of the textfield and what attribute i have to use to send it away. The current code at least triggers the method with the given input through the action= attribute of the commandbutton (but without even pushing it). So where do i have to add the respective EL to submit the input and what would the correct EL syntax look like to access the casTextBox input?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
d00d
  • 688
  • 1
  • 8
  • 29
  • Possible duplicate of [How to send form input values and invoke a method in JSF bean](https://stackoverflow.com/questions/3681123/how-to-send-form-input-values-and-invoke-a-method-in-jsf-bean) – Kukeltje Nov 07 '18 at 11:56

1 Answers1

0

You should link the input text box to a field contained into your bean then in your getNearestNeighborsAsJSON method you can access the value posted by your form. Remember that the bean should expose getter and setter for that field

<h:form id="form2">
    <p:inputText id="casTextBox" value="#{TsneDAODB.fieldXXX}" /> 
    <br/>
    <p:commandButton id="nearestNeighborsSubmit" type="post"  action="#{TsneDAODB.getNearestNeighborsAsJSON('blubb')}" value="Surrounding substances">

    </p:commandButton>

 </h:form>
TheOni
  • 810
  • 9
  • 26
  • Like how jsf works in general https://stackoverflow.com/questions/3681123/how-to-send-form-input-values-and-invoke-a-method-in-jsf-bean – Kukeltje Nov 07 '18 at 11:55