开发者

How to find in GSP from which action of controller its been called?

I am new to grails and i got stuck with another issue.

I have two form's in my single GSP search.gsp and have two actions in my controller serach and results.

Now when i click on search button in one of my GSP file it takes me to search action which renders me search.gsp.At this time it should display me on开发者_开发技巧ly first form in it. when i click results button in that form it will take me to results action.which has code line.

redirect(action:"search",params:[merchants:merchant,address:address])

this will take me back to search action but now i want to display 2nd form in search.gsp..

My problem is

  • how can i make search action once to run with out parameter's and once with parameter's?
  • how to determine in GSP from which action its been called?

with Advance thanks.


Depending on how different your forms are, you may want to consider having two separate GSP files (e.g., search.gsp and results.gsp). Use render(view:'action', model:[...]) to render a different view in the controller. This is often clearer that a single file with lots of conditionals.

Otherwise, you can find out the action using ${params.action}, so for example:

<g:if test="${params.action == 'search'}">
   Text to show if the action is search
</g:if><g:else>
   Text to show if the action is results
</g:else>


I would suggest you to separate your result page as template (_search.gsp), and render it from your result action. So that's how you will have different forms in different files.

By the way template is nothing but an ajax response, google it for detail about template in grails.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜