我有一个h:inputText
,它有一个文本,通过ajax请求,我如何将它的值发送到bean
类,这些值将在从bean类开始的进一步操作中进行验证。。
查看页面代码是
<h:form>
<p:panel id="panel" header="Login Panel" style="margin:0 auto;width:350px;margin-top:15%;">
<p:panelGrid columns="3" id="pgrid1" styleClass="theme" >
<p:outputLabel value="User Name:" />
<p:inputText id="name" value="#{loginBean.name}" required="true" requiredMessage="Name is required">
<f:ajax event="blur" render="label" listener="loginBean.validateName" ></f:ajax>
<!--Here the ajax event working properly but how can i get the inputText value when ajax event is invoked-->
</p:inputText>
<p:message for="name" style="color: red;" />
</p:panelGrid>
<p:commandButton type="Submit" value="Submit" action="#{loginBean.validate}" update="pgrid1" />
</p:panel>
我的Bean类代码是:
public void validateName(AjaxBehaviorEvent e)
{
//Here i need inputText value..how can i handle this task..!!
}
JSF此时已经设置了#{loginBean.name}
值。直接访问即可。
public void validateName(AjaxBehaviorEvent e)
{
System.out.println(name); // Look, JSF has already set it.
// ...
}
顺便说一句,<f:ajax listener>
中出现了EL语法错误,导致侦听器方法永远无法调用,但我敢打赌,这只是在准备问题时的疏忽,因为您提到它"工作正常"。在未来的问题中,请在真实的开发环境中编辑代码,并复制粘贴真实的工作代码,而不是在问题编辑器中盲目编辑代码。