-2

I have created a table in my database and saved some data of people using a form that I've created in jsf, now what I want is to be able to enter an id of any person I want and when I click on search button be able to get (view) every info saved in database table about only that person, thank you

enila
  • 1
  • 1
  • There would need to be a lot more information in order to answer this. Is this a school assignment? – NomadMaker Nov 10 '20 at 09:37
  • it is a school assignment, I have created a table in my database and saved some data of people using a form that I've created in jsf, now what I want is to be able to enter an id of any person I want in the search box on another page and be able to get every info saved in database table about only that person, thank you – enila Nov 11 '20 at 10:22

1 Answers1

0

Change the code for infos you have.You can write person.cs instead of map.

public class PersonInfo{

    private Map<String, String> exampleData = new HashMap<String, String>() {{ 
        put("Jack", "35"); 
        put("Ryan", "24");
    }};

    private String searchString; 
    private String person;

    public void updatePerson(AjaxBehaviorEvent event) {
        person= exampleData.get(searchString);
    }

    public String getSearchString() {
        return searchString;
    }

    public void setSearchString(String searchString) {
        this.searchString = searchString;
    }

    public String getPerson() {
        return person;
    }

}


}

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
>
    <h:head/>

    <h:body>        

        <h:form>
            <h:inputText id="search" value="#{PersonInfo.searchString}" 
                onkeypress="if (event.keyCode == 13) {onchange(event); return false;}"
                onchange="return event.keyCode !== undefined" 
            >
                <f:ajax listener="#{PersonInfo.updatePerson}" render="output" />
            </h:inputText>

            <h2>
                <h:outputText id="output" value="#{PersonInfo.person}"/>
            </h2>
        </h:form>

    </h:body>
</html>
Orhano95
  • 77
  • 9
  • thank you for this, sorry for not giving the full info the data of person is saved in database – enila Nov 11 '20 at 10:23