1

I want when user entered some value in text field and submit, the button should disabled.

But it just disabled when button is not in a form:

Works

<h:inputText/>
<h:commandButton value="btn1" action="#{bean2.showClicked}" onclick="this.disabled=true;" />

Not works

<h:form>
    <h:inputText/>
    <h:commandButton value="btn1" action="#{bean2.showClicked}" onclick="this.disabled=true;" />
</h:form>

I need to disable button in form.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Both of those work for me. Using Java EE 6 deployed to Glassfish 3.1.2.2. – DavidS May 05 '15 at 18:04
  • @DavidS I using java EE7 with Tomcat. –  May 05 '15 at 18:24
  • 1
    HTML/JavaScript are unrelated to Java EE. Besides, Tomcat is not an application server. It is a bare-bones Servlet container having Servlets/JSP APIs only -- not a Java EE compliant container. – Tiny May 05 '15 at 18:30
  • @Tiny Why in the second case it cannot disable the button? –  May 05 '15 at 18:31
  • Maybe he meant TomEE. – DavidS May 05 '15 at 18:41
  • The button is permanently disabled and no request is sent after disabling the button I could see, when I ran your example (the second one). This can never be a requirement by the way. – Tiny May 05 '15 at 18:41
  • 2
    You need to set an interval. See [here](http://stackoverflow.com/a/11746851/1391249). All in all, you want to prevent duplicate form submits I guess. You already use PrimeFaces. There are several ways to do so. Why not choose one of them -- what you need? – Tiny May 05 '15 at 19:03
  • @Tiny I tried suggested link solution, but not worked for me! –  May 05 '15 at 20:40
  • 'not worked for me' is not 'smart'... Mention what you experienced from a **developer** point of view. So things like server crashed and stopped working, ajax call not send, whatever... – Kukeltje May 05 '15 at 22:50
  • Use a local valiable to enable disable the button, on action method change it's value. And use **disabled** attribute to enable disable it. – Gaurav Jeswani May 06 '15 at 12:35

0 Answers0