6 Replies Latest reply on May 6, 2011 4:30 AM by u j

    managedproperty bean settings not shown on page load

    u j Novice

      Maybe this is not a RichFaces issue, but nevertheless:

      I have two view scoped beans to display properties of one bean on a page backed by the other bean. Although the properties are set in the PostConstruct method, on page load the field is not set.

       

      Main bean has managed property with helper bean:

       

          @ManagedProperty(value = "#{locationBean}")

          private LocationBean locationBean;

       

          @PostConstruct

          void init() {

              this.locationBean.setCityName("Ri");

          }

       

      The page uses the helper bean:

       

      <rich:autocomplete id="cityName" minChars="3" mode="ajax"

          value="#{locationBean.cityName}" autocompleteMethod="#{locationBean.suggestCities}"

          selectFirst="false">

          <rich:validator  />

      </rich:autocomplete>

       

      But on page load, the field cityName stays empty, although I checked that the init() method is called beforehand. I also checked that the locationBean sent in a following request is the same as the one injected.

       

      Thanks

        • 1. managedproperty bean settings not shown on page load
          Pavol Pitonak Master

          Hi,

           

          do you use Mojarra or MyFaces?

           

          Palo

          • 2. Re: managedproperty bean settings not shown on page load
            u j Novice

            Hm, not sure. I use JBoss 6 Final. Found this line on the startup:

             

            10:35:38,144 INFO  [JSFImplManagementDeployer] Initialized 3 JSF configurations: [Mojarra-1.2, MyFaces-2.0, Mojarra-2.0]

             

            I program with RichFaces 4 Final. Does RichFaces use or need any of them internally?

             

            I should add that the same happens if I refer to the locationBean with an h:outputLabel.

            However, if in PostConstruct I set a field defined in the main bean, the corresponding content is shown on the page.

             

            Thanks,

            Ulrich

            • 3. Re: managedproperty bean settings not shown on page load
              Pavol Pitonak Master

              Hi,

               

              yes, RichFaces adds some extra features to JSF so you need a JSF implementation (one of MyFaces or Mojarra). Since you're using JBoss 6, no confguration is needed from your side.

               

              1. Do you reference main bean in you page? The bean is not created until it's needed so your init() method won't be called.
              2. Can't you just set cityName in LocationBean's post-construct method?

               

              Palo

              • 4. Re: managedproperty bean settings not shown on page load
                u j Novice

                1. yes I reference both beans on the page. I checked with the debugger that init() is called. If I add in init()

                this.setAnotherProp("xxx")

                (where this is the main bean), xxx is shown on the page!

                 

                2. Well, locationBean is a helper bean with proper xhtml page used by includes in several pages, so it is not aware of being used in the main bean. The helper bean is injected in the main bean, not the other way round. This way I want to achieve a modular, reusable design both with xhtml fragments and corresponding backing beans.

                 

                Thanks

                • 5. Re: managedproperty bean settings not shown on page load
                  u j Novice

                  So, I don't know why it doesn't work, but finally I have found a way.

                   

                  In the main page do:

                   

                                      <ui:include src="/templates/location.xhtml" >

                                          <ui:param name="bean" value="#{searchEstabRequestBean}" />

                                      </ui:include>

                   

                  and in the included page use:

                   

                  <rich:autocomplete id="cityName" minChars="3" mode="ajax"

                      value="#{bean.locationBean.cityName}" autocompleteMethod="#{locationBean.suggestCities}"

                      selectFirst="false" >

                      <rich:validator  />

                  </rich:autocomplete>

                  • 6. managedproperty bean settings not shown on page load
                    u j Novice

                    Strange is the following: with

                     

                    autocompleteMethod="#{bean.locationBean.suggestCities}

                     

                    I get

                     

                    10:22:11,935 GRAVE [org.richfaces.log.Renderkit] Objetivo inalcanzable, identificador 'bean' resuelto a nulo: javax.el.PropertyNotFoundException: Objetivo inalcanzable, identificador 'bean' resuelto a nulo

                        at org.apache.el.parser.AstValue.getTarget(AstValue.java:75) [:6.0.0.Final]

                        at org.apache.el.parser.AstValue.invoke(AstValue.java:183) [:6.0.0.Final]

                        at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) [:6.0.0.Final]

                        at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43) [:6.0.0.Final]

                        at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56) [:6.0.0.Final]

                        at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43) [:6.0.0.Final]

                        at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56) [:6.0.0.Final]

                        at org.richfaces.renderkit.AutocompleteRendererBase.getItems(AutocompleteRendererBase.java:105) [:4.0.0-SNAPSHOT]

                        at org.richfaces.renderkit.AutocompleteRendererBase.encodeItems(AutocompleteRendererBase.java:160) [:4.0.0-SNAPSHOT]

                        at org.richfaces.renderkit.AutocompleteRendererBase.encodeMetaComponent(AutocompleteRendererBase.java:271) [:4.0.0-SNAPSHOT]

                     

                    It means identifier bean is null.

                    Could be a bug. But as it works as expected in the version above, I don't mind so much.