我有一个小问题。我想从我的输入区域获取价值,我正在投入,但它没有正确更新。字符串值始终为空。Primefaces获取输入值
XHTML:
<!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"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Pragma" content="No-cache" />
<meta http-equiv="Cache-Control"
content="no-store,No-cache,must-revalidate,post-check=0,pre-check=0,max-age=0" />
<meta http-equiv="Expires" content="-1" />
<link type="text/css" rel="stylesheet"
href="#{request.contextPath}/resources/css/styles.css" />
<link rel="shortcut icon" href="#{resource['Icon.png']}"
type="image/x-icon" />
<title>#{msg['title.index']}</title>
</h:head>
<h:body style="background:#f5f5f5;">
<h:form>
<p:commandButton value="#{bean.button}"
style="margin-left:10px;margin-top:10px;" />
<p:inputTextarea value="#{bean.text}" autoResize="true"
placeholder="#{msg['label.placeholder']}" rows="3" cols="90"
style="margin-top:250px;margin-left:5px;">
</p:inputTextarea>
</h:form>
</h:body>
</html>
豆:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name = "bean")
@SessionScoped
public class Controller {
private String text;
private String button = "Click";
public String getText() {
System.out.println(text);
return text;
}
public void setText(String text) {
this.text = text;
}
public String getButton() {
return button;
}
public void setButton(String button) {
this.button = button;
}
}
它没有看起来像他找不到我的豆,因为i的值给该按钮在浏览器中正确显示。但是输入不起作用。 我已经和jsf一起工作过,并且从来没有通过bean传递值的问题。我的另一个项目是使用像这里一样的方法,它的工作原理。但在这种情况下,我的输入不会转到bean。请帮助。
使用调试器,调用'setText'吗? – Smutje
不在按键。但他应该自动注意何时按下键并更新getter和setter。它没有。 –
它为什么要在按键上做任何事情,你根本没有AJAX听众? – Smutje