Search in sources :

Example 1 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project flowlogix by flowlogix.

the class UpdateEvent method checkSession.

@OnEvent(value = CHECK_SESSION_EVENT)
private JSONObject checkSession() {
    JSONObject rv = new JSONObject();
    if (isValidSession() == false) {
        rv.put("reloadPage", true);
        showSessionExpiredMessage = true;
    }
    return rv;
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject)

Example 2 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class SaxTemplateParser method possibleTapestryComponent.

/**
 * @param elementName
 * @param identifiedType
 *         the type of the element, usually null, but may be the
 *         component type derived from element
 */
private void possibleTapestryComponent(TemplateParserState state, String elementName, String identifiedType) {
    String id = null;
    String type = identifiedType;
    String mixins = null;
    int count = tokenStream.getAttributeCount();
    Location location = getLocation();
    List<TemplateToken> attributeTokens = CollectionFactory.newList();
    for (int i = 0; i < count; i++) {
        QName qname = tokenStream.getAttributeName(i);
        if (isXMLSpaceAttribute(qname))
            continue;
        // The name will be blank for an xmlns: attribute
        String localName = qname.getLocalPart();
        if (InternalUtils.isBlank(localName))
            continue;
        String uri = qname.getNamespaceURI();
        String value = tokenStream.getAttributeValue(i);
        Version version = NAMESPACE_URI_TO_VERSION.get(uri);
        if (version != null) {
            if (T_5_4.sameOrEarlier(version)) {
                strictMixinParameters = true;
            }
            if (localName.equalsIgnoreCase(ID_ATTRIBUTE_NAME)) {
                id = nullForBlank(value);
                validateId(id, "Component id '%s' is not valid; component ids must be valid Java identifiers: start with a letter, and consist of letters, numbers and underscores.");
                continue;
            }
            if (type == null && localName.equalsIgnoreCase(TYPE_ATTRIBUTE_NAME)) {
                type = nullForBlank(value);
                continue;
            }
            if (localName.equalsIgnoreCase(MIXINS_ATTRIBUTE_NAME)) {
                mixins = nullForBlank(value);
                continue;
            }
        // Anything else is the name of a Tapestry component parameter
        // that is simply
        // not part of the template's doctype for the element being
        // instrumented.
        }
        attributeTokens.add(new AttributeToken(uri, localName, value, location));
    }
    boolean isComponent = (id != null || type != null);
    if (mixins != null && !isComponent)
        throw new TapestryException(String.format("You may not specify mixins for element <%s> because it does not represent a component (which requires either an id attribute or a type attribute).", elementName), location, null);
    if (isComponent) {
        tokenAccumulator.add(new StartComponentToken(elementName, id, type, mixins, location));
    } else {
        tokenAccumulator.add(new StartElementToken(tokenStream.getNamespaceURI(), elementName, location));
    }
    addDefineNamespaceTokens();
    tokenAccumulator.addAll(attributeTokens);
    if (id != null)
        componentIds.put(id, location);
    processBody(state.insideComponent(isComponent));
}
Also used : Version(org.apache.tapestry5.internal.services.SaxTemplateParser.Version) QName(javax.xml.namespace.QName) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) Location(org.apache.tapestry5.commons.Location)

Example 3 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class PageNameComponentEventResultProcessor method processResultValue.

public void processResultValue(String value) throws IOException {
    Link link = linkSource.createPageRenderLink(value, false);
    primary.processResultValue(link);
}
Also used : Link(org.apache.tapestry5.http.Link)

Example 4 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class ComponentEventImplTest method coerce_context.

@Test
public void coerce_context() {
    ComponentEventCallback handler = mockComponentEventHandler();
    ComponentPageElementResources resources = mockComponentPageElementResources();
    EventContext context = mockEventContext();
    Integer value = new Integer(27);
    Logger logger = mockLogger();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, false);
    train_toClass(resources, "java.lang.Integer", Integer.class);
    train_getCount(context, 2);
    train_get(context, Integer.class, 0, value);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, resources, false, model, logger);
    assertSame(event.coerceContext(0, "java.lang.Integer"), value);
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentPageElementResources(org.apache.tapestry5.internal.structure.ComponentPageElementResources) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 5 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class MutableComponentModelImplTest method add_duplicate_parameters_to_embedded.

@Test
public void add_duplicate_parameters_to_embedded() {
    Resource r = mockResource();
    Logger logger = mockLogger();
    replay();
    MutableComponentModel model = new MutableComponentModelImpl(CLASS_NAME, logger, r, null, false, null);
    MutableEmbeddedComponentModel fred = model.addEmbeddedComponent("fred", "Fred", COMPONENT_CLASS_NAME, false, null);
    fred.addParameter("city", "bedrock");
    try {
        fred.addParameter("city", "slateville");
        unreachable();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "A value for parameter 'city' of embedded component fred (of component class org.example.components.Foo) has already been provided.");
    }
    verify();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) Logger(org.slf4j.Logger) MutableEmbeddedComponentModel(org.apache.tapestry5.model.MutableEmbeddedComponentModel) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)83 ComponentResources (org.apache.tapestry5.ComponentResources)30 ComponentModel (org.apache.tapestry5.model.ComponentModel)16 MarkupWriter (org.apache.tapestry5.MarkupWriter)13 Field (org.apache.tapestry5.Field)12 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)11 Location (org.apache.tapestry5.commons.Location)11 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)11 Type (org.apache.tapestry5.internal.plastic.asm.Type)11 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)11 Messages (org.apache.tapestry5.commons.Messages)10 JSONObject (org.apache.tapestry5.json.JSONObject)10 Request (org.apache.tapestry5.http.services.Request)9 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)9 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)8 Link (org.apache.tapestry5.http.Link)8 Binding (org.apache.tapestry5.Binding)7 ValidationException (org.apache.tapestry5.ValidationException)7 InternalPropertyConduit (org.apache.tapestry5.beanmodel.internal.InternalPropertyConduit)7 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)7