Grails portlet没有显示view.gsp,还原为index.gsp

时间:2014-06-06 16:17:12

标签: grails portlet liferay-6

我正在尝试使用grails创建一个基于API的简单API portlet。当我部署它(liferay 6.1.1)时,我找不到“HTTP状态404 - ”/ index.gsp“。”我想我已将URLMappings设置为重定向到 grails-app / views / displayRecent / view.gsp 但它无效。

我甚至没有拆开返回的字符串并使用groovy标签渲染图像。

以下是我认为的锗烷页面/代码片段。

/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")
    }

}

1 个答案:

答案 0 :(得分:0)

你的代码有几个问题,所以如果没有可运行的副本很难说,但你应该修复以下内容......

在DisplayRecentController中你正在做:

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

在视图名称前面加上一个正斜杠,这将导致框架查找:

grails-app/views/view.gsp

而不是:

grails-app/views/displayRecent/view.gsp

在UrlMappings中你有:

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

应该改为:

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