Missing classpath resource '/dojo-0.4.3/dojo2.js'

2008年02月20日

Missing classpath resource '/dojo-0.4.3/dojo2.js'

Tapestry4.1.5 bug

http://article.gmane.org/gmane.comp.jakarta.tapestry.devel/24877
https://issues.apache.org/jira/browse/TAPESTRY-2171

修改
tapestry-framework-4.1.5.jar
org.apache.tapestry.dojo.html包下ScriptIncludes.jwc文件
按照org.apache.tapestry.html.Shell.jwc的写法 使用 jsManager 控制路径

屏蔽掉
<asset name="defaultDojoSource" path="classpath:/dojo-0.4.3/dojo.js" />
<asset name="defaultDojoFormSource" path="classpath:/dojo-0.4.3/dojo2.js" />
<asset name="defaultDojoWidgetSource" path="classpath:/dojo-0.4.3/dojo3.js" />
<asset name="defaultDojoPath" path="classpath:/dojo-0.4.3/" />
<asset name="defaultTapestrySource" path="classpath:/tapestry/core.js" />
<asset name="defaultTapestryPath" path="classpath:/tapestry/" />
增加
<inject property="valueConverter" object="service:tapestry.coerce.ValueConverter" />
<inject property="pageService" object="engine-service:page" />
<inject property="applicationSpecification" object="infrastructure:applicationSpecification" />
<inject property="baseTagWriter" object="service:tapestry.url.BaseTagWriter" />
<inject property="jsManager" object="service:tapestry.js.JavascriptManager" />
修改

<parameter name="tapestrySource" default-value="asset:defaultTapestrySource">
        <description>
            If specified, allows for the default tapestry source included to be overriden.
        </description>
    </parameter>
   
    <parameter name="tapestryPath" default-value="asset:defaultTapestryPath">
        <description>
            Sets the tapestry path, needed for dojo to properly detect and find tapestry js modules
            when overriding the default dojo bundled with tapestry.
        </description>
    </parameter>
   
    <parameter name="dojoSource" default-value="asset:defaultDojoSource">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoFormSource" default-value="asset:defaultDojoFormSource">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoWidgetSource" default-value="asset:defaultDojoWidgetSource">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoPath" default-value="asset:defaultDojoPath">
        <description>
            Specifies the default path to the root dojo folder, not the dojo.js file itself. This is
            used by the djConfig.baseRelativePath javascript configuration variable in dojo.
        </description>
    </parameter>
变为
 <parameter name="tapestrySource" default-value="ognl:jsManager.tapestryAsset">
        <description>
            If specified, allows for the default tapestry source included to be overriden.
        </description>
    </parameter>
   
    <parameter name="tapestryPath" default-value="ognl:jsManager.tapestryPath">
        <description>
            Sets the tapestry path, needed for dojo to properly detect and find tapestry js modules
            when overriding the default dojo bundled with tapestry.
        </description>
    </parameter>
   
    <parameter name="dojoSource" default-value="ognl:jsManager.firstAsset">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoFormSource" default-value="ognl:jsManager.firstFormAsset">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoWidgetSource" default-value="ognl:jsManager.firstWidgetAsset">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoPath" default-value="ognl:jsManager.path">
        <description>
            Specifies the default path to the root dojo folder, not the dojo.js file itself. This is
            used by the djConfig.baseRelativePath javascript configuration variable in dojo.
        </description>
    </parameter>   

修改Tapestry3在{yourServlet}.application配置加载存在于classpath中的组件规范

2008年01月18日

修改Tapestry3在{yourServlet}.application配置加载存在于classpath中的组件规范
在Tapestry3中的{yourServlet}.application文件中不能加载配置在classpath中的jwc组件规范

<application name="yourApp" engine-class="org.apache.tapestry.engine.BaseEngine">
 <component-type type="MyComponent" specification-path="/com/yourApp/components/MyComponent.jwc"/>
</application>

这种写法按照常规的应该从classpath拿到组件的规范文件,但Tapestry3中出错拿不到规范文件
tapestry3分别有两个 org.apache.tapestry.IResourceLocation 的实现
org.apache.tapestry.resource.ClasspathResourceLocation
org.apache.tapestry.resource.ContextResourceLocation
分别加载classpath下的资源和webContext下的资源

解决办法
修改org.apache.tapestry.engine.Namespace类

    private IComponentSpecification locateComponentSpecification(String type)
    {
        String path = _specification.getComponentSpecificationPath(type);

        if (path == null)
            throw new ApplicationRuntimeException(
                Tapestry.format("Namespace.no-such-alias", type, getNamespaceId()));

        IResourceLocation location = getSpecificationLocation().getRelativeLocation(path);
        //hack
        if (location.getResourceURL() == null && path.startsWith("/"))
            location = new ClasspathResourceLocation(_specification.getResourceResolver(), path);
        //hack

        return _specificationSource.getComponentSpecification(location);
    }

增加该方法的hack的地方强制从classpath中查找资源