Jsf 我的actionListener被忽略了
我有一个jsf页面,其中有以下表单:Jsf 我的actionListener被忽略了,jsf,Jsf,我有一个jsf页面,其中有以下表单: <h:commandButton id="submit" value="Submit"> <h:inputText id="locationInputId" value="#{historicCtrl.historic.search}" ></h:inputText> <f:ajax event="click" render="resultGrou
<h:commandButton id="submit" value="Submit">
<h:inputText id="locationInputId" value="#{historicCtrl.historic.search}" ></h:inputText>
<f:ajax event="click" render="resultGroup" listener="#{cSVobjectCtrl.doRender}"/>
<label for="lat">Latitude</label>
<h:inputText id="lat" value="#{cSVobjectCtrl.lat}"/>
<label for ="lng">Longitude</label>
<h:inputText id="lng" value="#{cSVobjectCtrl.lng}"/>
<f:actionListener binding="#{historicCtrl.insertSearch(2)}"/>
</h:commandButton >
纬度
经度
问题是线路:
<h:form>
<h:outputText value="Lieu"/>
<h:inputText id="login" value="#{historicCtrl.historic.search}" required="true"></h:inputText>
<br/>
<h:commandButton value="Search">
<h:outputText id ="textToInsertId" value="#{historicCtrl.insertSearch(2)}"/>
</h:commandButton>
</h:form>
这一个正在工作,我可以看到该方法应该在控制台上打印的跟踪,并且在我的数据库中有插入
相反,我在消息中编写的第一个代码没有按预期工作。事实上,除了f之外,一切都在自然运行;正如我上面解释的那样
为什么不使用此指令?您的代码确实令人困惑,但我将集中讨论这个问题,并提供一个示例,说明您的代码应该是什么样子 如果要绑定actionListener,必须将其绑定到实现actionListener接口的对象,而不是方法,例如: facelet
<f:actionListener binding="#{historicCtrl}" />
如果使用绑定,则无法将参数传递给actionListener。更好的方法是使用h:commandButton的actionListener属性。在这种情况下,您的代码应该如下所示:
<h:form id="form">
<h:inputText id="locationInputId" value="#{historicCtrl.historic.search}" />
<br />
<h:outputLabel for="lat" value="Latitude" />
<h:inputText id="lat" value="#{cSVobjectCtrl.lat}"/>
<br />
<h:outputLabel for="lng" value="Longitude" />
<h:inputText id="lng" value="#{cSVobjectCtrl.lng}"/>
<br />
<h:commandButton id="submit" value="Submit" actionListener="#{historicCtrl.insertSearch(2)}">
<f:ajax execute="form" render="resultGroup" listener="#{cSVobjectCtrl.doRender}"/>
</h:commandButton>
</h:form>
<h:form id="form">
<h:inputText id="locationInputId" value="#{historicCtrl.historic.search}" />
<br />
<h:outputLabel for="lat" value="Latitude" />
<h:inputText id="lat" value="#{cSVobjectCtrl.lat}"/>
<br />
<h:outputLabel for="lng" value="Longitude" />
<h:inputText id="lng" value="#{cSVobjectCtrl.lng}"/>
<br />
<h:commandButton id="submit" value="Submit" actionListener="#{historicCtrl.insertSearch(2)}">
<f:ajax execute="form" render="resultGroup" listener="#{cSVobjectCtrl.doRender}"/>
</h:commandButton>
</h:form>