How to setItems in vaadin grid when items are in a map
I am trying to load use this query and the values into a map
LinkedHashMap<SCRegionPriority, String> hash = new LinkedHashMap<>();
pstmt=("SELECT a.Id,a.RegionName,ISNULL(b.Priority,0) as priority
FROM dbo.region a left join dbo.SCMap b on a.Id = b.RegionId
and a.CountryId = b.CountryId and b.SCId=1 where a.CountryId ='1'")
ResultSet rs = pstmt.executeQuery();
con.commit();
while (rs.next()) {
SCPri c = new SCPri();
c.setRegionid(rs.getInt(1));
c.setRegionname(rs.getString(2));
c.setPriority(rs.getInt(3));
hash.put(c, String.valueOf(rs.getInt(3)));
}
the query gives me the following values:
1,0|2,1|3,1|4,2|...
And then I am trying to load this into the vaadin grid like the following:
List<HashMap<SCPri, String>> rows = new ArrayList<>();
LinkedHashMap<SCPri, String> fakeBean1 = subdao1.getSCMap(subcontractor.getId(),subcontractor.getCountryId());
rows.add(fakeBean1);
Grid<HashMap<SCPri, String>> grid2 = new Grid<>();
grid2.setItems(rows);
for (Map.Entry<SCPri, String> entry : s.entrySet()) {
grid2.addColumn(h -> h.get(entry.getKey().getRegionname())).setCaption(entry.getKey().getRegionname());
}
addComponents(grid2);
I am not able to load the grid with the columns dynamically generated and one editable row of with values underneath those columns.
I am trying to make the grid look like the following:
r1|r2|r3|r4
0 |1 |1 |2
I tried to follow the following two links but failed to get it working:
How to fill Vaadin Grid with Map items type
https://vaadin.com/forum/thread/16038356/grid-8-without-bean-class
How can I achieve this?
java vaadin vaadin8 vaadin-grid
add a comment |
I am trying to load use this query and the values into a map
LinkedHashMap<SCRegionPriority, String> hash = new LinkedHashMap<>();
pstmt=("SELECT a.Id,a.RegionName,ISNULL(b.Priority,0) as priority
FROM dbo.region a left join dbo.SCMap b on a.Id = b.RegionId
and a.CountryId = b.CountryId and b.SCId=1 where a.CountryId ='1'")
ResultSet rs = pstmt.executeQuery();
con.commit();
while (rs.next()) {
SCPri c = new SCPri();
c.setRegionid(rs.getInt(1));
c.setRegionname(rs.getString(2));
c.setPriority(rs.getInt(3));
hash.put(c, String.valueOf(rs.getInt(3)));
}
the query gives me the following values:
1,0|2,1|3,1|4,2|...
And then I am trying to load this into the vaadin grid like the following:
List<HashMap<SCPri, String>> rows = new ArrayList<>();
LinkedHashMap<SCPri, String> fakeBean1 = subdao1.getSCMap(subcontractor.getId(),subcontractor.getCountryId());
rows.add(fakeBean1);
Grid<HashMap<SCPri, String>> grid2 = new Grid<>();
grid2.setItems(rows);
for (Map.Entry<SCPri, String> entry : s.entrySet()) {
grid2.addColumn(h -> h.get(entry.getKey().getRegionname())).setCaption(entry.getKey().getRegionname());
}
addComponents(grid2);
I am not able to load the grid with the columns dynamically generated and one editable row of with values underneath those columns.
I am trying to make the grid look like the following:
r1|r2|r3|r4
0 |1 |1 |2
I tried to follow the following two links but failed to get it working:
How to fill Vaadin Grid with Map items type
https://vaadin.com/forum/thread/16038356/grid-8-without-bean-class
How can I achieve this?
java vaadin vaadin8 vaadin-grid
You say that your attempt doesn't work, but you don't mention in what way. Are there compilation errors, and in that case from what part? Are there runtime exceptions, and in that case what are the exception details? Does the wrong thing show up on the screen, and in that case what does it show?
– Leif Åstrand
Nov 23 '18 at 7:51
I am getting only the column names like r1,r2,r3,r4 with one empty row and no values. I dont see any exception or anything as such.
– gopi
Nov 23 '18 at 8:23
add a comment |
I am trying to load use this query and the values into a map
LinkedHashMap<SCRegionPriority, String> hash = new LinkedHashMap<>();
pstmt=("SELECT a.Id,a.RegionName,ISNULL(b.Priority,0) as priority
FROM dbo.region a left join dbo.SCMap b on a.Id = b.RegionId
and a.CountryId = b.CountryId and b.SCId=1 where a.CountryId ='1'")
ResultSet rs = pstmt.executeQuery();
con.commit();
while (rs.next()) {
SCPri c = new SCPri();
c.setRegionid(rs.getInt(1));
c.setRegionname(rs.getString(2));
c.setPriority(rs.getInt(3));
hash.put(c, String.valueOf(rs.getInt(3)));
}
the query gives me the following values:
1,0|2,1|3,1|4,2|...
And then I am trying to load this into the vaadin grid like the following:
List<HashMap<SCPri, String>> rows = new ArrayList<>();
LinkedHashMap<SCPri, String> fakeBean1 = subdao1.getSCMap(subcontractor.getId(),subcontractor.getCountryId());
rows.add(fakeBean1);
Grid<HashMap<SCPri, String>> grid2 = new Grid<>();
grid2.setItems(rows);
for (Map.Entry<SCPri, String> entry : s.entrySet()) {
grid2.addColumn(h -> h.get(entry.getKey().getRegionname())).setCaption(entry.getKey().getRegionname());
}
addComponents(grid2);
I am not able to load the grid with the columns dynamically generated and one editable row of with values underneath those columns.
I am trying to make the grid look like the following:
r1|r2|r3|r4
0 |1 |1 |2
I tried to follow the following two links but failed to get it working:
How to fill Vaadin Grid with Map items type
https://vaadin.com/forum/thread/16038356/grid-8-without-bean-class
How can I achieve this?
java vaadin vaadin8 vaadin-grid
I am trying to load use this query and the values into a map
LinkedHashMap<SCRegionPriority, String> hash = new LinkedHashMap<>();
pstmt=("SELECT a.Id,a.RegionName,ISNULL(b.Priority,0) as priority
FROM dbo.region a left join dbo.SCMap b on a.Id = b.RegionId
and a.CountryId = b.CountryId and b.SCId=1 where a.CountryId ='1'")
ResultSet rs = pstmt.executeQuery();
con.commit();
while (rs.next()) {
SCPri c = new SCPri();
c.setRegionid(rs.getInt(1));
c.setRegionname(rs.getString(2));
c.setPriority(rs.getInt(3));
hash.put(c, String.valueOf(rs.getInt(3)));
}
the query gives me the following values:
1,0|2,1|3,1|4,2|...
And then I am trying to load this into the vaadin grid like the following:
List<HashMap<SCPri, String>> rows = new ArrayList<>();
LinkedHashMap<SCPri, String> fakeBean1 = subdao1.getSCMap(subcontractor.getId(),subcontractor.getCountryId());
rows.add(fakeBean1);
Grid<HashMap<SCPri, String>> grid2 = new Grid<>();
grid2.setItems(rows);
for (Map.Entry<SCPri, String> entry : s.entrySet()) {
grid2.addColumn(h -> h.get(entry.getKey().getRegionname())).setCaption(entry.getKey().getRegionname());
}
addComponents(grid2);
I am not able to load the grid with the columns dynamically generated and one editable row of with values underneath those columns.
I am trying to make the grid look like the following:
r1|r2|r3|r4
0 |1 |1 |2
I tried to follow the following two links but failed to get it working:
How to fill Vaadin Grid with Map items type
https://vaadin.com/forum/thread/16038356/grid-8-without-bean-class
How can I achieve this?
java vaadin vaadin8 vaadin-grid
java vaadin vaadin8 vaadin-grid
edited Nov 22 '18 at 17:06
James Z
11.2k71935
11.2k71935
asked Nov 22 '18 at 15:28
gopigopi
63
63
You say that your attempt doesn't work, but you don't mention in what way. Are there compilation errors, and in that case from what part? Are there runtime exceptions, and in that case what are the exception details? Does the wrong thing show up on the screen, and in that case what does it show?
– Leif Åstrand
Nov 23 '18 at 7:51
I am getting only the column names like r1,r2,r3,r4 with one empty row and no values. I dont see any exception or anything as such.
– gopi
Nov 23 '18 at 8:23
add a comment |
You say that your attempt doesn't work, but you don't mention in what way. Are there compilation errors, and in that case from what part? Are there runtime exceptions, and in that case what are the exception details? Does the wrong thing show up on the screen, and in that case what does it show?
– Leif Åstrand
Nov 23 '18 at 7:51
I am getting only the column names like r1,r2,r3,r4 with one empty row and no values. I dont see any exception or anything as such.
– gopi
Nov 23 '18 at 8:23
You say that your attempt doesn't work, but you don't mention in what way. Are there compilation errors, and in that case from what part? Are there runtime exceptions, and in that case what are the exception details? Does the wrong thing show up on the screen, and in that case what does it show?
– Leif Åstrand
Nov 23 '18 at 7:51
You say that your attempt doesn't work, but you don't mention in what way. Are there compilation errors, and in that case from what part? Are there runtime exceptions, and in that case what are the exception details? Does the wrong thing show up on the screen, and in that case what does it show?
– Leif Åstrand
Nov 23 '18 at 7:51
I am getting only the column names like r1,r2,r3,r4 with one empty row and no values. I dont see any exception or anything as such.
– gopi
Nov 23 '18 at 8:23
I am getting only the column names like r1,r2,r3,r4 with one empty row and no values. I dont see any exception or anything as such.
– gopi
Nov 23 '18 at 8:23
add a comment |
1 Answer
1
active
oldest
votes
A single row with empty cells implies that the value provider callback for each cell returns null
(or ""
).
In your case, the value provider callback is h -> h.get(entry.getKey().getRegionname())
. Here, h
represents the row object, i.e. your single HashMap<SCPri, String>
instance. I'm assuming getRegionname()
returns something like a String
, which would surely cause null
results from h.get()
since h
uses SCPri
instances as they key. Changing the callback to h -> h.get(entry.getKey())
instead might do the trick.
It is an unfortunate leftover from the pre-generics times that Map::get
accepts any Object
without compilation errors instead of requiring you to pass an instance of the actual key type of the map.
Oh yes,entry.getKey()
worked and i got the values. . I just have one more doubt regarding this. How can I set inline editor for this row as I am getting an error saying I cannot do it this way and need to add the mapping if I try to set using this linegrid.addColumn(h -> h.get(entry.getKey())).setEditable(true).setEditorComponent(tf,h -> h.get(entry.getKey())).setCaption(entry.getKey().getRegionname());
Please suggest
– gopi
Nov 23 '18 at 10:50
Second parameter ofsetEditorComponent
is a setter, not a getter. You could try something like(h, value) -> h.put(entry.getKey(), value))
– Leif Åstrand
Nov 23 '18 at 12:41
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%2f53434129%2fhow-to-setitems-in-vaadin-grid-when-items-are-in-a-map%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
A single row with empty cells implies that the value provider callback for each cell returns null
(or ""
).
In your case, the value provider callback is h -> h.get(entry.getKey().getRegionname())
. Here, h
represents the row object, i.e. your single HashMap<SCPri, String>
instance. I'm assuming getRegionname()
returns something like a String
, which would surely cause null
results from h.get()
since h
uses SCPri
instances as they key. Changing the callback to h -> h.get(entry.getKey())
instead might do the trick.
It is an unfortunate leftover from the pre-generics times that Map::get
accepts any Object
without compilation errors instead of requiring you to pass an instance of the actual key type of the map.
Oh yes,entry.getKey()
worked and i got the values. . I just have one more doubt regarding this. How can I set inline editor for this row as I am getting an error saying I cannot do it this way and need to add the mapping if I try to set using this linegrid.addColumn(h -> h.get(entry.getKey())).setEditable(true).setEditorComponent(tf,h -> h.get(entry.getKey())).setCaption(entry.getKey().getRegionname());
Please suggest
– gopi
Nov 23 '18 at 10:50
Second parameter ofsetEditorComponent
is a setter, not a getter. You could try something like(h, value) -> h.put(entry.getKey(), value))
– Leif Åstrand
Nov 23 '18 at 12:41
add a comment |
A single row with empty cells implies that the value provider callback for each cell returns null
(or ""
).
In your case, the value provider callback is h -> h.get(entry.getKey().getRegionname())
. Here, h
represents the row object, i.e. your single HashMap<SCPri, String>
instance. I'm assuming getRegionname()
returns something like a String
, which would surely cause null
results from h.get()
since h
uses SCPri
instances as they key. Changing the callback to h -> h.get(entry.getKey())
instead might do the trick.
It is an unfortunate leftover from the pre-generics times that Map::get
accepts any Object
without compilation errors instead of requiring you to pass an instance of the actual key type of the map.
Oh yes,entry.getKey()
worked and i got the values. . I just have one more doubt regarding this. How can I set inline editor for this row as I am getting an error saying I cannot do it this way and need to add the mapping if I try to set using this linegrid.addColumn(h -> h.get(entry.getKey())).setEditable(true).setEditorComponent(tf,h -> h.get(entry.getKey())).setCaption(entry.getKey().getRegionname());
Please suggest
– gopi
Nov 23 '18 at 10:50
Second parameter ofsetEditorComponent
is a setter, not a getter. You could try something like(h, value) -> h.put(entry.getKey(), value))
– Leif Åstrand
Nov 23 '18 at 12:41
add a comment |
A single row with empty cells implies that the value provider callback for each cell returns null
(or ""
).
In your case, the value provider callback is h -> h.get(entry.getKey().getRegionname())
. Here, h
represents the row object, i.e. your single HashMap<SCPri, String>
instance. I'm assuming getRegionname()
returns something like a String
, which would surely cause null
results from h.get()
since h
uses SCPri
instances as they key. Changing the callback to h -> h.get(entry.getKey())
instead might do the trick.
It is an unfortunate leftover from the pre-generics times that Map::get
accepts any Object
without compilation errors instead of requiring you to pass an instance of the actual key type of the map.
A single row with empty cells implies that the value provider callback for each cell returns null
(or ""
).
In your case, the value provider callback is h -> h.get(entry.getKey().getRegionname())
. Here, h
represents the row object, i.e. your single HashMap<SCPri, String>
instance. I'm assuming getRegionname()
returns something like a String
, which would surely cause null
results from h.get()
since h
uses SCPri
instances as they key. Changing the callback to h -> h.get(entry.getKey())
instead might do the trick.
It is an unfortunate leftover from the pre-generics times that Map::get
accepts any Object
without compilation errors instead of requiring you to pass an instance of the actual key type of the map.
answered Nov 23 '18 at 8:55
Leif ÅstrandLeif Åstrand
1,860510
1,860510
Oh yes,entry.getKey()
worked and i got the values. . I just have one more doubt regarding this. How can I set inline editor for this row as I am getting an error saying I cannot do it this way and need to add the mapping if I try to set using this linegrid.addColumn(h -> h.get(entry.getKey())).setEditable(true).setEditorComponent(tf,h -> h.get(entry.getKey())).setCaption(entry.getKey().getRegionname());
Please suggest
– gopi
Nov 23 '18 at 10:50
Second parameter ofsetEditorComponent
is a setter, not a getter. You could try something like(h, value) -> h.put(entry.getKey(), value))
– Leif Åstrand
Nov 23 '18 at 12:41
add a comment |
Oh yes,entry.getKey()
worked and i got the values. . I just have one more doubt regarding this. How can I set inline editor for this row as I am getting an error saying I cannot do it this way and need to add the mapping if I try to set using this linegrid.addColumn(h -> h.get(entry.getKey())).setEditable(true).setEditorComponent(tf,h -> h.get(entry.getKey())).setCaption(entry.getKey().getRegionname());
Please suggest
– gopi
Nov 23 '18 at 10:50
Second parameter ofsetEditorComponent
is a setter, not a getter. You could try something like(h, value) -> h.put(entry.getKey(), value))
– Leif Åstrand
Nov 23 '18 at 12:41
Oh yes,
entry.getKey()
worked and i got the values. . I just have one more doubt regarding this. How can I set inline editor for this row as I am getting an error saying I cannot do it this way and need to add the mapping if I try to set using this line grid.addColumn(h -> h.get(entry.getKey())).setEditable(true).setEditorComponent(tf,h -> h.get(entry.getKey())).setCaption(entry.getKey().getRegionname());
Please suggest– gopi
Nov 23 '18 at 10:50
Oh yes,
entry.getKey()
worked and i got the values. . I just have one more doubt regarding this. How can I set inline editor for this row as I am getting an error saying I cannot do it this way and need to add the mapping if I try to set using this line grid.addColumn(h -> h.get(entry.getKey())).setEditable(true).setEditorComponent(tf,h -> h.get(entry.getKey())).setCaption(entry.getKey().getRegionname());
Please suggest– gopi
Nov 23 '18 at 10:50
Second parameter of
setEditorComponent
is a setter, not a getter. You could try something like (h, value) -> h.put(entry.getKey(), value))
– Leif Åstrand
Nov 23 '18 at 12:41
Second parameter of
setEditorComponent
is a setter, not a getter. You could try something like (h, value) -> h.put(entry.getKey(), value))
– Leif Åstrand
Nov 23 '18 at 12:41
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.
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%2f53434129%2fhow-to-setitems-in-vaadin-grid-when-items-are-in-a-map%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
You say that your attempt doesn't work, but you don't mention in what way. Are there compilation errors, and in that case from what part? Are there runtime exceptions, and in that case what are the exception details? Does the wrong thing show up on the screen, and in that case what does it show?
– Leif Åstrand
Nov 23 '18 at 7:51
I am getting only the column names like r1,r2,r3,r4 with one empty row and no values. I dont see any exception or anything as such.
– gopi
Nov 23 '18 at 8:23