Grails- Add link href to button - grails

I'm building a simple Grails app for a web development class. For the most part, the app is finished, but I'm having one sticking issue.
On the index page, I have a series of buttons that correspond to the List, Create, and other templates that are built in Grails via scaffolding. How can I dynamically pass on the correct path to the controller action?
In order to do this, I need to get the current page URL and add the proper location. Is that possible to do in Grails or should I stick with jquery or some other ajax solution?

What are you trying to achieve here,
If you want to generate link to controller actions that you can use for button href, you can do it like this,
<button href="${createLink(controller:'foo', action:'bar')}"/>
See the createLink tag
If you want to know controller and action name, ${controllerName} and ${actionName} can be used.

Can you use ${controllerName} to get the name of the current controller?
An alternative might be ${params.controller}, but again, not 100% sure it works in gsps

Related

Struts 2: Navigation of pages through Link

I am using struts2 . I want that after clicking on link on 1st page it should go to 2nd jsp page.How to do that.
Thanks in Advance
First remember one thing since you are working with MCV2 based platform so its never advised to go from a jsp page to another jsp page directly which is being treated as bad practice.(you are not going through proper request cycle)
Request should go through Actions.Struts2 provide a convenient way to help you for such use-cases.
If in your struts config file you do not provide any Action class name framework will create an action class for you on the fly with return type as SUCCESS. This is all you need to do:
<action name=gotoJSP2>
<result>/page2.jsp</result>
</action>
This is all you need and you are good to go.
Though you can go from one JSP to Another but make sure you have no Struts2 tags and any such framework dependence since going form one JSP to another means not calling Struts2 Dispatcher filter and not letting framework to do required work to serve you.

Spring MVC: url passing variable page style not working

I am using spring mvc for my app. So far everything is going all. However, when I get to a page that has a variable in the url (ie, /edit/{id}), the style doesn't work on that page. In addition when I submit the form on that custom path page and try to go to another page (from the controller using the ModelAndView), the style doesn't work on that destination page which is weird cause the style works fine on that when I access it from elsewhere.
I think the reason the style is not working on the destination page is because the url still stay at the custom path with the url passing variable (localhost:8080/app/edit/5).
Late answer, but I've just experienced this myself and am having a few issues. As far as style sheets or JS files (basically any static resource) not being found after using a path variable, I was able to fix that by prefixing all of my style sheet or JS file links with ${pageContext.request.contextPath}. This ensures that the server always searches for them from WebContent, rather than from the offending path variable. I am also now having the issue of not being able to send proper requests to the other pages, but as my controllers only return Strings for the view resolver rather than ModelAndView objects, I'm not sure your solution will fit for me.

Grails tab order

I was recently given a project to modify and I know very little about Grails. All I need to do is edit the code to make it so the user does not have to use a mouse, so I need to set the tab order. How do I do that?
Thanks!
Set the tabindex property on the fields in the .gsp files, just like an HTML page.

How to create reusable component in Struts 2

Hi
I want to make reusable component in/for Struts 2 framework. For example, a login form having validations, authentication on form submission, error display, Forgot password link etc.
I want to create this form in such a way so that it can be placed anywhere within the site and in any site without any changes.
Please suggest what should I use or better if you can provide and reference for the example of such type of components.
Thanks
Krishan Babbar
Why not, this is Model View Controller, source code can be reused, for example if you want to go to another framework, everything you will need to modify is View, because each framework has its specific tags, you could do everything with simple html tags, but this is already a framework problem

Ruby on Rails ajax - dynamically loading all pages

I have a flash media player (similar to lala.com) that needs to continue to stream while people click around. I don't want to use an iframe.
So, I need to dynamically load all site pages with ajax no matter what link people click on.
I've got this working with Rails and JQuery for a single page. With this method I have to place a file.js.erb file for whatever controller is called. Example: example.com/home is called and I have to have an index.js.erb in the views home dir to respond to this.
I used:
http://railscasts.com/episodes/174-pagination-with-ajax
to get this to work on one page, but it wouldn't be DRY at all to copy .js.erb files to every controller.
Is there something I can do with the main application_controller or even with routes.rb?
I found a way to do this. You can load whatever pages you want via the jquery load method.
$('#result').load('ajax/test.html #container');
They will then be placed in the div with the #result id.
You can also specify a page fragment with #container so you only load the part you want.
This allows all your controllers to stay in tact etc with no extra js.
This is really going to impact your visibility to search engines. I also think it will mean you need to think about the flow of your controllers. Rather than having controllers responding with views that represent a page, controllers will respond with snippets of HTML/JSON/etc that get injected into the home page. Your home page acts as a coordinator, loading the content in and out. Perfectly fine to have js.erb files in each view folder ... as they should be returning content specific to an individual controller.

Resources