how to render a response to a specific place on a gsp grails

ironmantis7x

I am new to grails and groovy. I am trying to find out how to render a response from an action in a grails controller IN THE SAME gsp - but in a DIFFERENT SECTION OF THE gsp - as the gsp that takes the request (in this case a web form gsp page)?

any links or turorials or just straight to the point "do this" kind of replies are welcomed.

I tried to google search for it, but I was not sure what to use as a search term and I could not find a concise answer.

========= UPDATE TO QUESTION (INCLUDING SOME CODE) =========

Here is the code I am working with. It is a Grails application in which I am using a bootstrap template (available for free on the internet of course).

Now the actual code itself for functionality works. What I am having an issue with is this:

I have a gsp page that uses a css template and another gsp temlate for layout. I can start the page as inside the gsp+css tempate using this code (snippet) in my gsp page:

<g:layoutBody/>

This allows me to call my calling controller code in this gsp file for the request:

<body>
<g:form name="form" controller="apiStart" id="form">
    <div><g:select name="protocolType" value="restCall" from="${["-select-", "GET", "POST", "PUT", "DELETE"]}"/> &nbsp <label>URL: </label><g:textField name="url" value="${url}" />
    &nbsp <label>username: </label><g:textField name="userName" value="${userName}" />  &nbsp <label>password: </label><g:textField name="passWord" value="${passWord}" /></div>

    %{--<div class="text-field"><label>URL: </label><g:textField name="url" value="${url}" /></div>--}%
    %{--<div class="text-field"><label>username: </label><g:textField name="userName" value="${userName}" /></div>
    <div class="text-field"><label>password: </label><g:textField name="passWord" value="${passWord}" /></div>--}%
    <br>
    <div><label>Use Advanced Parameters?</label><g:checkBox name="useAdvParms" value="${false}" /></div>
    <div class="text-field"><label>Header1: </label><g:textField name="header1" value="${header1}" /> &nbsp <label>Value1: </label><g:textField name="value1" value="${header2}" /></div>
    %{--<div class="text-field"><label>Value1: </label><g:textField name="value1" value="${header2}" /></div>--}%
    <div class="text-field"><label>Header2: </label><g:textField name="header2" value="${header3}" /> &nbsp <label>Value2: </label><g:textField name="value2" value="${header4}" /></div>
    %{--<div class="text-field"><label>Value2: </label><g:textField name="value2" value="${header4}" /></div>--}%
    <br>
    <div class="submit"><g:actionSubmit value="Submit" action="save"/></div>
</g:form>
</body>

And then this gsp code for the response:

<body>
<h3>API Test Results</h3>
API Tested: ${apiStart.url}, Response: ${apiStart.response3}
<br>
%{--<g:textArea name="myField" value="myValue" rows="20" cols="100"/>--}%
<div class="textarea"><label>Output</label><br><g:textArea name="myField" value="${apiStart.result3}"  />
</div>
%{--Responce Code: ${apiStart.response3}<br>--}%
%{--Response: <br> ${apiStart.result3} <br>--}%

</body>

My issue: it works fine as separate pages. I want to render the results of the request on the same page as the calling request.

in the screen shot attached: I want to put the results in the text box where it says "Output Displayed here...." screenshot of gsp page

I assumed templates in grails is the way to go about it. but I get a Java Null pointer exception when I try to insert the template into that part of the code.

Can someone advise and show me the best way to do this?

==================== END of Updated question ===================

thanks.

ironmantis7x

Mike B

You can try using Grails templates. Basically Template is a (reusable) part of a View.
Info:
So you create template file bookTemplate.gsp, put all the gsp/html code in there as usual (but just the part, if it will be used in the body, then don't add html, body, head tags etc.
Example:

<div class="book" id="${book?.id}">
   <div>Title: ${book?.title}</div>
   <div>Author: ${book?.author?.name}</div>
</div>

Then you render that template into the gsp page in places where you want them to be (with a simple grails render tag. And it will simply get compiled (as the code from template would be pasted into gsp view).
Render:

<g:render template="bookTemplate" model="[book: myBook]" />

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Grails and gsp: How to render nested template with the same model/bean?

From Dev

Grails and gsp: How to render nested template with the same model/bean?

From Dev

Grails: render file from assets folder into gsp

From Dev

Grails javascript render from controller to gsp

From Dev

How to inject environments variable into Grails GSP file?

From Dev

How to inject domain constraints into a Grails GSP?

From Dev

Grails 3.0 How to use Javascript in GSP's?

From Dev

How to iterate Map in grails view(gsp)?

From Dev

How to inject environments variable into Grails GSP file?

From Dev

How to show results in a list Grails gsp

From Dev

How to iterate Map in grails view(gsp)?

From Dev

Grails 3.0 How to use Javascript in GSP's?

From Dev

How to set format a string in gsp grails?

From Dev

How to get a response to the same GSP page

From Dev

How to render JSON in Grails?

From Dev

How to avoid extra parameters in grails (GSP page to Controller)

From Dev

How can I exclude a plugin from grails default gsp encoding?

From Dev

How to populate grails gsp select(drop down box) field?

From Dev

How to execute query on grails using params from gsp?

From Dev

How can I exclude a plugin from grails default gsp encoding?

From Dev

How to show String new lines on gsp grails file?

From Dev

Grails: how to set language dynamically in gsp or using js

From Dev

Render JSON from GSP

From Dev

How to render a static file in Grails?

From Dev

Groovy:Xml: How to display Xml response in textarea of gsp page

From Dev

Grails: Asset Pipeline and GSP Templates

From Dev

Grails : Generating PDF from GSP

From Dev

grails: show field of object in gsp

From Dev

Grails is it possible to protect the .gsp files?

Related Related

HotTag

Archive