Announcement Announcement Module
Collapse
No announcement yet.
Java backed webscript renderer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Java backed webscript renderer

    hi,

    I created my application with :
    http://www.springsurf.org/sites/1.0....beginning.html

    It builds fine. but i want to use java backed web scripts.

    so i started following this example :
    http://wiki.alfresco.com/wiki/Java-b...cripts_Samples

    so i created:
    org.springframework.extensions.webscripts.custom-webscripts-context.xml


    Code:
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
    
    <beans>
    
    	<bean id="webscript.webscripts.quick-links.side.get" 
    		class="entertainment.quicklink.QuickLink"
    		parent="webscript">
    	</bean>
    
    </beans>

    created : entertainment.quicklink.QuickLink
    Code:
    package entertainment.quicklink;
    
    import java.io.IOException;
    
    import org.json.JSONException;
    import org.json.JSONObject;
    import org.springframework.extensions.webscripts.AbstractWebScript;
    import org.springframework.extensions.webscripts.WebScriptException;
    import org.springframework.extensions.webscripts.WebScriptRequest;
    import org.springframework.extensions.webscripts.WebScriptResponse;
    
    public class QuickLink extends AbstractWebScript{
    
        public void execute(WebScriptRequest req, WebScriptResponse res)throws IOException{
        	
        	try
        	{
    	    	// build a json object
    	    	JSONObject obj = new JSONObject();
    	    	
    	    	// put some data on it
    	    	obj.put("field1", "data1");
    	    	
    	    	// build a JSON string and send it back
    	    	String jsonString = obj.toString();
    	    	res.getWriter().write(jsonString);
        	}
        	catch(JSONException e)
        	{
        		throw new WebScriptException("Unable to serialize JSON");
        	}   
    	}
    }
    and the script desc :
    side.get.desc.xml

    Code:
    <webscript>
      <shortname>Quick Links</shortname>
      <description>Quick Links</description>
      <url>/home/side</url>
      <authentication>none</authentication>
      <format default="json">argument</format>
    </webscript>
    if i go to the page http://localhost:8180/home/side
    i get : {"field1":"data1"}

    so all seems well, but if i go to my home.xml under pages/home/
    and add the component :

    Code:
    <?xml version='1.0' encoding='UTF-8'?>
    <page>
       <id>home</id>
       <title>Home Page</title>
       <template-instance>home</template-instance>
       <authentication>none</authentication>
       <order-id>0</order-id>
       
       <components>
          <component>
             <region-id>main</region-id>
             <url>/home/main</url>
          </component>   
          <component>
             <region-id>side</region-id>
             <url>/home/side</url>
          </component>   
       </components>
       
       <associations>
          <page-association>
             <dest-id>blog</dest-id>
             <assoc-type>child</assoc-type>
          </page-association>
          <page-association>
             <dest-id>downloads</dest-id>
             <assoc-type>child</assoc-type>
          </page-association>
       </associations>
       
    </page>
    I dont see the same result inside the component..., actually i dont see anything.

    Do i need to render it a FTL, JSP ??

    I tried using a file side.get.html.ftl, side.get.json.ftl, but it seems to ignore it .

    Am i missing something? I cant seem to find any help on forums/documentation.

    Thank you

  • #2
    please, anyone to put me in the right direction ?

    thank you

    Comment


    • #3
      The syntax the component you've defined in your page looks correct, and if you're able to access the WebScript URL directly then I can only assume that your pages template .ftl file does not include a <@region id="side" scope="page"/> FreeMarker tag (I'm assuming that it's the "side" region that you're binding the Java backed WebScript component to).

      Its this <@region> tag that actually causes bound components to be rendered.

      Let me know if this is not the issue and I'll try and debug further,

      Regards,
      Dave

      Comment


      • #4
        Hi, thank you for the response.

        At the moment i do not have an ftl file.
        The problem im having is the rendering inside the components of home.xml

        As you can see i defined
        Code:
         
        <component>
                 <region-id>side</region-id>
                 <url>/home/side</url>
        </component>
        inside the home.xml file.

        The webscript is composed of two file, the desc.xml and the java class.
        I have written thousands of javascript webscripts (alfresco) and the only thing i ever needed to do was add a filename.get.html.ftl to the same folder than the desc.

        The ftl is then picked up and all is well.

        But here i have tried using filename.get.json.ftl, filename.get.xml.ftl and filename.get.html.ftl and all of them are ignored.

        I also tried adding a filename.ftl under web-inf/templates/ but nothing, still ignores it.

        do i need to define in spring where the results are to be rendered to ?

        Is there a tutorial ? because i havent managed to find one yet.

        Here is the link to the project (zip format)

        Thank you

        Comment


        • #5
          Looking in your .zip file you do have a home.ftl template file (in your ~/pages/home.xml file you'll see reference to a <template-instance>home</template-instance> - this refers to a the file ~/templates/home.xml which uses the ~/templates/home.ftl file that contains the <@region> FreeMarker tags that will cause the components to get rendered).

          The configuration of your pages/templates looks correct. Are you seeing any output at all in the browser (i.e. is the remainder of the page being rendered correctly)? If it's just the one component that is not being rendered try swapping out the URL for one that does work to double check that the configuration is rendered correctly.

          Comment


          • #6
            It seems its just the one component not showing.

            If i change pages/home/home.xml to :

            Code:
            <?xml version='1.0' encoding='UTF-8'?>
            <page>
               <id>home</id>
               <title>Home Page</title>
               <template-instance>home</template-instance>
               <authentication>none</authentication>
               <order-id>0</order-id>
               
               <components>
                  <component>
                     <region-id>main</region-id>
                     <url>/home/main</url>
                  </component>   
                  <component>
                     <region-id>side</region-id>
                  <!--    <url>/home/side</url> -->
                  <url>/home/main</url>
                  </component>   
               </components>
               
               <associations>
                  <page-association>
                     <dest-id>blog</dest-id>
                     <assoc-type>child</assoc-type>
                  </page-association>
                  <page-association>
                     <dest-id>downloads</dest-id>
                     <assoc-type>child</assoc-type>
                  </page-association>
               </associations>
               
            </page>
            It shows the main component inside the side no problem.

            Any ideas ?

            Comment


            • #7
              I'll see if I can try and reproduce and debug the problem. I've noticed that you're using the M3 release... ideally you should move up to the latest RC.

              Comment


              • #8
                This issue was obviously caused by a bug that existed in M3... I updated your pom.xml file to change:

                Code:
                <dependency>
                    <groupId>org.springframework.extensions.surf</groupId>
                    <artifactId>spring-surf</artifactId>
                    <version>1.0.0.M3</version>
                </dependency>
                to

                Code:
                <dependency>
                    <groupId>org.springframework.extensions.surf</groupId>
                    <artifactId>spring-surf</artifactId>
                    <version>1.0.0-RC2</version>
                </dependency>
                And the side component was rendered correctly.

                Comment


                • #9
                  Perfect.

                  Works fine now !! thank you..

                  Comment

                  Working...
                  X