我的xhtml页面如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title> Portal Financeiro </title>
<link rel="icon" type="image/png" href="" />
</h:head>
<h:body>
<h:form id="form">
<h:inputText value="#{testeBean.name}" />
<h:commandButton value="Enviar" action="#{testeBean.enviar}" />
</h:form>
</h:body>
</html>
我的豆子背后:
package br.com.teste.controller;
import javax.faces.bean.RequestScoped;
import javax.inject.Named;
@Named
@RequestScoped
public class TesteBean {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void enviar(){
System.out.println("NAME " + name );
}
}
问题是:当我提交表单时,字段名称的值返回null。
我的配置:
答案 0 :(得分:2)
导入错误,CDI注释位于javax.enteprise.context
包中。因此,您应该导入javax.enteprise.context.RequestScoped
。或者对于此特定组合(@RequestScoped
+ @Named
),您可以使用名为@Model
的内置stereotype。