Package org.apache.tapestry5.model

Examples of org.apache.tapestry5.model.EmbeddedComponentModel


    public void multiple_validators_via_specification() throws Exception
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        Validator required = mockValidator();
        Validator minLength = mockValidator();
        TypeCoercer coercer = mockTypeCoercer();
        FieldComponent field = newFieldComponent();
        Messages messages = mockMessages();
        MessageFormatter requiredFormatter = mockMessageFormatter();
        MessageFormatter minLengthFormatter = mockMessageFormatter();
        Object inputValue = "input value";
View Full Code Here


    @Test
    public void validator_with_constraint() throws Exception
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        Validator validator = mockValidator();
        TypeCoercer coercer = mockTypeCoercer();
        FieldComponent field = newFieldComponent();
        Messages messages = mockMessages();
        MessageFormatter formatter = mockMessageFormatter();
        Object inputValue = new Object();
        ComponentResources resources = mockComponentResources();
View Full Code Here

        }

        // Let subclasses do more.
        configure(config);

        renderSupport.addInit("autocompleter", new JSONArray(id, menuId, link.toAbsoluteURI(), config));
    }
View Full Code Here

        "class", "t-autocomplete-menu");
        writer.end();

        Link link = resources.createEventLink(EVENT_NAME);

        JSONObject config = new JSONObject();
        config.put("paramName", PARAM_NAME);
        config.put("indicator", loaderId);

        if (resources.isBound("minChars"))
            config.put("minChars", minChars);

        if (resources.isBound("frequency"))
            config.put("frequency", frequency);

        if (resources.isBound("tokens"))
        {
            for (int i = 0; i < tokens.length(); i++)
            {
                config.accumulate("tokens", tokens.substring(i, i + 1));
            }
        }

        // Let subclasses do more.
        configure(config);
View Full Code Here

        // This may be null for an anonymous component.
        String embeddedId = token.getId();

        String embeddedComponentClassName = null;

        final EmbeddedComponentModel embeddedModel =
                embeddedId == null
                ? null
                : assembler.getModel().getEmbeddedComponentModel(embeddedId);

        if (embeddedId == null)
            embeddedId = assembler.generateEmbeddedId(embeddedType);

        if (embeddedModel != null)
        {
            String modelType = embeddedModel.getComponentType();

            if (InternalUtils.isNonBlank(modelType) && embeddedType != null)
            {
                String message = String.format(
                        "Embedded component '%s' provides a type attribute in the template ('%s') " +
                                "as well as in the component class ('%s'). " +
                                "You should not provide a type attribute in the template when defining an embedded component " +
                                "within the component class.",
                        embeddedId, embeddedType, modelType
                );

                throw new TapestryException(message, token, null);
            }

            embeddedType = modelType;
            embeddedComponentClassName = embeddedModel.getComponentClassName();
        }

        String componentClassName = embeddedComponentClassName;

        // This awkwardness is making me think that the page loader should resolve the component
        // type before invoking this method (we would then remove the componentType parameter).

        if (InternalUtils.isNonBlank(embeddedType))
        {
            // The type actually overrides the specified class name. The class name is defined
            // by the type of the field. In many scenarios, the field type is a common
            // interface,
            // and the type is used to determine the concrete class to instantiate.

            try
            {
                componentClassName = componentClassResolver.resolveComponentTypeToClassName(embeddedType);
            }
            catch (IllegalArgumentException ex)
            {
                throw new TapestryException(ex.getMessage(), token, ex);
            }
        }


        // OK, now we can record an action to get it instantiated.

        EmbeddedComponentAssembler embeddedAssembler =
                assembler.createEmbeddedAssembler(embeddedId,
                                                  componentClassName,
                                                  embeddedModel,
                                                  token.getMixins(),
                                                  token.getLocation());

        addActionForEmbeddedComponent(context, embeddedAssembler, embeddedId, elementName, componentClassName);

        addParameterBindingActions(context, embeddedAssembler, embeddedModel);

        if (embeddedModel != null && embeddedModel.getInheritInformalParameters())
        {
            // Another two-step:  The first "captures" the container and embedded component. The second
            // occurs at the end of the page setup.

            assembler.add(new PageAssemblyAction()
View Full Code Here

     */
    private boolean isPublishedParameter(ComponentModel model,  String parameterName)
  {
      for (String embeddedComponentId : model.getEmbeddedComponentIds())
    {
        EmbeddedComponentModel embeddedComponentModel = model
            .getEmbeddedComponentModel(embeddedComponentId);
        if (embeddedComponentModel.getPublishedParameters().contains(parameterName)) return true;
    }
     
      return false;
  }
View Full Code Here

    private List<String> getPublishedParameters(ComponentModel model)
    {
      List<String> publishedParameters = CollectionFactory.newList();
      for (String embeddedComponentId : model.getEmbeddedComponentIds())
      {
        EmbeddedComponentModel embeddedComponentModel = model.getEmbeddedComponentModel(embeddedComponentId);
          publishedParameters.addAll(embeddedComponentModel.getPublishedParameters());
      }
      return publishedParameters;
    }
View Full Code Here

     
      ComponentModel containerComponentModel = resources.getComponentModel();
     
      for(String embeddedComponentId : containerComponentModel.getEmbeddedComponentIds())
      {
        EmbeddedComponentModel embeddedComponentModel = containerComponentModel
            .getEmbeddedComponentModel(embeddedComponentId);
       
        InternalComponentResources embeddedComponentResources = (InternalComponentResources) resources
            .getEmbeddedComponent(embeddedComponentId).getComponentResources();
        /**
           * If the parameter is not a formal parameter, then the parameter must be a published parameter
           * of an embeddedComponent of the component we are currently examining.
           */
        if(embeddedComponentModel.getPublishedParameters().contains(publishedParameterName)
            && embeddedComponentResources.getComponentModel().isFormalParameter(publishedParameterName))
        {
          return embeddedComponentResources;
        }
       
View Full Code Here

        // This may be null for an anonymous component.
        String embeddedId = token.getId();

        String embeddedComponentClassName = null;

        final EmbeddedComponentModel embeddedModel = embeddedId == null ? null : assembler.getModel()
                .getEmbeddedComponentModel(embeddedId);

        if (embeddedId == null)
            embeddedId = assembler.generateEmbeddedId(embeddedType);

        if (embeddedModel != null)
        {
            String modelType = embeddedModel.getComponentType();

            if (InternalUtils.isNonBlank(modelType) && embeddedType != null)
            {
                throw new TapestryException(
                        PageloadMessages.redundantEmbeddedComponentTypes(embeddedId, embeddedType, modelType), token, null);
            }

            embeddedType = modelType;
            embeddedComponentClassName = embeddedModel.getComponentClassName();
        }

        String componentClassName = embeddedComponentClassName;

        // This awkwardness is making me think that the page loader should resolve the component
        // type before invoking this method (we would then remove the componentType parameter).

        if (InternalUtils.isNonBlank(embeddedType))
        {
            // The type actually overrides the specified class name. The class name is defined
            // by the type of the field. In many scenarios, the field type is a common
            // interface,
            // and the type is used to determine the concrete class to instantiate.

            try
            {
                componentClassName = componentClassResolver.resolveComponentTypeToClassName(embeddedType);
            } catch (RuntimeException ex)
            {
                throw new TapestryException(ex.getMessage(), token, ex);
            }
        }

        // OK, now we can record an action to get it instantiated.

        EmbeddedComponentAssembler embeddedAssembler = assembler.createEmbeddedAssembler(embeddedId,
                componentClassName, embeddedModel, token.getMixins(), token.getLocation());

        addActionForEmbeddedComponent(context, embeddedAssembler, embeddedId, elementName, componentClassName);

        addParameterBindingActions(context, embeddedAssembler, embeddedModel);

        if (embeddedModel != null && embeddedModel.getInheritInformalParameters())
        {
            // Another two-step: The first "captures" the container and embedded component. The second
            // occurs at the end of the page setup.

            assembler.add(new PageAssemblyAction()
View Full Code Here

        // We know that if embeddedId is null, embeddedType is not.

        if (embeddedId == null) embeddedId = generateEmbeddedId(embeddedType, idAllocator);

        final EmbeddedComponentModel embeddedModel = loadingComponentModel
                .getEmbeddedComponentModel(embeddedId);

        if (embeddedModel != null)
        {
            String modelType = embeddedModel.getComponentType();

            if (isNonBlank(modelType) && embeddedType != null)
            {
                Logger log = loadingComponentModel.getLogger();
                log.error(ServicesMessages.compTypeConflict(embeddedId, embeddedType, modelType));
            }

            embeddedType = modelType;
            embeddedComponentClassName = embeddedModel.getComponentClassName();
        }

        if (isBlank(embeddedType) && isBlank(embeddedComponentClassName)) throw new TapestryException(
                ServicesMessages.noTypeForEmbeddedComponent(embeddedId, loadingComponentModel.getComponentClassName()),
                token, null);

        final ComponentPageElement newComponent = pageElementFactory.newComponentElement(page, loadingElement,
                                                                                         embeddedId, embeddedType,
                                                                                         embeddedComponentClassName,
                                                                                         elementName,
                                                                                         token.getLocation());

        addMixinsToComponent(newComponent, embeddedModel, token.getMixins());

        final Map<String, Binding> newComponentBindings = newMap();
        componentIdToBindingMap.put(newComponent.getCompleteId(), newComponentBindings);

        if (embeddedModel != null)
            bindParametersFromModel(embeddedModel, loadingElement, newComponent, newComponentBindings);

        addToBody(newComponent);

        // Remember to load the template for this new component
        componentQueue.push(newComponent);

        // Any attribute tokens that immediately follow should be
        // used to bind parameters.

        addAttributesAsComponentBindings = true;

        // Any attributes (including component parameters) that come up belong on this component.

        activeElementStack.push(newComponent);

        // Set things up so that content inside the component is added to the component's body.

        bodyPageElementStack.push(newComponent);

        // And clean that up when the end element is reached.


        final ComponentModel newComponentModel = newComponent.getComponentResources().getComponentModel();

        // If the component was from an embedded @Component annotation, and it is inheritting informal parameters,
        // and the component in question supports informal parameters, than get those inheritted informal parameters ...
        // but later (this helps ensure that <t:parameter> elements that may provide informal parameters are
        // visible when the informal parameters are copied to the child component).

        if (embeddedModel != null && embeddedModel.getInheritInformalParameters() && newComponentModel.getSupportsInformalParameters())
        {
            final ComponentPageElement loadingElement = this.loadingElement;

            Runnable finalizer = new Runnable()
            {
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.model.EmbeddedComponentModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.