Sending a value through render() in grails controller - model-view-controller

This is probably one very simple question to answer, but I can't output the variable I am trying to send to a view through a controller in the Grails Framework.
render(view: 'parseerror', error: it)
That's my code in my controller, it renders the view correctly but as soon as I am trying to call the variable through ${error} it outputs nothing. It should output a string since when I print the iterator, the console output: The example string
Thanks for helping me out :)

The map key is "errors", not "error", but I belive, you want to achieve something similar to this code:
render( view: 'parseerror', model: [ 'error': error ] )

Related

How I get model attribute in Vue?

How can i get Model Attribute in Vue?
This is My controller in backend(Spring).
#CrossOrigin(origins = "http://localhost:8080")
#PutMapping("/board/postlist")
public String boardList(Model model){
model.addAttribute("posts", postService.findAllDesc());
model.addAttribute("attrTest", "WHATTHOE");
return "IndexController.update() working";
}
postsis a List.First, I guess my list or sth was wrong. So i add another String attribute attrTest but still in problem...
And this is my vue template.
<b-textarea placeholder="${attrTest}"></b-textarea>
And this is part of my vue script.
<script>
export default {
name: "postList",
data: ()=>({
content:'',
author:'',
})
}
</script>
Screen just display ${attrTest}, in text. It doesn't seem recognize variable.
I been searching many solutions but it doesn't work for me. I tried ${} like jquery but also failed. Maybe my project doesn't have jquery... i can't found jquery in my pakage.json too.
In mustache, i just write {{#posts}} for get model atrribution. Also use Axios result succesfuly but is it impossible to get model attribute with Vue solution? like $attr or sth.
Is it necessary to install jquery?
now I don't no where to start. I tried get posts list all day long. I really need help.
If you're using Thymeleaf as view resolver, try th:placeholder

Laravel 5.5 How to read flash data in a view page

My Controller is redirecting to this View with flash data(data from a table row). How do I print for example, just the "titulo" or "resumo"?
Or, instead of sending all the information from a table row to a single variable, do I have to send separately into different variables?
Thanks in advance.
This is the way you can send flash data from the backend:
public function show (){
//some code here
return redirect('/')->with('flash', 'message here');
}
and in the view you can display it like this:
{{session('flash')}}
The above will display "message here".
If you have return redirect('/')->with('alert', 'something happened');
{{session('alert')}}
The above will display "something happened".

Grails remoteFunction ajax assistance

I'm really struggling with getting the percentage value of progress that is continuously being updated in a function on my controller to appear in template GSP page using remoteFunction.
This is my controller code and "progressData" is sent from a service to constantly update the current progress of a task:
def progress(progressData) {
def statusToView = progressData
[statusToView: statusToView]
}
and in my _progress.gsp page:
<g:javascript>
setInterval( "refreshMe();", 300 );
function refreshMe(){
${remoteFunction(action:'progress', controller:'data')}
}
</g:javascript>
The controller is expecting the property progressData which is doesn't get from the remoteFunction, and so I'm guessing I have to think to do this another way but I'm just at a bit of a loss now. Plus I'm not getting the value statusToView within the GSP because of this.
As you pointed out, your action progress is actually waiting for the progressData param, which is not passed.
If your progressData value is stored somewhere in your gsp page, you should change your remoteFunction in this way or similar:
$remoteFunction(action: 'progress', controller: 'data', update: [success: 'great', failure: 'ohno'], params: '\'progressData=\' + progressData')
Regarding update: [success: ... ], here you can find the description of the various attributes.

Razor syntax issue with RenderPartial (CS1501)

The RenderAction is working just fine but as soon as I surround it with a if statement I get a compile error:
#if (#Model.IsConfigurationAllow)
{
#{ Html.RenderAction("Save"); } // CS1501: No overload for method 'Write' takes 0 arguments
}
More general question where can I found the grammar for the Razor view syntax?
Html.RenderAction renders the HTML directly into the response, so you cant call it in a code block.
The counterpart Html.Action returns a string with the results.
See http://haacked.com/archive/2009/11/17/aspnetmvc2-render-action.aspx
Did you try this?
#if (#Model.IsConfigurationAllow)
{
<text>#{ Html.RenderAction("Save"); }</text>
}
There are a few below (more can be found just by googling);
www.w3schools.com
A quick Reference
Introduction of Using Razor Syntax

Syntax Issue- Razor MVC4

I'm trying to display a partial view using a custom helper method. The only problem is, I can't get past this syntax issue. The model set for this cshtml file is an IEnumerable collection of models I've defined as Operation. I'm sure this is an easy fix. Here's an example of what I'm seeing:
I have this block of code:
#using(Html.BeginForm()) {
<div id="editor_rows">
#foreach (var item in Model){
Html.RenderPartial("OperationEditorRow", item);
}
</div>
}
This gives me the following error at runtime:
Unexpected "{" after "#" character. Once inside the body of a code block (#if {}, #{}, etc.) you do not need to use "#{" to switch to code.
But if I remove the # sign in front of the foreach statement, everything is interpreted as plain text. So I tried placing an # in front of Html as follows:
#using(Html.BeginForm()) {
<div id="editor_rows">
#foreach (var item in Model){
#Html.RenderPartial("OperationEditorRow", item);
}
</div>
}
This comes back with a compilation error that says:
Cannot implicitly convert type void to object
If I run the project from here, I get a runtime error that says:
The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments
I'm assuming this is related to the previous error. If anybody has a suggestion for me, please help.
Problem solved. I worked on this with a coworker. It turns out the error refferring to the write method pointed to a problem inside my partial view. I was using #{} around a block of code inside of there, which was most likely throwing the other syntax errors also. Thanks for the responses.
Add {}'s around your render call like #{RenderPartial...}

Resources