JSF - <f:selectitems>没有从Bean获取值

时间:2018-04-28 01:37:53

标签: maven jsf web-applications xhtml

我正在使用Maven构建一个非常简单的WebApp,以创建一个小的REST Api(同时使用JSF)。

在我的一个bean(以及其他方法和变量中)中,我创建了一个非常简单的List,以测试我是否可以在JSF中获取其选项<p:selectItems>

这是bean代码:

 @ManagedBean(name="er", eager=true)
 public class ExchangeRates {
        private List<String> frase = new ArrayList<>();

            public List<String> getFrase() {
                frase.add("opcao1");
                frase.add("opcao2");
                return frase;
            }

            public void setFrase(List<String> frase) {
                this.frase = frase;
            }
/*some more code that doesn't use "frase"*/

这是(xhtml)JSF

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>Currency Conversion REST Api</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    </h:head>
    <h:body>
        <h1>Currency Conversion</h1>

        <h:form>               
            <h:outputLabel for="txtName">
                           <h:outputText value="Quantity:  " />
            </h:outputLabel>
            <h:inputText id="txtNamea" value="#{er.quantity}" />

            <br></br><br></br>

            <h:outputLabel for="currency1" value="Convert from:  "/> 
                <h:selectOneMenu id="currency1" value="#{er.currency1}" style="width:70px">
                    <f:selectItems value="#{er.frase}" />
                </h:selectOneMenu>

        </h:form> 
    </h:body>
</html>

<f:selectItems>创建的下拉列表应该给我2个选项(“opcao1”和“opcao2”)。但是,当我点击它时,它就好像我没有为它分配任何变量或值,我可能做错了什么?

0 个答案:

没有答案