我試圖將正常的bean驗證附加到以編程方式生成的Primefaces UIComponent上的模糊事件。如何將ajax驗證添加到以編程方式生成的primefaces組件
如果我手動創建使用XHTML的組件,它工作得很好,它看起來像這樣:
<p:inputText id="customerName" value="#{editCustomerBean.name}" label="Name">
<p:ajax async="true" event="blur" update="customerName, customerNameMsg" />
</p:inputText>
不幸的是我需要產生的,因爲這將基於填充一些動態屬性的飛這個組件運行時數據。該代碼我寫了嘗試,並準確地複製此組件:當我生成這樣,這個組件
UIInput input = new InputText();
AjaxBehavior ajax = new AjaxBehavior();
ajax.setAsync(true);
ajax.setUpdate("customerName, customerNameMsg");
input.addClientBehavior("blur", ajax);
input.setId("customerName");
input.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{editCustomerBean.name}", String.class));
,我看到發送到執行模糊事件的服務器的請求,但沒有確認發生。這是發佈的請求看起來相同的是,當我指定XHTML組件被髮送:
javax.faces.partial.ajax=true&javax.faces.source=mainForm%3AcustomerName&javax.faces.partial.execute=mainForm%3AcustomerName&javax.faces.partial.render=mainForm%3AcustomerName+mainForm%3AcustomerNameMsg&javax.faces.behavior.event=blur&javax.faces.partial.event=blur&mainForm%3AcustomerName=&javax.faces.ViewState=8176624577669857830%3A-4154840965136338204
我已經看到張貼本網站和Primefaces論壇上類似的問題,但它通常涉及連接監聽器的方法AjaxBehavior,這不是我在這裏要做的。當沒有指定偵聽器時,我希望該行爲與標記相同,即驗證字段。