S.O. , , , , , .
import play.api.data.Form
import play.api.data.Forms._
case class P1_18(f1: String,f2: String,f3: String,f4: String,f5: String,f6: String,f7: String,f8: String,f9: String,f10: String,f11: String,f12: String,f13: String,f14: String,f15: String,f16: String,f17: String,f18: String)
case class P2_18(f1: String,f2: String,f3: String,f4: String,f5: String,f6: String,f7: String,f8: String,f9: String,f10: String,f11: String,f12: String,f13: String,f14: String,f15: String,f16: String,f17: String,f18: String)
case class P36(f1: String,f2: String,f3: String,f4: String,f5: String,f6: String,f7: String,f8: String,f9: String,f10: String,f11: String,f12: String,f13: String,f14: String,f15: String,f16: String,f17: String,f18: String,f19: String,f20: String,f21: String,f22: String,f23: String,f24: String,f25: String,f26: String,f27: String,f28: String,f29: String,f30: String,f31: String,f32: String,f33: String,f34: String,f35: String,f36: String)
P36 - , , P1/P2 - , , , .
, :
val f = Form(
mapping(
"" -> mapping(
"f1" -> text,
"f2" -> text,
"f3" -> text,
"f4" -> text,
"f5" -> text,
"f6" -> text,
"f7" -> text,
"f8" -> text,
"f9" -> text,
"f10" -> text,
"f11" -> text,
"f12" -> text,
"f13" -> text,
"f14" -> text,
"f15" -> text,
"f16" -> text,
"f17" -> text,
"f18" -> text
)(P1_18.apply)(P1_18.unapply),
"" -> mapping(
"f19" -> text,
"f20" -> text,
"f21" -> text,
"f22" -> text,
"f23" -> text,
"f24" -> text,
"f25" -> text,
"f26" -> text,
"f27" -> text,
"f28" -> text,
"f29" -> text,
"f30" -> text,
"f31" -> text,
"f32" -> text,
"f33" -> text,
"f34" -> text,
"f35" -> text,
"f36" -> text
)(P2_18.apply)(P2_18.unapply)
)(
(p1, p2) =>
P36(
f1 = p1.f1,
f2 = p1.f2,
f3 = p1.f3,
f4 = p1.f4,
f5 = p1.f5,
f6 = p1.f6,
f7 = p1.f7,
f8 = p1.f8,
f9 = p1.f9,
f10 = p1.f10,
f11 = p1.f11,
f12 = p1.f12,
f13 = p1.f13,
f14 = p1.f14,
f15 = p1.f15,
f16 = p1.f16,
f17 = p1.f17,
f18 = p1.f18,
f19 = p2.f1,
f20 = p2.f2,
f21 = p2.f3,
f22 = p2.f4,
f23 = p2.f5,
f24 = p2.f6,
f25 = p2.f7,
f26 = p2.f8,
f27 = p2.f9,
f28 = p2.f10,
f29 = p2.f11,
f30 = p2.f12,
f31 = p2.f13,
f32 = p2.f14,
f33 = p2.f15,
f34 = p2.f16,
f35 = p2.f17,
f36 = p2.f18
)
)(
p => {
val p1 = P1_18(p.f1,p.f2,p.f3,p.f4,p.f5,p.f6,p.f7,p.f8,p.f9,p.f10,p.f11,p.f12,p.f13,p.f14,p.f15,p.f16,p.f17,p.f18)
val p2 = P2_18(p.f19,p.f20,p.f21,p.f22,p.f23,p.f24,p.f25,p.f26,p.f27,p.f28,p.f29,p.f30,p.f31,p.f32,p.f33,p.f34,p.f35,p.f36)
Option(
(p1,p2)
)
}
)
)
: Huh. , , . ? :
val dataSeq = for(i <- 1 to 36) yield s"f${i}" -> s"text no. #${i}"
val filledFormFromMap = f.bind(dataSeq.toMap)
filledFormFromMap.value
// res9: Option[P36] = Some(P36(text no.
. 18 , 18 , . , ObjectMapping source, , key ObjectMapping . , :
val field1 = f1._2.withPrefix(f1._1).withPrefix(key)
, "" - . , , , ObjectMapping 2,
val field1 = f1._2.withPrefix(f1._1).withPrefix(key)
val field2 = f2._2.withPrefix(f2._1).withPrefix(key)
mappings Mapping a Seq[Mapping], , -, , , " , , , , , field.nested.thing, , . , , , (, , ), - , 18 , , apply unapplyto combine things (as opposed to trying to use P36.apply and P36.unapply, as they will not work due to the restriction of the tuple that I consider)