gpt4 book ai didi

android - Grails模板

转载 作者:行者123 更新时间:2023-12-02 15:25:35 25 4
gpt4 key购买 nike

我正在使用grails 2.4.4。我有三个gsp文件。
1._configureMessage(模板)
2._configureProjectId(模板)
3.索引( View )

我在索引中呈现两个模板。但是我收到以下错误。

    Line | Method
->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run . . . in java.lang.Thread

Caused by GroovyPagesException: Error processing GroovyPageView: Error executing tag <g:render>: Error executing tag <g:form>: Error evaluating expression [gcmDeviceInstance.projectId] on line [8]: Cannot get property 'projectId' on null object
->> 527 | runWorker in G:\grails workspace\MDM_2.4.4\MDM\grails-app\views\androidGcmSender\gcmIndex.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Caused by GrailsTagException: Error executing tag <g:render>: Error executing tag <g:form>: Error evaluating expression [gcmDeviceInstance.projectId] on line [8]: Cannot get property 'projectId' on null object
->> 8 | doCall in G:/grails workspace/MDM_2.4.4/MDM/grails-app/views/androidGcmSender/gcmIndex.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

显示的对象gcmDeviceInstace为null。我已将gcmProjectInstance返回到index.gsp。我应该再为模板做一次吗?
我提供了下面的代码。这是我正在尝试使用的android-gcm插件,而且还很新! :)

AndroidGcmSenderController
package mdm
import java.util.List;
import java.util.Map;

class AndroidGcmSenderController {

def androidGcmService
def grailsApplication

def gcmIndex={
def gcmDeviceInstance= new GcmDevice()
gcmDeviceInstance.properties=params
return[gcmDeviceInstance: gcmDeviceInstance]
}

// def configureProjectId={
// def gcmDeviceInstance= new GcmDevice()
// gcmDeviceInstance.properties=params
// gcm
// return[gcmDeviceInstance: gcmDeviceInstance]
// }

def beforeInterceptor = {
if (params.projectId) {
params.tokens = (GcmDevice.findAllByProjectId(params.projectId) +
GcmDevice.findAllByProjectIdIsNull())*.token
}
}

def configureMessage = {
// def gcmDeviceInstance= new GcmDevice()
// gcmDeviceInstance.properties=params
// return[gcmDeviceInstance: gcmDeviceInstance]

params.apiKey = grailsApplication.config.android.gcm.api.key ?: ''
render view:'index', model: params
}

def Index = {
render view:'index', model:params
}

def sendMessage = {
['deviceToken', 'messageKey', 'messageValue'].each {
key -> params[key] = [params[key]].flatten().findAll { it }
}
def messages = params.messageKey.inject([:]) {
currentMessages, currentKey ->
currentMessages << [ (currentKey) : params.messageValue[currentMessages.size()]]
}
flash.message = 'received.message.response'
flash.args = [androidGcmService.sendMessage(messages, params.deviceToken,
params.collapseKey, params.apiKey).toString()]
redirect(action:'index', params: params)
}
}

GcmDevice域
package mdm

class GcmDevice {

String token
String projectId


static constraints = {
token(nullable:false, blank:false, unique:true)
projectId(nullable:true)
}

}

gcmIndex.gsp
<html>
<head>
<meta name="layout" content="main" />
<title><g:message code="sender.title" /></title>
</head>
<body>
<div id="projectIdConfiguration">
<g:render template="androidGcmSender/configureProjectId" />
</div>
<div id="messageConfiguration">
<g:if test="${gcmDeviceInstance.projectId}">
<g:render template="androidGcmSender/configureMessage" />
</g:if>
</div>
<script type="text/javascript">
ajaxifyLink("form[name='projectId']", "#content", "action", "submit", "POST");
jQuery("input[name='projectId']").change(function(e) {
jQuery(form[name='projectId']).submit();
});
</script>
<g:if test="${request.xhr && gcmDeviceInstance.projectId && !flash.message}">
<script type="text/javascript">
jQuery("div#messageConfiguration").show("slide", { direction: "up" }, 300);
jQuery("div#messageConfiguration").effect("bounce", { times: 3, distance: 10 }, 200);
</script>
</g:if>
</body>
</html>

_configureMessage.gsp
<p class="usage"><g:message code="sender.usage.message" /></p>
<g:form name="message" action="sendMessage" controller="AndroidGcmSender">
<g:hiddenField name="projectId" value="${gcmDeviceInstance.projectId}" />
<div class="formEntryContainer">
<div class="labelContainer">
<label for="deviceToken"><g:message code="sender.form.deviceToken"/></label>
</div>
<div class="inputContainer">
<g:each var="token" in="${[deviceToken].flatten()}">
<div class="toDupe">
<g:select name="deviceToken" from="${tokens}" value="${token}" noSelection="['':'-']"/>
</div>
</g:each>
</div>
<div class="actionsContainer">
<button type="button" class="add dupeParam deviceToken">
<img src="${resource(dir: 'images/skin',file:'add.png')}" alt="${message(code:'add')}" border="0" />
</button>
</div>
</div>

<div class="formEntryContainer">
<div class="labelContainer">
<label for="apiKey"><g:message code="sender.form.apiKey"/></label>
</div>
<div class="inputContainer">
<g:textField name="apiKey" value="${apiKey}" />
</div>
<div class="actionsContainer">
</div>
</div>

<div class="formEntryContainer">
<div class="labelContainer">
<label for="collapseKey"><g:message code="sender.form.collapseKey"/></label>
</div>
<div class="inputContainer">
<g:textField name="collapseKey" value="${collapseKey}" />
</div>
<div class="actionsContainer">
</div>
</div>

<div class="formEntryContainer">
<div class="labelContainer">
<g:message code="sender.form.message"/>
</div>
<div class="inputContainer">
<g:each var="key" in="${[messageKey].flatten()}" status="index">
<div class="toDupe">
<div style="display:table"><div style="display:table-row">
<div style="display:table-cell">
<label for="messageKey"><g:message code="sender.form.messageKey" /></label>:
</div>
<div style="display:table-cell">
<g:textField name="messageKey" value="${key}" />
</div>
</div>
<div style="display:table-row">
<div style="display:table-cell">
<label for="messageKey"><g:message code="sender.form.messageValue" /></label>:
</div>
<div style="display:table-cell">
<g:textField name="messageValue" value="${[messageValue].flatten()[index]}" /><br/>
</div>
</div></div>
</div>
</g:each>
</div>
<div class="actionsContainer">
<button type="button" class="add dupeParam">
<img src="${resource(dir: 'images/skin',file:'add.png')}"
alt="${message(code:'add')}" border="0" />
</button>
</div>
</div>

<div class="formEntryContainer">
<div class="submitContainer">
<g:submitButton name="send" value="${message(code:'send')}" />
</div>
</div>
</g:form>

<script type="text/javascript">
jQuery("input[name='multicast']").attr("disabled", "disabled");
jQuery(".actionsContainer button.dupeParam").click(function(e) {
var prev = jQuery(this).parent().prev('.inputContainer');
var toClone = prev.children('.toDupe :first');
toClone.clone().appendTo(prev);
});
ajaxifyLink("form[name='message']", "#content", "action", "submit", "POST");
</script>

_configureProjectID.gsp
<p class="usage"><g:message code="sender.usage.projectId" /></p>
<g:form name="projectId" action="configureMessage" controller="AndroidGcmSender">
<div class="formEntryContainer">
<div class="labelContainer">
<label for="projectId"><g:message code="sender.form.projectId"/></label>
</div>
<div class="inputContainer">
<g:textField name="projectId" value="${gcmDeviceInstance.projectId}" />
</div>
<div class="actionsContainer">
<g:submitButton name="refresh" value="${message(code:'refresh')}" />
</div>
</div>
</g:form>

最佳答案

是的,您必须使用modelg:render属性将数据传递到模板。

例如,将gcmIndex.gsp的第8行更改为:

<g:render template="androidGcmSender/configureProjectId" model="['gcmDeviceInstance':gcmDeviceInstance]"/>

关于android - Grails模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28147006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com