1 Reply Latest reply on Mar 3, 2011 5:46 PM by Rocky S

    Access to composite component attributtes

    Jakub Pawłowski Newbie

      Hi,

       

      I have a composite component on page:

       

          <h:body>

              <dc:demoComponent title="Any string here"/>

          </h:body>

       

      This is definiton of this component:

       

        <!-- INTERFACE -->

        <cc:interface>

            <cc:attribute name="title" required="true"/>

        </cc:interface>



        <!-- IMPLEMENTATION -->

        <cc:implementation>

                  <h:panelGrid>

                      <h:outputText value="#{componentBean.outputVal}"/>

              </h:panelGrid>

        </cc:implementation>

       

      and ManagedBean for this component;

       

      @ManagedBean

      @RequestScoped

      public class ComponentBean {



          private String outputVal;


          // getters and setters

      }

       

      My question is: how to get programatically in componentBean values passed to composite component from main page ? I mean something like this:

       

       CompositeComponent  comp = (CompositeComponent)resolveExpression("#{demoComponent}");

      Map compAttributes = comp.getAttributes();

      String name = compAttributes.get("title");

       

      Thanks for help

      Kuba

        • 1. Access to composite component attributtes
          Rocky S Master

          use action listener or your managed bean itself to get values-

           

          action listener, example-

           

          public class LoginActionListener implements ActionListener {

              public void processAction(ActionEvent event) throws AbortProcessingException {

              UIComponent container = event.getComponent().getNamingContainer();

              String name = (String) ((UIInput)

             container.findComponent("form:name")).getValue();

             String pwd = (String) ((UIInput)

             container.findComponent("form:password")).getValue();

            if (Registrar.isRegistered(name, pwd)) return;

          FacesContext context = FacesContext.getCurrentInstance();

          context.addMessage(container.getClientId(),

          new FacesMessage("Name and password are invalid. Please try again."));

          throw new AbortProcessingException("Invalid credentials");

          }

          }