[
https://issues.apache.org/jira/browse/WICKET-6350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15947795#comment-15947795
]
Joachim Rohde commented on WICKET-6350:
---------------------------------------
Seems like today is not my day. You are right that it would make more sense to
make the FormComponent required if it is a primitive class. Especially since
the message originally used double negation before it was changed with
https://github.com/apache/wicket/commit/3c15f4be7ea4ac1e421453e840501fe40a033866
But then I'm questioning the whole check. Since a FormComponent is as default
not required the check is only executed if I explicitly call setRequired(false)
which would result in a WicketRuntimeException. If I omit the call I would have
the same behaviour (a non-required FormComponent), except that it would not
result in a WicketRuntimeException and I would get the default value for the
provided primitive type. That is not consistent.
At the moment I would say the complete check can be deleted.
> setRequired checks for primitive type only when the FormComponent is NOT
> required
> ---------------------------------------------------------------------------------
>
> Key: WICKET-6350
> URL: https://issues.apache.org/jira/browse/WICKET-6350
> Project: Wicket
> Issue Type: Bug
> Components: wicket
> Affects Versions: 8.0.0-M4
> Reporter: Joachim Rohde
> Priority: Minor
>
> I was tinkering around with Kotlin and Wicket and had the following snippet:
> val housenumbervalue: Int? = null
> val housenumberModel: IModel<Int> = Model<Int>()
> val housenumber = TextField<Int>("housenumberModel", housenumberModel,
> Int::class.java)
> val form: Form<Unit> = object : Form<Unit>("adressForm") {}
> override fun onInitialize() {
> super.onInitialize()
> form.add(housenumber.setRequired(false))
> form.add(object : SubmitLink("submit") {
> override fun onSubmit() {
> super.onSubmit()
> println(housenumberModel.`object`)
> }
> })
> add(form)
> }
> This code resulted in
> org.apache.wicket.WicketRuntimeException: FormComponent can't be required
> when the type is primitive class: [TextField [Component id =
> housenumberModel]]
> at
> org.apache.wicket.markup.html.form.FormComponent.setRequired(FormComponent.java:1052)
> at com.mycompany.test.web.pages.Test.onInitialize(Test.kt:28)
> Turns out that setRequired was checking only if the FormComponent was *not*
> required. It should be the other way round. I opened a pull request.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)