0

I have to enable the 'save button' only when there is an update in my form page, otherwise it should be disabled. Here after the code I am using for :

<a4j:commandButton styleClass="boutonAction buttonSave"
    value="#{messages['btn.save.label']}"
    update="editForm"
    action="#{Action.save()}"

    ajaxSingle="false" immediate="false" limitToList="true"
    reRender="msg" />

I think in this case I need to include a JS ?

Vasil Lukach
  • 3,658
  • 3
  • 31
  • 40
Nabil Salah
  • 300
  • 3
  • 7
  • 19
  • Not related to problem: `a4j:commandButton` doesn't have `update` attribute in RichFaces 3.x (I guess this version is used based on `reRender`) – Vasil Lukach Nov 13 '15 at 15:59
  • Yes maybe you are right, but my problem is how to disable the 'a4j:commandButton' button ? – Nabil Salah Nov 13 '15 at 16:01
  • You should use `disabled` attribute and re-rendering mechanism – Vasil Lukach Nov 13 '15 at 16:03
  • yes I did some searches we advise to use 'disabled'. Could you just give me an example of use (is this correct : disabled="#{ editForm.isEditAccess() == true}") ? – Nabil Salah Nov 13 '15 at 16:06
  • It will not work in your old environment. It can be like `disabled="#{editForm.editAccess}"` where isEditAccess is method name in your java bean. Or `disabled="#{editForm.editAccess == 'false'}"` – Vasil Lukach Nov 13 '15 at 16:10
  • Actually EditForm is a bean and isEditAccess() is a boolean method in that bean. By debbuging I made sure that isEditAccess() is returning false in my case and I tried with disabled="#{editForm.isEditAccess() == 'false'}" : the button remain enabled. Is there an other solution ? – Nabil Salah Nov 13 '15 at 16:38

2 Answers2

0

You can use disabled attribute

<a4j:commandButton value="Update"
                   disabled="#{!bean.save}"/>
<a4j:commandButton value="Save"
                   disabled="#{bean.save}"/>

Now how you will disable/enable button,Put this inside a panel grid if you have logic to hide/show in your bean method then on action you can update the save variable.

<h:panelGrid id="panelGrid">
 <a4j:commandButton value="Update" 
                       disabled="#{!bean.save}" render="panelGrid"/>
  <a4j:commandButton value="Save" action=""
                       disabled="#{bean.save}" render="panelGrid"/>
</h:panelGrid>

There could be other way also possible but you have to clearly right your problem in detail.

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
  • Thank you for your answer. For more details : what I need is that in case there is no update in my form the save button should be darken (with no possibility to click in) otherwise could save the information update by clicking in the button. – Nabil Salah Nov 13 '15 at 16:46
  • Its called Dirty Checking this problem not specif to JSF..here is detail solution given by a rich developer of JSF @Balusc http://stackoverflow.com/questions/8259090/how-to-detect-unsaved-data-in-form-when-user-leaves-the-page – Subodh Joshi Nov 13 '15 at 16:54
0

I resolved the issue by using this :

disabled="#{editForm.editAccess == 'false'}"

I tried with IE it works. Apparently firefox do not make darken the button.

Nabil Salah
  • 300
  • 3
  • 7
  • 19