Wicket DropDownChoice selected value
I am trying to get the Id of my selected choice on a DropDownChoice but I get an error..
I know that when I choose a value I just update the model and not the object (reflection).
I expected to get all the values of object "User" through getModelObject() but all i get is a NullPointerException..
I have tried many things according to tutorials and Wicket 8 documentation but nothing seems to work..
My code is like:
// POJO
class User {
private Integer id;
private String name;
[...]
}
// Main.class
private User selected;
ChoiceRenderer<User> choiceRenderer = new ChoiceRenderer<User>("id", "name");
List<User> list = getUsers();
final DropDownChoice<User> dropdown1 = new DropDownChoice<User>("dropdown",
new PropertyModel<User>(this, "selected"), list, choiceRenderer);
Button btn = new Button("btn") {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
RecrRemoteOperations recr = new RecrRemoteOperations();
try {
// NullPointerException!
// Integer id = dropdown.getModel().getObject().getId();
// id: the id of the selected "User" value on dropdown
recr.updateCommand(id);
} catch (Throwable e) {
e.printStackTrace();
}
}
}.setDefaultFormProcessing(false);
private static List<User> getUsers() {
List<User> allUsers = new ArrayList<User>();
[...]
return list;
}
java wicket dropdown
add a comment |
I am trying to get the Id of my selected choice on a DropDownChoice but I get an error..
I know that when I choose a value I just update the model and not the object (reflection).
I expected to get all the values of object "User" through getModelObject() but all i get is a NullPointerException..
I have tried many things according to tutorials and Wicket 8 documentation but nothing seems to work..
My code is like:
// POJO
class User {
private Integer id;
private String name;
[...]
}
// Main.class
private User selected;
ChoiceRenderer<User> choiceRenderer = new ChoiceRenderer<User>("id", "name");
List<User> list = getUsers();
final DropDownChoice<User> dropdown1 = new DropDownChoice<User>("dropdown",
new PropertyModel<User>(this, "selected"), list, choiceRenderer);
Button btn = new Button("btn") {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
RecrRemoteOperations recr = new RecrRemoteOperations();
try {
// NullPointerException!
// Integer id = dropdown.getModel().getObject().getId();
// id: the id of the selected "User" value on dropdown
recr.updateCommand(id);
} catch (Throwable e) {
e.printStackTrace();
}
}
}.setDefaultFormProcessing(false);
private static List<User> getUsers() {
List<User> allUsers = new ArrayList<User>();
[...]
return list;
}
java wicket dropdown
Do you have a getter and a setter forselected
?
– GustavoCinque
Nov 19 '18 at 16:44
Yeah I tried that but the "selected" object is empty..
– user10376560
Nov 19 '18 at 16:47
add a comment |
I am trying to get the Id of my selected choice on a DropDownChoice but I get an error..
I know that when I choose a value I just update the model and not the object (reflection).
I expected to get all the values of object "User" through getModelObject() but all i get is a NullPointerException..
I have tried many things according to tutorials and Wicket 8 documentation but nothing seems to work..
My code is like:
// POJO
class User {
private Integer id;
private String name;
[...]
}
// Main.class
private User selected;
ChoiceRenderer<User> choiceRenderer = new ChoiceRenderer<User>("id", "name");
List<User> list = getUsers();
final DropDownChoice<User> dropdown1 = new DropDownChoice<User>("dropdown",
new PropertyModel<User>(this, "selected"), list, choiceRenderer);
Button btn = new Button("btn") {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
RecrRemoteOperations recr = new RecrRemoteOperations();
try {
// NullPointerException!
// Integer id = dropdown.getModel().getObject().getId();
// id: the id of the selected "User" value on dropdown
recr.updateCommand(id);
} catch (Throwable e) {
e.printStackTrace();
}
}
}.setDefaultFormProcessing(false);
private static List<User> getUsers() {
List<User> allUsers = new ArrayList<User>();
[...]
return list;
}
java wicket dropdown
I am trying to get the Id of my selected choice on a DropDownChoice but I get an error..
I know that when I choose a value I just update the model and not the object (reflection).
I expected to get all the values of object "User" through getModelObject() but all i get is a NullPointerException..
I have tried many things according to tutorials and Wicket 8 documentation but nothing seems to work..
My code is like:
// POJO
class User {
private Integer id;
private String name;
[...]
}
// Main.class
private User selected;
ChoiceRenderer<User> choiceRenderer = new ChoiceRenderer<User>("id", "name");
List<User> list = getUsers();
final DropDownChoice<User> dropdown1 = new DropDownChoice<User>("dropdown",
new PropertyModel<User>(this, "selected"), list, choiceRenderer);
Button btn = new Button("btn") {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
RecrRemoteOperations recr = new RecrRemoteOperations();
try {
// NullPointerException!
// Integer id = dropdown.getModel().getObject().getId();
// id: the id of the selected "User" value on dropdown
recr.updateCommand(id);
} catch (Throwable e) {
e.printStackTrace();
}
}
}.setDefaultFormProcessing(false);
private static List<User> getUsers() {
List<User> allUsers = new ArrayList<User>();
[...]
return list;
}
java wicket dropdown
java wicket dropdown
edited Nov 19 '18 at 16:51
asked Nov 19 '18 at 16:38
user10376560
Do you have a getter and a setter forselected
?
– GustavoCinque
Nov 19 '18 at 16:44
Yeah I tried that but the "selected" object is empty..
– user10376560
Nov 19 '18 at 16:47
add a comment |
Do you have a getter and a setter forselected
?
– GustavoCinque
Nov 19 '18 at 16:44
Yeah I tried that but the "selected" object is empty..
– user10376560
Nov 19 '18 at 16:47
Do you have a getter and a setter for
selected
?– GustavoCinque
Nov 19 '18 at 16:44
Do you have a getter and a setter for
selected
?– GustavoCinque
Nov 19 '18 at 16:44
Yeah I tried that but the "selected" object is empty..
– user10376560
Nov 19 '18 at 16:47
Yeah I tried that but the "selected" object is empty..
– user10376560
Nov 19 '18 at 16:47
add a comment |
2 Answers
2
active
oldest
votes
The problem is in button.setDefaultFormProcessing(false)
. This tells Wicket to not use the submitted values and to not update the models of the FormComponents, i.e. the DropDownChoice won't have model object and thus won't set selected
.
.setDefaultFormProcessing(false)
is usually used for Cancel
buttons, where you just want to leave the form.
Indeed the problem was that function .setDefaultFormProcessing(false).. I copied the DropDownChoice from another page and I didnt pay attention.. :) Thank you martin-g
– user10376560
Nov 20 '18 at 6:54
add a comment |
I am not sure but my problem is very similar to this question
I was told that I don't need to use Ajax but I will try to see if it works
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379070%2fwicket-dropdownchoice-selected-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem is in button.setDefaultFormProcessing(false)
. This tells Wicket to not use the submitted values and to not update the models of the FormComponents, i.e. the DropDownChoice won't have model object and thus won't set selected
.
.setDefaultFormProcessing(false)
is usually used for Cancel
buttons, where you just want to leave the form.
Indeed the problem was that function .setDefaultFormProcessing(false).. I copied the DropDownChoice from another page and I didnt pay attention.. :) Thank you martin-g
– user10376560
Nov 20 '18 at 6:54
add a comment |
The problem is in button.setDefaultFormProcessing(false)
. This tells Wicket to not use the submitted values and to not update the models of the FormComponents, i.e. the DropDownChoice won't have model object and thus won't set selected
.
.setDefaultFormProcessing(false)
is usually used for Cancel
buttons, where you just want to leave the form.
Indeed the problem was that function .setDefaultFormProcessing(false).. I copied the DropDownChoice from another page and I didnt pay attention.. :) Thank you martin-g
– user10376560
Nov 20 '18 at 6:54
add a comment |
The problem is in button.setDefaultFormProcessing(false)
. This tells Wicket to not use the submitted values and to not update the models of the FormComponents, i.e. the DropDownChoice won't have model object and thus won't set selected
.
.setDefaultFormProcessing(false)
is usually used for Cancel
buttons, where you just want to leave the form.
The problem is in button.setDefaultFormProcessing(false)
. This tells Wicket to not use the submitted values and to not update the models of the FormComponents, i.e. the DropDownChoice won't have model object and thus won't set selected
.
.setDefaultFormProcessing(false)
is usually used for Cancel
buttons, where you just want to leave the form.
answered Nov 20 '18 at 6:31


martin-g
12k1825
12k1825
Indeed the problem was that function .setDefaultFormProcessing(false).. I copied the DropDownChoice from another page and I didnt pay attention.. :) Thank you martin-g
– user10376560
Nov 20 '18 at 6:54
add a comment |
Indeed the problem was that function .setDefaultFormProcessing(false).. I copied the DropDownChoice from another page and I didnt pay attention.. :) Thank you martin-g
– user10376560
Nov 20 '18 at 6:54
Indeed the problem was that function .setDefaultFormProcessing(false).. I copied the DropDownChoice from another page and I didnt pay attention.. :) Thank you martin-g
– user10376560
Nov 20 '18 at 6:54
Indeed the problem was that function .setDefaultFormProcessing(false).. I copied the DropDownChoice from another page and I didnt pay attention.. :) Thank you martin-g
– user10376560
Nov 20 '18 at 6:54
add a comment |
I am not sure but my problem is very similar to this question
I was told that I don't need to use Ajax but I will try to see if it works
add a comment |
I am not sure but my problem is very similar to this question
I was told that I don't need to use Ajax but I will try to see if it works
add a comment |
I am not sure but my problem is very similar to this question
I was told that I don't need to use Ajax but I will try to see if it works
I am not sure but my problem is very similar to this question
I was told that I don't need to use Ajax but I will try to see if it works
answered Nov 19 '18 at 19:06
user10376560
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379070%2fwicket-dropdownchoice-selected-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you have a getter and a setter for
selected
?– GustavoCinque
Nov 19 '18 at 16:44
Yeah I tried that but the "selected" object is empty..
– user10376560
Nov 19 '18 at 16:47