template navigation using Grails controllers - grails

I am new to Grails and I am trying to get a template navigation bar to be populated dynamically through a controller. I am really close to solving this but seem to have run into a wall lately.
I currently am getting the navigation to populate only when I click on the link for that controller. Every where else the navigation just populates the bullet points for the links. I am probably not referencing the controller correctly in my template but have not found any good examples yet.
using Grails 2.3.3
the controllers are dynamic.
Here is the code for my navigation template
<body>
<!-- Links to the committees go here -->
<div class="leftMenu">
<!-- template of hospitals and there committees goes here -->
<div>
<g:render template="/hospital/committeeTemp" />
</div>
<tr valign="top">
<td>
<a href="index.jsp?nav=main&hosp=<%=hospGiven %>" target="_top">
<img src="/Trustees/static/images/img/navigate.events.gif" border="0">
</a>
</td>
</tr>
<tr valign="top">
<td>
<a href="index.jsp?nav=main&hosp=<%=hospGiven %>" target="_top">
<img src="/Trustees/static/images/img/navigate.news.gif" border="0">
</a>
</td>
</tr>
<tr valign="top">
<td>
<a href="index.jsp?nav=main&hosp=<%=hospGiven %>" target="_top">
<img src="/Trustees/static/images/img/navigate.help.gif" border="0">
</a>
</td>
</tr>
<%-- </table>--%>
</div>
</body>
I am using a nested loop to populate the navigation bar. That code can be found here Grails navigation links nested loop

With a little more knowledge under my belt. I found out that it was only populating on that one page because that is where it was accessing that particular controller's action. So I ended up putting that mapping into ever action in my controller.

Related

The page is validated automatically after I set a validator and every time I want to redirect to another page, I get the error from validator?

I though I have finished working on the page, however, after another round of checking, it seems that the previous working link is not working anymore and every time when clicked, tries to validate the page.
The link is a part of a main master page.
Looks like the Post Back event called from the clicking on the link is trying to validate Date Pickers again.
I have the following logic to build CustomValidator and RadGrid, where I validates RadDatePickers:
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
<div align="center">
<asp:CustomValidator ID="checkForTwoDates" ClientValidationFunction="AtLeastOneDate_ClientValidate" ViewStateMode="Enabled"
EnableClientScript="True" ErrorMessage="At least one date should be selected" runat="server"></asp:CustomValidator>
<table class="moss2Search">
<tr>
<td>
<div runat="server">
<telerik:RadDatePicker RenderMode="Lightweight" ID="RadDatePicker1" width="100%" runat="server" DateInput-Label="Boarding Start Date"></telerik:RadDatePicker>
</div>
</td>
<td>
<div runat="server">
<telerik:RadDatePicker RenderMode="Lightweight" ID="RadDatePicker2" width="100%" runat="server" DateInput-Label="Boarding End Date">
</telerik:RadDatePicker>
</div>
</td>
<td>
<div>
<asp:CheckBox ID="chkMerActive" runat="server" Checked="true"/>Active
</div>
</td>
<td>
<telerik:RadButton RenderMode="Lightweight" runat="server" Text="Search" ID="Button1" OnClick="btnSearch_Click"></telerik:RadButton>
</td>
</tr>
</table>
</div>
</telerik:RadAjaxPanel>
<asp:Label ID="lblMsg" ForeColor="red" runat="server"></asp:Label>
<br />
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="ajaxControl">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="ajaxUpdateControl"></telerik:AjaxUpdatedControl>
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<div>
<telerik:RadGrid RenderMode="Lightweight" runat="server" ID="grdMoss2Merchants" AllowPaging="True" AllowSorting="true" PagerStyle-AlwaysVisible="true" OnNeedDataSource="BindToDatasource">
<ExportSettings IgnorePaging="true">
<Excel WorksheetName="Moss2Merchants" />
</ExportSettings>
</telerik:RadGrid>
</div>
What am I doing wrong or missing?

Calling an Inline Function on a webform inside of mvc application

I am trying to call a function inside of a ListView control Item Template. The function is adding a new row on the event of a group change.
<ItemTemplate>
<%# AddGroupingRowIfParentHasChanged() %>
<tr style="">
<td><asp:Label ID="ClauseLabel" runat="server" Text='<%# Eval("Clause") %>' /></td>
<td><asp:Label ID="ClauseNameLabel" runat="server" Text='<%# Eval("ClauseName") %>' /></td>
<td><asp:Label ID="SortOrderLabel" runat="server" Text='<%# Eval("SortOrder") %>' /></td>
<td><asp:LinkButton ID="btnDeleteClause" runat="server" CssClass="btn btn-sm btn-danger" CommandName="DeleteClause"><i class="fa fa-trash"></i></asp:LinkButton></td>
</tr>
</ItemTemplate>
I am using a webform that resides inside of an MVC application.
The page used to be apart of a webform application, but I am looking to move it into a new MVC application. Due to the overall complexity of the form, I want to avoid redeveloping it as mvc.
The issue is that I am unable to call AddGroupingRowIfParentHasChanged()
the Error that I am getting on this line is, The name 'AddGroupingRowIfParentHasChanged()' does not exist in the current context.
I cannot seem to find any resolution for this.
You should use #foreach for your data source, replace server control by razor syntax like this.
MVC view engine did not support <% %> in razor with version later than 1.0
#foreach(var item in datasource){
<tr style="">
<td><label>#item.Clause</label></td>
<td><label>#item.ClauseName</label></td>
<td><label>#item.SortOrder</label></td>
<td><button Id="btnDeleteClause" class="btn btn-sm btn-danger" ><i class="fa fa-trash"></i></button></td>
</tr>
}
Looks like it was an issue with Visual Studio, when I was copying over code. I commented those lines out, built the solution then re-added those lines and it worked.

Pass one of many objects from view to controller

In an ASP.Net Core web app, I'm passing a List<Parameter> to a view via ViewBag.Parameters. The view also has a SelectParameterViewModel that consists of one property only, an int ParameterId. The objects are then displayed in a table like so (I skipped straight to tbody as the view works fine from a cosmetic perspective):
#model WebApp.Models.ReportViewModels.SelectParameterViewModel
[...]
<tbody>
#foreach (var item in ViewBag.Parameters)
{
<tr>
<td class="col-xs-1">
<form asp-controller="Report" asp-action="Launch">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input asp-for="#Model.ParameterId" type="hidden" value="#item.Id" />
<input type="submit" class="btn btn-primary btn-sm" value="Select" />
</form>
</td>
<td class="col-xs-8">#item.Description</td>
<td class="col-xs-3">
<a asp-action="Edit" asp-route-id="#item.Id">Edit</a> |
<a asp-action="Details" asp-route-id="#item.Id">Details</a> |
<a asp-action="Delete" asp-route-id="#item.Id">Delete</a>
</td>
</tr>
}
</tbody>
I would like the user to click on the button of the chosen table-row and submit either that row's Parameter (preferred) or the Parameter's Id, like I tried to do in this case. I would then do the same with the <a> tags on the third column. The point is that I don't want the user to simply type /Report/Launch/id and run the report, as each user would have its own sets of parameters and should not be allowed to use any of the others', and the ViewBag only contains the list of its Parameter. I can change the view model and/or the receiving controller's argument depending on the solution, both would work. I tried a few versions of the above html, but none would work, while the above returns ParameterId with value 0.
I couldn't find a similar scenario in other SO questions. There were some solutions that involved JavaScript and, correct me if I'm wrong, but that would still show the ParameterId value in the webpage source. While that would be sort-of-ok in this specific case, I have other cases where I definitely would not want that to happen.
What would be an elegant solution to achieve this? Thank you!

Grails controller populated menu with separate main controller view

I am trying to create a membership directory. I have the directory filled out and ready to go. I am using the main.gsp layout and have created the templates for it.
The side navigation bar needs to be populated by the committees and boards that the members belong too. I have created that through a separate domain and controller. The view that it creates makes links that pass search parameters by the committee.id to the member page to sort the list of members.
I am trying to populate that side navigation bar with the committee control throughout the layout of the site but when I got to test out the site that template section does not populate. It just populates when the committee controller page is selected that I created to test my output. I believe that I am missing a call to the controller or some reference that makes this view active throughout the site and not just on the controller page.
I am using Grails v. 2.3.3
Here is the code for the side navigation bar in main.gsp.
<div id="leftNav" >
<g:render template="/common/left_nav" model="[hospital:Hospital]" />
</div>
Here is where the navigation template is called in "_left_nav.gsp".
<div>
<g:render template="/hospital/committee" model="[hospital:Hospital]" />
</div>
Here is where the navigation template is called again in "_committee.gsp".
<%# page import="trustees.Hospital" %>
<div id="hospcomm" class="content scaffold-list" role="navigation">
<table>
<g:each in="${hospitalInstanceList}" status="i" var="hospitalInstance">
<tr>
<td>
<g:link controller="hospital" action="show" id="${hospitalInstance.id}">${fieldValue(bean: hospitalInstance, field: "hospitalName")}</g:link>
<%-- <g:link action="show" id="${hospitalInstance.id}">--%>
<%-- <a href="index.jsp?nav=main&hosp=<%=hospGiven %>" target="_top">--%>
<%-- <img src="/Trustees/static/images/img/navigate.msh_board.gif" border="0">--%>
<%-- </a>--%>
<%-- </g:link> --%>
</td>
</tr>
<tr>
<td>
<ul>
<g:each in="${hospitalInstance.committees}">
<li>
<g:link controller="hospital" action="show" id="${it.id}"> ${it.committeeName} </g:link>
</li>
</g:each>
</ul>
</td>
</tr>
</g:each>
</table>
</div>
The controller for this view is being called dynamically.
Yes. The side navigation bar would only be populated when you access that particular controller's action. You have 2 options, compute this value in every controller's action that would use a view with the side navigation bar or use a filter
If you want this info on every page, I would recommend you trying to make this accessible by using a Filter. You can retrieve hospital everytime a page is loaded.
If you are using a Security plugin, such as Shiro or SpringSecurity as part of your app, you could place this bit there.

Twitter bootstrap modal inside of dropdown

I'm using the twitter boot-strap library within groovy grails and can currently get both modals and dropdowns to work, but not one inside the other. Here's the code I'm writing, it's so close, when I click on something inside of the dropdown, a psuedo modal shows up, it turns the screen black (transparency included in modals) but doesn't display the box with the info I supplied. Also I've noticed upon further inspection with firebug that only the first set of modals are made but the rest aren't, I'm confused why this is the case. Can anyone help?
Code:
<table>
<thead>
<tr>
<g:sortableColumn property="name" title="${message(code: 'course.name.label', default: 'Name')}" />
<g:sortableColumn property="description" title="${message(code: 'course.description.label', default: 'Description')}" />
</tr>
</thead>
<tbody>
<g:each in="${courseInstanceList}" status="i" var="courseInstance">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<td>
<ul class="nav nav-pills">
<li class="dropdown" id="menu${courseInstance.id}">
<a class="dropdown-toggle" data-toggle="dropdown" href="#menu${courseInstance.id}">
${courseInstance.name}
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<g:each in="${courseInstance.hasMany}" var="param">
<a data-toggle="modal", href="#myModal${courseInstance.id}${param.getProperties().key}", id="${courseInstance.id}${param.getProperties().key}">${param.getProperties().key}</a>
<div class="modal" id="myModal${courseInstance.id}${param.getProperties().key}">
<div class="modal-header">
<a class="close" data-dismiss="modal">x</a>
<h3>Students in ${courseInstance.name}</h3>
</div>
<div class="modal-body">
<g:javascript>
$('#myModal${courseInstance.id}${param.getProperties().key}').modal({
keyboard: true
})
$('#myModal${courseInstance.id}${param.getProperties().key}').modal('hide')
</g:javascript>
</div>
<div class="modal-footer">
Close
Save changes
</div>
</div>
</li>
</g:each>
</td>
<td>${fieldValue(bean: courseInstance, field: "description")}</td>
</tr>
</g:each>
</tbody>
</table>
There is a missing <li> element between the g:each and the a reference...but this should not be the point.
I'am using bootstrap with grails too, and I also use a modal within a navbar dropdown button, it works (but takes me several hours...).
I dont know for sure that it matters but i render the modal template outside of the dropdown. I also set the javascript to "modalize" the dialog below the modal div (not inside the modal-body).
Are you sure that everywhere the expression: myModal${courseInstance.id}${param.getProperties().key} is evaluated to same?
Also make sure that you dont import the modal.js manually (it is already imported in bootstrap.js). This caused some weird behaviour.
I'm using <div class="modal hide fade" id="..."> for the modal. This auto hides the div and adds some nice fade transitions (requires transitions.js).
Then the code reduces to: $('#...').modal({
keyboard: true,
show : false
})
Maybe some of these tips helps...
M.

Resources