简体   繁体   中英

Grails portlet not showing view.gsp, reverts to index.gsp

I'm trying to create a simple API based instagram portlet with grails. When I deploy it (liferay 6.1.1) I get a "HTTP Status 404 - "/index.gsp" not found." I think I have the URLMappings set to redirect to grails-app/views/displayRecent/view.gsp but it's not working.

I haven't even gotten to pulling apart the returned string and using a groovy tag to render the image yet.

Below are what I think the germane pages/code snippets.

/grails-app/portlets/Portlet.groovy

import javax.portlet.*
class dispalyRecentPortlet {

 def title = 'CSS Instagram Viewer'
 def description = '''
CSS Instagram Viewer
'''
 def displayName = 'CSS Instagram Viewer'
 def supports = ['text/html':['view']]

 // DEFINITIONS FOR liferay-display.xml
 def liferay_display_category = 'MyCollegePortlets'

 // DEFINITIONS FOR liferay-portlets.xml
 def liferay_portlet_ajaxable = 'true'
 def liferay_portlet_header_portlet_css = [
         '/css/protoFlow.css'
 ]
 def liferay_portlet_header_portlet_javascript = [
         '/plugins/richui-0.5/js/flow/lib/prototype.js',
         '/plugins/richui-0.5/js/flow/lib/scriptaculous.js',
         '/plugins/richui-0.5/js/reflection/reflection.js',
         '/plugins/richui-0.5/js/flow/protoFlow.js'
 ]
}

/CssInstaViewer/grails-app/controllers/cssinstaviewer/DisplayRecentController.groovy

package cssinstaviewer

import groovy.json.*
import grails.converters.JSON

class DisplayRecentController {

    def view() { 

       def apiUrl = new URL("https://api.instagram.com/v1/BUNCHOFSTUFFTHATWORKS/users/")
//     def doc = new JsonSlurper().parseText(apiUrl.text)
//     def jsonObj = new JsonBuilder(doc.data.images.low_resolution[0]).toPrettyString()
       def doc = new JsonSlurper().parseText(apiUrl.json)
       def jsonObj = new JsonBuilder(doc.data.images.low_resolution[0])

                        render(view:"/view", model: [jsonObj: jsonObj as JSON]) 
//     println jsonObj

    }
}

/CssInstaViewer/grails-app/conf/UrlMappings.groovy

import cssinstaviewer.DisplayRecentController;

class UrlMappings {

    static mappings = {
        "/$controller/$action?/$id?"{
            constraints {
                // apply constraints here
            }
        }

        "/"(controller:"DisplayRecentController", action:"view")
        "500"(view:'/error')
    }
}

/CssInstaViewer/grails-app/views/displayRecent/view.gsp

<%@page import="cssinstaviewer.DisplayRecentPortlet"%>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<div>
<h1>View Page</h1>
The map returned by renderView is passed in. Value of jsonObj: ${jsonObj}
    <form method="post" action="${portletResponse.createRenderURL()}">
        <input type="hidden" name="action" value="DisplayRecent"/>
        <input type="submit" value="submit">
    </form>

<g:img src="${jsonObj.url}" width="${jsonObj.width}" height="${jsonObj.height}"/>

</div>

/CssInstaViewer/grails-app/portlets/cssinstaviewer/DisplayRecentPortlet.groovy

package cssinstaviewer
import javax.portlet.*
class DisplayRecentPortlet {
    def title = 'CSS Instagram Viewer'
    def description = '''
CSS Instagram Viewer
'''
    def displayName = 'CSS Instagram Viewer'
    def supports = ['text/html':['view']]
    //uncomment to declare events support
    //def events = [publish: ["event-1"], process: ["event-2"]]
    //uncomment to declare public render parameter support
    //def public_render_params = ["prp-1","prp-2"]
    // Used for liferay
    // @see http://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/anatomy-of-a-portlet
     def liferay_display_category = "category.MyCollegePortlets"
    def actionView = {
        //TODO Define action phase for 'view' portlet mode
        portletResponse.setRenderParameter("prp-1", "value-1");
    }
    def eventView = {
        //TODO Define event phase for 'view' portlet mode.
        def eventValue = portletRequest.event.value
    }
    def renderView = {
        //TODO Define render phase for 'view' portlet mode.
        //Return the map of the variables bound to the view,
        //in this case view.gsp if it exists or render.gsp if not
        ['jsonObj':'jsonObj']
    }
    def resourceView = {
        //TODO define resource phase for 'view' portlet mode.
        //Render HTML as response
        render {
            html {
                head()
                body {
                    "Render me"
                }
            }
        }
    }
    def actionEdit = {
        //TODO Define action phase for 'edit' portlet mode
        portletResponse.setEvent("event-1","event-1")
        portletResponse.setPortletMode(PortletMode.VIEW)
    }
    def renderHelp = {
        //TODO Define render phase for 'help' portlet mode
        //Return the map of the variables bound to the view,
        //in this case help.gsp if it exists or render.gsp if not
        ['mykey':'myvalue']
    }
    def doResource = {
        //TODO Define handling for default resource URL handling method, independent of porlet mode
        //Return the map of the variables bound to the view,
        //in this case resource.gsp
        ['mykey':'myvalue']
    }
    //invoked by setting 'action' param in resourceURL (as an example) to 'doSomethingAjaxy'
    def doSomethingAjaxy =  {
        //render JSON
        render(contentType:"text/json") {
            example(mykey:"myvalue")
        }
    }
    //invoked by setting 'action' param in eventURL (as an example) to 'handleThisEvent'
    def handleThisEvent =  {
        //render thisEvent.gsp
        render(view:"thisEvent")
    }

}

There are several things wrong with your code so it is hard to say without having a runnable copy but you should fix the following...

In DisplayRecentController you are doing:

render(view:"/view", model: [jsonObj: jsonObj as JSON])

When you prefix the view name with a forward slash that will cause the framework to look for:

grails-app/views/view.gsp

instead of:

grails-app/views/displayRecent/view.gsp

In UrlMappings you have:

"/"(controller:"DisplayRecentController", action:"view")

That should be changed to:

"/"(controller:"displayRecent", action:"view")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM