This discussion is archived
13 Replies Latest reply: Jan 24, 2013 9:04 PM by bigchill RSS

enable/disable via managed bean

bigchill Newbie
Currently Being Moderated
Hi

using jdev 11.1.1.3
Can anyone tell me how to disable/enable a input textfield from a managed bean which should happen on a button click.
The fields are already populated with data and is editable, and is part of a taskflow.

any help will be helpfull

thanks
  • 1. Re: enable/disable via managed bean
    Koen Verhulst Newbie
    Currently Being Moderated
    Hi bigchill,

    a possible solution could be:

    1. create a bean containing following methods & attributes
    public class MyBean
    {
         // initial value
         private boolean disabled= true;
    
         public String doSomething() 
         {
              this.disabled= false;
              return null;
         }
    
         public void setDisabled(boolean pDisabled)
         {
              this.disabled= pDisabled;
         }
    
         public boolean isDisabled()
         {
              return disabled;
         }
    }
    2. Create an instance of the bean on a certain scope (depending on your requirements)
    3. Link the disabled attribute of the input component with the disabled property of the bean and link the "doSomething" bean method with the action attribute of the commandButton:
    <af:inputText label="Some textfield" disabled="#{s_myBean.disabled}"/>
    <af:commandButton action="#{s_myBean.doSomething}"/>
    That's it.

    Kind regards,

    Koen Verhulst
  • 2. Re: enable/disable via managed bean
    KevinAngus Explorer
    Currently Being Moderated
    In addition, you can do it with a partial page refresh by also setting the button to PartialSubmit=true and the PartialTriggers of the text item to be the id of the button.

    Kevin
  • 3. Re: enable/disable via managed bean
    bigchill Newbie
    Currently Being Moderated
    Hi

    I'm trying Koens method now. but the problem is since its baseclass code, I want it to be genric and also I have another method executing on the action. Is there any other way like doing an EL to execute that method which sets the boolean value.
    tia.
  • 4. Re: enable/disable via managed bean
    Mohammad Jabr Guru
    Currently Being Moderated
    Write the method to set the Boolean values in the ActionListener method of the button.
  • 5. Re: enable/disable via managed bean
    KevinAngus Explorer
    Currently Being Moderated
    If the action of the button is simply to disable the text field with no further logic you could use an af:setPropertyListener on the button to set a viewScope boolean attribute e.g.
    <af:setPropertyListener from="true"
                            to="#{viewScope.myTextItemDisabled}"
                            type="action"/>
    Then set the disabled property of the text item to be "#{viewScope.myTextItemDisabled}".

    To make the button toggle you could maybe do something like this:
    <af:setPropertyListener from="#{not viewScope.myTextItemDisabled}"
                            to="#{viewScope.myTextItemDisabled}"
                            type="action"/>
    Kevin
  • 6. Re: enable/disable via managed bean
    Koen Verhulst Newbie
    Currently Being Moderated
    Can't you just call the setDisabled method in your "other method" which is currently defined on the action attribute of the bean?
    Or just use an actionListerer like Mohammad mentioned.

    I suppose you base class does not contain references to the - probably - page specific inputtext which you want to disable?

    Regards,

    Koen Verhulst
  • 7. Re: enable/disable via managed bean
    Koen Verhulst Newbie
    Currently Being Moderated
    +1!
  • 8. Re: enable/disable via managed bean
    Suresh Karunarathne Guru
    Currently Being Moderated
    Hi,
    Declare boolean attribute in bean with getter and setter then it bind to disable property of inputtext and write on actionListner of button to set disable true also set partial trigger the inputtext
  • 9. Re: enable/disable via managed bean
    bigchill Newbie
    Currently Being Moderated
    Yes what you said last is true.
  • 10. Re: enable/disable via managed bean
    bigchill Newbie
    Currently Being Moderated
    Hi Kevin

    This button just disables the fields in the form(except 1), so no toggle effect on button needed. Question I have is what code I use in the button action. Can you explain please

    tia
  • 11. Re: enable/disable via managed bean
    bigchill Newbie
    Currently Being Moderated
    Mohamed and Suresh

    I set this in the action as you said like this

    String ceaseExpr= "#{pageFlowScope.MyBean.attrForCease}";
    MyADFUtil.invokeMethodExpression(ceaseExpr, true, boolean.class);

    but then I get method not found: com......backing.MyBean@13bc38d.attrForCease(boolean)

    Also I set disabled property in textfield to
    disabled="#{pageFlowScope.MyBean.attrForCease}"

    not sure if anything to do with pageflowscope or expression invokation.

    Edited by: bigchill on 24/01/2013 17:21

    Edited by: bigchill on 24/01/2013 17:23
  • 12. Re: enable/disable via managed bean
    bigchill Newbie
    Currently Being Moderated
    I have moved this method into my base class to test and still doesnt seem to work. Probably I'm missing some PRR like what Suresh suggested
  • 13. Re: enable/disable via managed bean
    bigchill Newbie
    Currently Being Moderated
    Hi all, With all your inputs I have managed to solve this issue and its working fine.
    It was bit of everything you guys said.
    Thank you all so much for your help.

    Edited by: bigchill on 24/01/2013 21:02

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points