2013-06-06 25 views
-1

我正在嘗試自動提交jsf表單。 我在窗體中有一個輸入隱藏文本框,其中字段值是從請求對象設置的。一旦完成,表單需要自動提交。如何在jsf中自動提交表單

我已經完成了使用JavaScript自動提交,也使用Primefaces,但我需要使用簡單的JSF東西。

不需要使用richfaces,primefaces。

<h:form id="form"> 
    <h:inputhidden value="#ManagedBean.user"/> 
     <h:comandbutton action="#{ManagedBean.processAction()}" /> //disabled 
       </h:form> 

回答

0

如果您使用jquery,您可以添加一個事件偵聽器到窗體並檢查是否按下了回車。

我們做的RichFaces這下面的方式,但它的地圖非常簡單的jQuery:

<rich:hotKey 
    selector="#searchForm" 
    key="return" 
    type="keypress" 
    handler="if (isValidInputFieldForHotkeyEvent(event)) { event.preventDefault(); jQuery('.searchFormDefaultAction').click(); } else { sendShiftEnter(event); }" 
    disableInInput="false" 
    disableInInputTypes=""/> 

這些JavaScript函數:

function isValidInputFieldForHotkeyEvent(event) { 
    return event.target.type != 'textarea'; 
} 

function sendShiftEnter(event) { 
    event.shiftKey = true; 
    event.ctrlKey = true; 
    event.altKey = true; 
    event.keyCode = 13; 
    event.target.fireEvent("keyPressed", event); 
} 
+0

我能夠使用richfaces。但是我需要使用沒有任何richfaces,primefaces標籤等的jsf東西。一旦它在bean中設置了inputhidden值,表單應該是自動提交的。即沒有輸入任何密鑰 – Ramya

0

您可以使用普通的舊的JavaScript?在窗口加載呼叫

document.getElementById('form').submit(); 
+0

我可以使用JavaScript。我需要使用沒有任何richfaces,primefaces標籤等的jsf東西。一旦它在bean中設置了inputhidden值,表單應該是自動提交的。即沒有輸入任何密鑰 – Ramya

+0

如何在bean中設置值? – roel