2012-04-11 107 views
-1

我有一個頁面,其中a4j:commandbutton捕獲2個文本框的值。該文本框的值默認這種方式:如何將輸入文本值重置爲默認值?

<a4j:region id="pnreg" > 
    <h:inputText id="pn" binding="#{bean.pn}" 
    value="Enter Number..."  
    onclick="clickclear(this, 'Enter Number...')"/>  
    </a4j:region> 
    </td> 
    <td width="20"> 
    <a4j:region id="qtyreg" > 
    <h:inputText value="Enter Part Qty..." id="qty" binding="#{bean.qty}"  
    onclick="clickclear(this, 'Enter Qty...')"/>  
    </a4j:region> 
    </td>  
    <td width="20%"> 
    <a4j:commandButton id="addPart" render="pn,qty" value="Add Part" 
    action="#{bean.submit}" /> 

當第一次加載頁面文本框顯示的默認值,當其用戶點擊的編碼值將被清除。當按鈕被點擊時,我希望文本框返回到默認值。使用jquery我想我需要添加一個點擊事件處理程序,但是richfaces api已經有一個附加到a4j:commandbutton的事件處理程序。我如何讓我的jQuery的eventhandler與richfaces eventhandler一起工作?謝謝。

+0

,這是通過簡單地創建與輸入完成「重置」的類型,它將顯示爲一個按鈕。 – Shea 2012-04-12 02:32:58

回答

0

創建一個新的JavaScript函數,在您的文本字段上調用clickclear()。然後修改a4j:commandButton,添加一個oncomplete =「yourNewFuction();」屬性,以便在您的AJAX調用完成時執行新函數。

+0

謝謝,我會給這些鏡頭並回來。 – sotn 2012-04-12 16:23:56

0

如果你想折戟的inputText的值,那麼你應該添加您的js函數在a4j:commandButtononclick方法:

<a4j:commandButton id="addPart" value="Add Part" 
    onclick="alert('Before the ajax submit...');verifyInputTexts();" 
    action="#{bean.submit}" 
    render="pn,qty" limitToList="true" 
    oncomplete="alert('Ajax completed!')" /> 

在此代碼示例,verifyInputTexts可能是你的JS功能使用javascript驗證您的HTML。還有一件事,我寫a4j:commandButton屬性的方式是按照它們執行的順序執行的,limitToList="true"是告訴ajax只應該重新渲染render值中的組件。

0

把inputText的相同的形式的內部爲「取消」按鈕和使用類型=「復位」 例如:使用形式和輸入的普通HTML

<h:form id="globalNotificationSettingsForm"> 
     your input <h:inputText> 
     <a4j:commandButton id="cancelButton" 
     ....other tags.. 
     render="globalNotificationSettingsForm" 
     immediate="true" 
     type="reset"/> 
</h:form>