3 Replies Latest reply on Mar 30, 2013 6:37 PM by Radim Hanus

    a4j:ajax CDI render issue

    Luca Becarelli Newbie

      hello,

      i have this simple xhtml page:

       

      <h:form prependId="false">

           <h:selectBooleanCheckbox value="#{richBean.enabled}">

                <a4j:ajax event="change" render="richPnl"></a4j:ajax>

           </h:selectBooleanCheckbox>

           <rich:panel id="richPnl">

                <h:panelGroup id="input" >

                     <h:outputLabel value="Name:" for="nameInput" />

                     <h:inputText id="nameInput" value="#{richBean.name}" rendered="#{richBean.enabled}">

                          <a4j:ajax event="keyup" render="output" />

                     </h:inputText>

                </h:panelGroup>

                <h:panelGroup id="output">

                     <h:outputText value="Hello #{richBean.name}!" rendered="#{not empty richBean.name}" />

                </h:panelGroup>

           </rich:panel>

      </h:form>

       

      the issue is that the setName() of rechBean don't is activated when insert char on his input field.

      If i remove the rendered attribut of nameInput  all works correctly.

      The richBean is :

       

      @Named

      @Stateful

      @ConversationScoped

      public class RichBean implements Serializable {

          private static final long serialVersionUID = -6239437588285327644L;

          private String name;

          private boolean enabled;

          public boolean isEnabled() {

              return enabled;

          }

          public void setEnabled(boolean enabled) {

              this.enabled = enabled;

          }

          @PostConstruct

          public void postContruct() {

              name = "John";

          }

          public String getName() {

              return name;

          }

          public void setName(String name) {

              this.name = name;

          }

       

      I have noted that all works correctly if i replace

      @Named

      @Stateful

      @ConversationScoped

       

      with

      @ViewScoped

      @ManagedBean

       

      thanks for any help

       

      Regards

       

      Luca

        • 1. Re: a4j:ajax CDI render issue
          Radim Hanus Expert

          you define conversation scope but you did'nt start that scope so that your statefull bean is not connected with http session in no way

          your last scenario works because view scoped managed beans are available untill you navigate to another facelet

           

          moreover using ejb statefull beans if you don't use transactions, persistence, caching, ...  has no effect, they are usually used only in specific use cases, for instance jpa extended persistence context

           

          last but no least don't mix jsf managed beans with cdi beans, see this great article for details

          • 2. Re: a4j:ajax CDI render issue
            Luca Becarelli Newbie

            Please give me the link to the article, i will read it with interest.

            I have cdi beans because i try to work with CRUD application generated from forge UI scaffold  (the bean that you see is a semplificated bean only for example) and @Stateful

            @ConversationScoped CDI bean is the bean that forge create for manage an entity.

             

             

            Please can you give me more detail of what you mean when you say "you define conversation scope but you did'nt start that scope so that your statefull bean is not connected with http session in no way"?

             

            Thanks for all.

            Luca

            • 3. Re: a4j:ajax CDI render issue
              Radim Hanus Expert

              sorry the link is missing, the article is here

              Please can you give me more detail of what you mean when you say "you define conversation scope but you did'nt start that scope so that your statefull bean is not connected with http session in no way"?

              see weld reference guide chapter 5.3

              note both conversation.begin() and conversation.end() calls in conversation demarcation sample

              1 of 1 people found this helpful