Scala Lift: how to get ajaxRadio parameters - scala

I have ajaxRadio ineach row of a table.
when this Radio is selected, I want scala function to get two parameters:
1st one is the selected radio, 2nd one is the data key of the row.
my source is as follows:
val radioList = List("wideArea", "oldArea","newArea")
def liftForm(xhtml: NodeSeq): NodeSeq = {
var areaList = newOrderList.map(values =>{
<li id={values(1)} >
<table>
<thead></thead>
<tbody>
<tr class = "real">
<td class="listImage">
<img class="areaImage" src={values(6)}/>
</td>
<td style="vertical-align:top;">
<tr><p class="areaName">{values(4)}</p></tr>
<tr><p class="areaComment">{values(5)}</p></tr>
</td>
<td class="listCheck" >
{ajaxButton(S.?("delete"), () => doDelete(values(1)), "class" -> "button delete")}
</td>
</tr>
<tr>
<td></td>
<td>
{
val it = ajaxRadio[String](radioList,Box.legacyNullTest(values(2)),doRadioChange _).toForm.grouped(4)
for(i <- it)yield(<tr>{i.flatMap(y => <td> {y} </td>)}</tr>)
}
</td>
</tr>
</tbody>
</table>
</li>})
bind("list",xhtml,"areaList" -> <ul>{areaList}</ul>)
By doRadioChange _, I can only get selected radio. How can I get the the 2nd parameter: data key of the row. ie values(1)?

Your functions can close over all of the local state at that point in the function. You should be able to replace doRadioChange _ with:
doRadioChange(_, values(1))
Assuming, of course, that doRadioChange accepts the proper parameters.

Related

How to retrieve the 'Linktext' value of an ActionLink created in a DB Model table?

I have an MVC table that I've created from database query results. The issue that I'm having is that I am trying to create links out of the first column (device/circuit) results that will pass to an .aspx page to display the load history for the circuit that was clicked. I have the links creating and passing to the .aspx page, but the data being displayed is always for the last item.CUIRCUIT returned from the query. Is there any way to retrieve the LinkText from the link that was clicked? Everything that I've seen so far uses static ActionLinks, not variable ones.
As mentioned above, I have tried using the variable item.CIRCUIT LinkText value, and have set a Global Variable to this value to pre-populate a dropdownlist on the .aspx page, but of course I only receive the last Circuit from the list that was returned; not the value of the link that was clicked.
MVC Index code
#model IEnumerable<Mvc.Models.Circuits_View>
#using Mvc.Variables;
…
<div style="max-height:335px;overflow:auto;">
<table class="table table-bordered table-condensed table-striped">
#foreach (var item in Model)
{
<tr>
<td>
#*#Html.DisplayFor(modelItem => item.CIRCUIT)*#
#Html.ActionLink(item.CIRCUIT, null, "AmpLoadDaily", Globals.ddl_cktval1 = item.CIRCUIT, null)
</td>
<td align="right">
#Html.DisplayFor(modelItem => item.IA)
</td>
<td align="right">
#Html.DisplayFor(modelItem => item.IB)
</td>
<td align="right">
#Html.DisplayFor(modelItem => item.IC)
</td>
<td align="right">
#Html.DisplayFor(modelItem => item.IG)
</td>
<td align="right">
#Html.DisplayFor(modelItem => item.KW)
</td>
<td align="right">
#Html.DisplayFor(modelItem => item.KVA)
</td>
<td align="right">
#Html.DisplayFor(modelItem => item.KVAR)
</td>
<td align="right">
#Html.DisplayFor(modelItem => item.PF)
</td>
<td>
#Html.DisplayFor(modelItem => item.STATUS)
</td>
</tr>
}
</table>
</div>
ASPX DropDownList
<asp:DropDownList runat="server" ID="ddlDevice1" DataSourceID ="SqlDataSource_ddlDevice1" DataTextField="CIRCUIT" DataValueField="CIRCUIT"
AppendDataBoundItems="true" AutoPostBack="true" Width="95" OnSelectedIndexChanged="ddlDevice1_SelectedIndexChanged">
<asp:ListItem Text="-Device1-" Value=" " Selected="True">
</asp:ListItem>
</asp:DropDownList>
CodeBehind
if (Globals.ddl_cktval1 != "")
{
ddlDevice1.SelectedValue = Globals.ddl_cktval1;
Globals.ddl_cktval1 = "";
}
I expect the value to be the name of the link clicked, (i.e. Device1, or Device23), not always DeviceLast, (unless that was the link clicked, of course).
It seems that I was able to use an Anonymous Type after all to collect the item.CIRCUIT information for the specific ActionLink desired.
#foreach (var item in Model)
{
<tr>
<td>
#*#Html.DisplayFor(modelItem => item.CIRCUIT)*#
#Html.ActionLink(item.CIRCUIT, null, "AmpLoadDaily", new { device = item.CIRCUIT }, null)
</td>
My issue must have come from getting the Request.QueryString correct in the code behind.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlDevice1.SelectedValue = Request.QueryString["device"];
I am now able to pre-populate the DropDownList on the ASPX page with the value provided from the MVC page. I just need to figure out how to have the SqlDataSource's, (that use the selected value as a parameter), re-runat="server" during the page load, after I set the SelectedValue of the DropDownList to the new value passed. The search continues …

how to save value on table grails?

my image..
http://www.4shared.com/photo/Rj_0Ymdt/1111.html
this is my coding in controller
def simpan(){
def banklimit = new BankLimit()
for(int i = 0; i<params.limitPerDay.size();i++) {
def baaa = CurrencyList.list(params)
banklimit.dayLimit = params.limitPerDay[i].toBigDecimal()
banklimit.alertLimit = (banklimit.dayLimit*0.8)
banklimit.currency = CurrencyList.findBySym(baaa.sym[i])
banklimit.save()
}
return banklimit
}
<table>
<thead>
<tr>
<g:sortableColumn property="sym" title="${message(code: 'banklimit.currency.sym.label', default: 'Simbol')}" />
<g:sortableColumn property="limitday" title="${message(code: 'banklimit.dayLimit.label', default: 'Limit/Day')}" />
</tr>
</thead>
<tbody>
<g:each in="${aaa}" status="i" var="bbb">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td id="${bbb.id}"> ${fieldValue(bean: bbb, field: "sym")}</td>
<td id="${bbb.id}" colspan="2"> <g:textField name="limitPerDay" value="${value}" /></td>
</tr>
</g:each>
<tr>
<td></td>
<td><g:submitButton name="save" value="SAVE" /> <g:actionSubmit action="back" value="BACK" /></td>
</tr>
</tbody>
</table>
i want to save the field on coloum limit /day if i click "SAVE" buttons.
based my coding, when i click save, only the last row was save in database...
example : theres 4 row..
row 1,2,3,4 filled, then i click save..why only 4th rows save in database? row 1 ,2,3 arenot saving?
You have just one banklimit = new BankLimit() but saving it 4 times. it's one object saved 4 times with different values in loop.
You need:
for(int i = 0; i<params.limitPerDay.size();i++) {
def banklimit = new BankLimit()
//.... fill with values
banklimit.save()
}
For client side it's better to make:
<g:each in="${aaa}" status="i" var="bbb">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td>${fieldValue(bean: bbb, field: "sym")}</td>
<td colspan="2"><g:textField name="limitPerDay[${i}]" value="${value}" /></td>
</tr>
</g:each>

Lift - Binding list of values to template

Here is my template -
<div class="lift:Admin.showInvitees">
<tr class="success"> <!-- "success" "error" -->
<td><invitee:name></invitee:name></td>
<td><invitee:description></invitee:description></td>
<td><invitee:status></invitee:status></td>
<td></td>
</tr>
</div>
and here is the snippet -
class Admin {
def showInvitees(in: NodeSeq): NodeSeq = {
val invitees = Invitation.allInvitations
invitees.flatMap{invitee => bind("invitee", in, "name" -> invitee.name.is, "status" -> invitee.status.is, "description" -> invitee.description.is)}
}
}
I checked this question and used the solution. But it's not working for me. Values are not getting bound at all. This is what I get as output -
<tr class="success">
<td><invitee:name></invitee:name></td>
<td><invitee:description></invitee:description></td>
<td><invitee:status></invitee:status></td>
</tr>
Need help binding a list of values to template.
After the first answer I tried this as well -
def showInvitees(in: NodeSeq): NodeSeq = {
val invitees = Invitation.allInvitations
(".invitees" #> invitees.map{ inv =>
".invitee-name" #> inv.name.is &
".invitee-description" #> inv.description.is &
".invitee-status" #> inv.status.is
})(in)
}
Even this is not working-
Template -
<div class="lift:Admin.showInvitees">
<tr class="invitees success"> <!-- "success" "error" -->
<td><span class="invitee-name"></span></td>
<td><span class="invitee-description"></span></td>
<td><span class="invitee-status"></span> </td>
<td></td>
</tr>
</div>
This is the old syntax for binding values. Try the new one:
// snippet
class Admin {
def showInvitees = {
case class Invitee(name: String, descr: String, status: String)
val invitees = List(Invitee("Alex", "for cookies", "ok"), Invitee("Bob", "for beer", "kicked out"))
".invitee" #> invitees.map { i =>
".invitee-name" #> i.name.is &
".invitee-descr" #> i.description.is &
".invitee-status" #> i.status.is
}
}
}
// html
<div class="Admin.showInvitees">
<table>
<tr class="invitee success">
<td><span class="invitee-name"></span></td>
<td><span class="invitee-descr"></span></td>
<td><span class="invitee-status"></span></td>
</tr>
</table>
</div>
// result
<table>
<tbody><tr class="invitee success">
<td>Alex</td>
<td>for cookies</td>
<td>ok</td>
</tr><tr class="invitee success">
<td>Bob</td>
<td>for beer</td>
<td>kicked out</td>
</tr>
</tbody></table>

Lift framework: Not able to render table rows using comet properly

In my web page I have a text box in which user enters an item name that would be sent to server asynchronously, that message would be sent to CometActor then further it adds additional information to it and in the render method it tries to append a new row to existing table on the page asynchronously. Whenever I add an item always new row is getting placed on top of table rather than as table row, after that if I press refresh it is getting placed properly in the table. Here is
<table cellpadding="0" cellspacing="0" border="1" class="display" id="example">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Time</th>
</tr>
</thead>
<tbody class="lift:comet?type=ProvisionComet">
<tr id="tr_content">
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
LiftActor object
object ItemsServer extends LiftActor with ListenerManager {
private var items = Vector[Item]()
private lazy val date: Box[Date] = DependencyFactory.inject[Date] // inject the date
def createUpdate = items
override def lowPriority = {
case s: String => items :+= new Item(items.length + 1, s, date.map(_.toString)); updateListeners()
case _ => None
}
}
Comet Actor
class ItemComet extends CometActor with CometListener {
private var items = Vector[Item]()
def registerWith = ItemsServer
override def lowPriority = {
case v: Vector[Item] => items = v; reRender()
}
def render = "#tr_content *" #> {
items.map(i => {
<td>{i.sNum}</td>
<td>{i.itemName}</td>
<td>{i.updatedTime.toString}</td>
})
}
The result before refresh is
The result after refresh
How to get the correct result without refreshing?
render method is the place where I am adding rows
Try moving the class attribute from tbody to table:
<table class="lift:comet?type=ProvisionComet" cellpadding="0" cellspacing="0" border="1" class="display" id="example">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Time</th>
</tr>
</thead>
<tbody >
<tr id="tr_content">
<td></td>
<td></td>
<td></td>
</tr>
</tbody>

How to filter the dropdown list by using other dropdown list in asp.net MVC web-application

everyone, I encounter a problem when I try to filter the drop down list.
The situation is I wish to filter the Agent dropdown list by using the Company dropdown list in same view/form. Since I need to display the Agents that only belong to the selected Company. But I have no idea to do that.
Any solution, please?
First add Method in Controller as follows
MvcApplication2.Models.MySampleDBEntities db = new Models.MySampleDBEntities();
public ActionResult SearchNames(string ddlcontent)
{
var list = new List<string>();
var nameqry = from n in db.Images
select n.PlayerName;
list.AddRange(nameqry.Distinct());
ViewBag.ddlcontent = new SelectList(list);
var names = from m in db.Images
select m;
if (string.IsNullOrEmpty(ddlcontent))
return View(names);
else//Filter content basedon dropdownlist selected item
return View(names.Where(s => s.PlayerName.Contains(ddlcontent)));
}
then bind it to view as follows
#model IEnumerable<MvcApplication2.Models.Image>
#{
ViewBag.Title = “SearchNames”;
}
<h2>SearchNames</h2>
#using (#Html.BeginForm(“SearchNames”, “Names”, FormMethod.Get))
{
#Html.DropDownList(“ddlcontent”, “All”)<input type=”submit” value=”Filter” />;
}
<table border=”4″ style=”border: medium dashed #FF0000″>
<tr>
<th>
PlayerName
</th>
<th>
Play
</th>
<th>
CountryName
</th>
<th>
Image
</th>
<th></th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.PlayerName)
</td>
<td>
#Html.DisplayFor(modelItem => item.Play)
</td>
<td>
#Html.DisplayFor(modelItem => item.CountryName)
</td>
<td>
<img src=”#item.ImagePath” height=”100″ width=”100″/>
</td>
</tr>
}
</table>
2 options really...either split the server-based form post into multiple steps, or use jquery to handle this behavior JIT