-1

I am trying to autosubmit a jsf form. I have one inputhidden textbox in the form, where the field value is set from request object.Once its done, the form need to submit automatically.

I have done autosubmit using javascript and also using Primefaces, but I need to do it using Simple JSF stuff.

No need of using richfaces, primefaces.

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

2 Answers2

0

if you use jquery, you can add an event listener to the form and check if enter is pressed.

We do this following way with richfaces, but it maps quite simple to jquery:

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

These are the javascript functions:

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);
}
cremersstijn
  • 2,375
  • 4
  • 28
  • 41
  • I can able to do using richfaces. But I need to use jsf stuff without any richfaces, primefaces tags etc. The form should be autosubmit once it sets the inputhidden value in the bean. ie without enterning any key – Ramya Jun 06 '13 at 09:06
0

You can use plain old javascript? On window load call

document.getElementById('form').submit();
jeremyjjbrown
  • 7,772
  • 5
  • 43
  • 55
roel
  • 2,005
  • 3
  • 26
  • 41
  • I can able to do using javascript. I need to use jsf stuff without any richfaces, primefaces tags etc. The form should be autosubmit once it sets the inputhidden value in the bean. ie without enterning any key – Ramya Jun 06 '13 at 09:04
  • how is your value set in the bean? – roel Jun 06 '13 at 12:48