You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Michael Wyraz (JIRA)" <ji...@apache.org> on 2014/08/26 13:09:58 UTC

[jira] [Created] (TAP5-2376) Add a "switch" component

Michael Wyraz created TAP5-2376:
-----------------------------------

             Summary: Add a "switch" component
                 Key: TAP5-2376
                 URL: https://issues.apache.org/jira/browse/TAP5-2376
             Project: Tapestry 5
          Issue Type: New Feature
          Components: tapestry-core
            Reporter: Michael Wyraz
            Priority: Trivial


Like the "if" component, a simple switch component should be added to the set of default components. The documentation in http://tapestry.apache.org/switching-cases.html should be changed accordingly.

Example:


import javax.inject.Inject;

import org.apache.tapestry5.Block;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.SupportsInformalParameters;

@SupportsInformalParameters
public class Switch
{
	@Parameter(required=true)
	protected String value;
	
	@Inject
	protected ComponentResources resources;
	
    Object beginRender(MarkupWriter writer)
    {
    	if (value!=null)
    	{
    		Block block=resources.getBlockParameter(value);
    		if (block!=null) return block;
    	}
    	
        return resources.getBody();
    }

    boolean beforeRenderBody()
    {
        return false;
    }
}





--
This message was sent by Atlassian JIRA
(v6.2#6252)