如何解决由于呈现了属性,因此无法获取jsf inputtext值
下面是一个简单的jsf页面,其中包含1 x selectOneMenu,3 x inputText和1 x commandButton。 单击commandButton时,testBean无法从Submit方法中的inputText中获取p2和p3的值,p2和p3始终返回null。它与'rendered'属性有关,当我删除它时p2和p3可以正常工作。
根据日志,将执行setType和setP1,但缺少setP2和setP3。
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<meta charset="utf-8" />
<title>Test</title>
</h:head>
<h:body>
<h:messages id="msg" />
<h:form id="form1" method="post">
<h:selectOneMenu value="#{testBean.type}">
<f:selectItem itemValue="" itemLabel="Select..." />
<f:selectItem itemValue="all" />
<f:ajax render="@form" execute="@form" />
</h:selectOneMenu>
<h:inputText value="#{testBean.p1}" />
<h:inputText value="#{testBean.p2}"
rendered="#{not empty testBean.type}" />
<h:panelGroup rendered="#{not empty testBean.type}">
<h:inputText value="#{testBean.p3}" />
</h:panelGroup>
<h:commandButton value="Submit" action="#{testBean.submit}" />
</h:form>
</h:body>
</html>
@javax.interceptor.Interceptors(LogInterceptor.class)
@javax.inject.Named
@javax.enterprise.context.RequestScoped
public class TestBean {
protected static final org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getLogger();
String type;
String p1;
String p2;
String p3;
public void submit() {
logger.debug("type: {}",this.type);
logger.debug("p1: {}",this.p1);
logger.debug("p2: {}",this.p2);
logger.debug("p3: {}",this.p3);
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getP1() {
return p1;
}
public void setP1(String p1) {
this.p1 = p1;
}
public String getP2() {
return p2;
}
public void setP2(String p2) {
this.p2 = p2;
}
public String getP3() {
return p3;
}
public void setP3(String p3) {
this.p3 = p3;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。