password input custom - scala

Greetings
In my User.scala file:
I'm using the next class to customize the password input
The code is the next
import net.liftweb.mapper.MappedPassword
[...]
class User extends MegaProtoUser[User] {
[...]
override def _toForm: Box[NodeSeq] = {
S.fmapFunc({s: List[String] => this.setFromAny(s)}){funcName =>
Full(
<tr>
<td>{S.??("repeat")}</td>
<td><input id={fieldId} type='password' name={funcName} value={is.toString}/> </td>
</tr>
<tr>
<td>{S.??("repeat")}<td>
<td><input type='password' name={funcName} value={is.toString}/></td>
</tr>
)
}
}
[...]
}
the compiler displays the following error:
[ERROR] ....../org/santix/model/User.scala:209: error: value setFromAny is not a member of org.santix.model.User
[INFO] S.fmapFunc({s: List[String] => this.setFromAny(s)}){funcName =>
anyone have any idea?

There's just too little information to answer, but I can see some points here...
First, I imagine you might be copying from some example, since you use this.setFromAny. The code containing this snippet is inside the class User, which extends MegaProtoUser[User]. Alas, MegaProtoUser does not have any method setFromAny, and I imagine your own class User doesn't either, and this is the primary cause of the error.
Now, setFromAny is part of the class MappedPassword, which you import, but doesn't seem to use in any place, so I don't know why you imported it. However, I can see that MegaProtoUser has a member which returns a MappedPassword. This member is called password, so I imagine this might work:
S.fmapFunc({s: List[String] => this.password.setFromAny(s)}){funcName =>

PROBLEM SOLVED!!!!
class User extends MegaProtoUser[User] {
...
override lazy val password = new MyPassword(this) {
override def _toForm: Box[NodeSeq] = {
S.fmapFunc({s: List[String] => this.setFromAny(s)})
{funcName =>
Full(
<tr>
<td>{ passwordDisplayName }</td>
<td>
<input id={fieldId} type='password' name={funcName} value=''/>
<!-- by sanx, value={is.toString} -->
</td>
</tr>
<tr>
<td>{S.??("repeat")}</td>
<td>
<input type='password' name={funcName} value=''/>
</td>
</tr>
)
}
}
}
}

Related

How to use pattern matching in Binding.scala?

I have the following model:
case class CarBinding(ownerId: Var[String], specs: Var[Option[Specs]])
Specs is a trait and has the following concrete types:
trait Specs {
def name: String
}
case class SportsCarSpecs(name: String, details: Details) extends Specs
In my Scala.js app, I now want to create a table and list all the entries:
#dom
def buildTable(): Binding[BindingSeq[Node]] = {
val data = Vars.empty[CarBinding]
/* Initial population. */
// Some code...
<br/>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th class="col-md-1">
<small>Owner ID</small>
</th>
<th class="col-md-1">
<small>Specs</small>
</th>
</tr>
</thead>
<tbody>
{for (entry <- data) yield {
<tr>
<td>
<small>
{entry.ownerId.bind}
</small>
</td>
<td>
<small>
{entry.specs.bind match {
case Some(SportsCarSpecs(name, details)) => {name} <span>{details.ps}</span>
case _ => -
}}
</small>
</td>
</tr>
}}
</tbody>
</table>
</div>
}
However, I get the following error:
';' expected but $XMLSTART$< found.
[error] case Some(SportsCarSpecs(name, details)) => {name} <span>{details.ps}</span>
What am I doing wrong?
This:
entry.specs.bind match {
case Some(SportsCarSpecs(name, details)) => {name} <span>{details.ps}</span>
case _ => -
}
isn't a valid expression, so you can't interpolate it in the XML literal. If you had complete XML expressions in both branches, it should work. So the easiest fix I can see is to pull <small> inside:
<td>
{entry.specs.bind match {
case Some(SportsCarSpecs(name, details)) => <small>{name} <span>{details.ps}</span></small>
case _ => <small>-</small>
}}
</td>

How to deal with implict b3 field constructor with the play scala template?

#(loggedUser: Option[User], loginInfo: Option[LoginInfo], cards: Seq[Card], addCardInput: AddCardInput)(implicit request: RequestHeader, messages: Messages)
#category(card: Card) = {
<tr>
<td>
#b3.form(routes.DeckBuilder.deleteCard()) {
#helper.CSRF.formField
#b3.submit('class -> "btn btn-primary") { Submit }
}
</td>
</tr>
}
#views.html.templates.mainApp(Messages("app.title"), tab = "index", loggedUser = loggedUser, loginInfo = loginInfo)) {
<h2 class="text-primary">Your Cards</h2>
<p class="lead">
#loggedUser.map { user =>
<div class="modal-body">
<table class="table">
<tbody>
#cards.map(grouped => category(grouped))
</tbody>
</table>
</div>
}.getOrElse {
#Html(Messages("index.notLogged", routes.Auth.signIn, routes.Auth.startSignUp)) <br/>
#Html(Messages("index.resetPassword", routes.Auth.startResetPassword))
}
</p>
}
The above code produces error
could not find implicit value for parameter fc:
views.html.b3.B3FieldConstructor
The error points to the line where I am building the submit button. I'm aware that it requires the implicit field constructor and in another file, I've done this successfully, but that was where the form wasn't in a helper method.
You just need to declare the implicit field constructor at the top of your partial (I know - it seems contradictory to declare an implicit.. but this works):
#implicitFieldConstructor = #{ b3.vertical.fieldConstructor }

play frame work and scala : pass parameter value from one page to another

I need to pass parameter with a object to page from another page
Here is my router
GET /Location/edit:locid controllers.Locations.editLocation(locid:Int)
I`m calling from this page
#import models._
#import play.api.Play.current
#import play.api.i18n.Messages.Implicits._
#index(Messages("application.name")+" | Locations"){
<div class="container" style="float:left">
<div class="menu_title">
<h1>Locations</h1>
</div>
<div class="menu_box">
<p>Add new +</p>
</div>
<table class="table table-hover">
<thead>
<tr>
<th>Location ID</th>
<th>Location Name</th>
<th>Ref No</th>
<th></th>
</tr>
</thead>
<tbody>
#for(l <- Location.findAllLocations()){
<form action="#routes.Locations.editLocation(l.id)">
<tr>
<input type="hidden" name="locid" value="#l.id"/>
<td>#l.id</td>
<td>#l.name</td>
<td>#l.ref</td>
<td> <p id="subbut"> <input type="submit" id="logbut" class="btn btn-default" value='Edit'></p></td>
</tr>
</form>
}
</tbody>
</table>
</div>
}
Here is the controller method i use
def editLocation(locid: Int) = Action { implicit request =>
request.session.get("mysession").map { user =>
val form = if (request.flash.get("error").isDefined)
locationForm.bind(request.flash.data)
else
locationForm
Location.findLocationBydb(locid).map { location =>
Ok(views.html.location.editLocation(form,location))
}.getOrElse(NotFound)
}.getOrElse {
Redirect(routes.Users.loginUser())
}
}
here is the Model
def findLocationBydb(id:Int)={
var locations= new ListBuffer[Location]()
val conn = DB.getConnection()
try {
val stmt = conn.createStatement
val rs = stmt.executeQuery("SELECT * from m_locations where idLoc='"+id+"' ")
if (rs.next()) {
locations+= Location(rs.getInt("idLoc"),rs.getString("LocDes"),rs.getString("LocRef"));
}
} finally {
conn.close()
}
locations.toList.head
}
But I got this Error
Read from stdout:
D:\PROJECTS\test\SimpleRequest22-DBCon_Session\app\controllers\Locations.scala:71:
value map is not a member of models.Location
D:\PROJECTS\test\SimpleRequest22-DBCon_Session\app\controllers\Locations.scala:71:
value map is not a member of models.Location Read from stdout:
Location.findLocationBydb(locid).map { location =>
Location.findLocationBydb(locid).map { location => Read from stdout: ^
^ Read from stdout:
D:\PROJECTS\test\SimpleRequest22-DBCon_Session\app\views\location\editLocation.scala.html:7:
not found: value loc
D:\PROJECTS\test\SimpleRequest22-DBCon_Session\app\views\location\editLocation.scala.html:7:
not found: value loc Read from stdout: #(loc:Location) #(loc:Location)
Read from stdout: ^
^ Read from stdout: two errors found two errors found Read from stdout: (compile:compileIncremental) Compilation failed
(compile:compileIncremental) Compilation failed
The error that you get is map is not member of Location. You are trying to use map on Location that is returned by Location.findLocationBydb.
Instead of
Location.findLocationBydb(locid).map { location =>
Ok(views.html.location.editLocation(form,location))
}
use
val location = Location.findLocationBydb(locid)
Ok(views.html.location.editLocation(form,location))
Hi friends I got the solution my self,
First I change the controller method like this
def editLocation(locid: Int) = Action { implicit request =>
request.session.get("mysession").map { user =>
val form = if (request.flash.get("error").isDefined)
locationForm.bind(request.flash.data)
else
locationForm
Ok(views.html.location.editLocation(locationForm,Location.findLocationBydb(locid)))
}.getOrElse {
Redirect(routes.Users.loginUser())
}
}
And also I have changed the view page (editLocation.scala.html) by
#(locationForm: Form[Location],loc:Location)(implicit flash: Flash, lang: Lang)

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>

Scala Lift: how to get ajaxRadio parameters

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.