Page 1 of 1

Adding JS Files to Admin Example

Posted: Mon Jan 27, 2014 10:54 am
by RapidTransit
Following http://github.com/BroadleafCommerce/docs/issues/8

Updated to be a bit more coherent and work with Jrebel.

This guide uses Broadleaf 3.1.0-SNAPSHOT, and this is by no means a way to solve the following issue

Issue: I want the application to handle generating my URL's

Solution: The following Javascript File named "category-extension.js"

Code: Select all

$(document).ready(function(){
    $("body").keyup( function()
    {
        var inputString = $("#fields\\'name\\'\\.value").val();
        var pattern =
        $("#fields\\'url\\'\\.value").val('/' + inputString.replace(/\s/g, '-')
            .replace(/&/g, 'and')
            .replace(/#/g, 'No')
            .replace(/\./g,'')
            .replace(/'/g, ''));

        });
});


    In your Admin module, under your webapp directory, add a directory called "js" without quotes.

    Place your Javascript file under "/js"


    Now open your applicationContext-admin.xml

    Put the following before the "blJsResources" Bean:

    This tells BLC where my JS files are located with the Bean id of "blMyAdminJsLocations"

    Code: Select all

    <bean id="blMyAdminJsLocations" class="org.springframework.beans.factory.config.ListFactoryBean">
            <property name="sourceList">
                <list>
                    <value>/js/</value>
                </list>
            </property>
        </bean>


    This tells BLC to merge the additional location "blMyAdminJsLocations" with the frameworks, "blJsLocations"

    Code: Select all

    <bean class="org.broadleafcommerce.common.extensibility.context.merge.LateStageMergeBeanPostProcessor">
            <property name="collectionRef" value="blMyAdminJsLocations" />
            <property name="targetRef" value="blJsLocations" />
        </bean>



    Add this before the "blJsFileMap" bean:

    This maps the file to the bean "blMyAdminJsFileList" if your file is under another sub directory say your path to the file is /admin/js/category/category-extension.js then your value would be "category/category-extension.js"

    Code: Select all

     <bean id="blMyAdminJsFileList" class="org.springframework.beans.factory.config.ListFactoryBean" >
            <property name="sourceList">
                <list>
                    <value>category-extension.js</value>
                </list>
            </property>
        </bean>

    Merge the bean "blMyAdminJsFileList" to the "blJsFileList" (Contains a record of all the files to load)

    Code: Select all

    <bean class="org.broadleafcommerce.common.extensibility.context.merge.LateStageMergeBeanPostProcessor">
            <property name="collectionRef" value="blMyAdminJsFileList" />
            <property name="targetRef" value="blJsFileList" />
        </bean>


    All the JS files relative URLs are auto pre-pended with "admin/js/" under the default configuration