Announcement Announcement Module
Collapse
No announcement yet.
passing parameters into the component from the page Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • passing parameters into the component from the page

    I found some information on how to pass parameters into a component from the page definition like so...

    <page>
    ...
    <component>
    <region-id>middleRight1</region-id>
    <url>/scripts/urlBasedComponent</url>
    <pageargs>/here/there</pageargs>
    </component>
    ...
    </page>

    I need to access this pageargs value in the webscript javascript controller but am at a loss of how to do it.

    Two main questions are:
    - if the variable is wrapped with <pageargs> then what key do I give to some method to extract that value? or can the term "pageargs" be replaced with any value?

    - what method can be used in the webscript javascript to extract that variable(s) passed in?

    Thanks

    Kris

  • #2
    Page properties tag is used to pass values.

    Code:
    <page> 
       <id>contactpage1</id>
       <description>contact us page with form</description>    
       <title>title.contact</title>
       <template-instance>two-block</template-instance>
       <authentication>none</authentication>
       <components>     
          <component>
             <region-id>left1</region-id>
             <url>/contact/form</url>
             <properties>
                <successAsset>thankyou.html</successAsset>
             </properties>         
          </component>       
          <component>
             <region-id>right1</region-id>
             <url>/content/named</url>
             <properties>
      	     	<asset>location.html</asset>
        	 </properties>         
          </component>       
       </components>
    </page>
    This is then available in the js file as

    Code:
    args.asset
    In Web script Java code you can get it by

    Code:
    RequestContext requestContext = ThreadLocalRequestContext.getRequestContext()
    String asset = requestContext.getPage().getProperty("asset");
    Ainga

    Comment


    • #3
      Many thanks, I am so much closer now but still not there

      args.asset

      does not work, it actually gives a 500 error because the value is null

      further research leaves me wondering where "args" comes from. According to this doc, http://wiki.alfresco.com/wiki/Surf_P...oot-Scoped_API

      args is on the url object

      so shouldn't it be url.args.asset ??

      even that fails as well

      that doesn't seem right because the properties value is not bound to the url node in the page descriptor, seems like it should be

      page.properties["asset"]

      but that fails as well

      I am using the M3 version
      Last edited by [email protected]; Sep 10th, 2010, 05:15 PM.

      Comment


      • #4
        Hi,

        There was a bug in M3 where component properties nested inside page definitions did not get loaded. I have fixed that for RC1 and if you take a nightly build (very stable at the moment!) then it works correctly.

        To clarify, to get args from the page URL, use:
        Code:
        page.url.args["foo"]
        to get properties defined in a page definition from within a component use:
        Code:
        page.properties["foo"]
        to get properties defined in a template definition from within a component use:
        Code:
        template.properties["foo"]
        to get properties defined in a component definition from within a component:
        Code:
        args["foo"]
        Of course you can use .foo dot notation if you prefer.

        Hope this helps!

        Kev

        Comment


        • #5
          If you have defined a UriTemplate then to access the arguments from the URL you would need to use:
          Code:
          page.url.templateArgs["foo"]
          So these arguments will be set based on a matching uriTemplate defined somewhere in your application configuration (typically in your "surf.xml" file). For example:

          Code:
          <config evaluator="string-compare" condition="UriTemplate">
              <uri-templates>
                  <uri-template id="uriTemplate1">/pageid/{pageid}/arg1/{arg1}/arg2/{arg2}</uri-template>
              </uri-templates>
          </config>
          This will make the keys: "pageid", "arg1" and "arg2" available to you. If you set one of the arguments with the key "pageid" then the associated value will be used as the page id of the page to be rendered.

          This can be a more convenient way to retrieve args if you template the urls you want.
          Last edited by kroast; Sep 22nd, 2010, 04:31 AM.

          Comment


          • #6
            Works in 1.0.0-RC1!

            Confirmed. I am able to access properties set within the <component> declaration in page xml (using 1.0.0-RC1):

            Code:
            <page> 
               <id>echo</id>
               <title>echo Page</title>
               <template-instance>threeColumn</template-instance>
               <authentication>none</authentication>
               
                <component>
                  <region-id>middleMain2</region-id>
                  <url>/scripts/echo</url>    
                  <properties>
              	     <greeting>Welcome to Green Energy!</greeting>
                  </properties>    
                </component>
            </page>
            I am then able to access the property in the JavaScript for the "echo" component:

            Code:
            var greeting = instance.properties["greeting"];
             if(greeting != null)
             {
             	model.greeting = greeting;
             } else {
            	 model.greeting = "<null>";
             }

            This is all per the documentation HERE. This did NOT work in 1.0.0-M3.
            Last edited by BoJo; Oct 6th, 2010, 08:35 PM.

            Comment


            • #7
              Hi,

              I know this is an old topic but i need some help.

              Using 1.0.0-RC2

              Im trying to read my custom properties as described here but with a java backed webscript.
              the webscript extends DeclarativeWebScript.

              Code:
              RequestContext requestContext = ThreadLocalRequestContext.getRequestContext()
              String asset = requestContext.getPage().getProperty("asset");
              this will always return null, no matter what. has this changed ?

              Thank you.
              Last edited by LeTom; Jan 28th, 2011, 03:30 PM.

              Comment


              • #8
                Indeed it should work, i'll take a look.

                Kev

                Comment


                • #9
                  We found way to get the property values in the Java controller. The difference I see between what we are doing and what LeTom posted is we are getting the property directly form the WebScriptRequest rather than request.getPage().

                  Set the property in the page declaration:

                  <properties>
                  <cbtLimit>4</cbtLimit>
                  </properties>

                  Access the property from the Java controller:

                  Code:
                     public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
                  
                             .....
                  	        
                  	        // Attempt to get the limit property from the page definition
                  	        String cbtLimitProperty = req.getParameter("cbtLimit");

                  Comment


                  • #10
                    sorry for the delayed response.

                    Yes it works perfectly, thank you

                    Comment


                    • #11
                      Yes it works perfectly, thank you.
                      Last edited by ctnguyen89; Feb 26th, 2011, 12:21 AM.

                      Comment

                      Working...
                      X