简体   繁体   中英

search and display person by id in jsf

我在我的数据库中创建了一个表,并使用我在 jsf 中创建的表单保存了一些人的数据,现在我想要的是能够输入我想要的任何人的 id,当我点击搜索按钮时能够获取(查看)保存在数据库表中的关于该人的所有信息,谢谢

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM