Get data for form from database [message #1817346] |
Wed, 20 November 2019 17:34  |
Eclipse User |
|
|
|
Hi
I'am currently trying to display some user data. For this I set up a UserTablePage, a UserNodePage and a UserForm.
The UserTablePage obviously shows all users in a table. For every user a child page of type UserNodePage is created. The node pages only content is the UserForm, which should display more details than the table.
Everything works fine, except the UserForm. The load() in the UserService looks like this:
public UserFormData load(UserFormData formData) {
String sql = ""
+ "SELECT name "
+ "FROM user_account "
+ "WHERE token = ??? "
+ "INTO :name";
SQL.selectInto(sql, formData);
return formData;
}
This does not work, since I don't know how to get information about the user I'm trying to get data for (the ??? in the query).
I figured I can give the UserNodePage the needed information with this setter/getter:
@FormData
public String getToken() {
return token;
}
@FormData
public void setToken(String token) {
this.token = token;
}
But how can I pass this information to the UserForm?
Some additional information:
To immediatly view the UserForm, I added a ViewHandler:
public class ViewHandler extends AbstractFormHandler {
@Override
protected void execLoad() {
IUserService service = BEANS.get(IUserService.class);
UserFormData formData = new UserFormData();
exportFormData(formData);
formData = service.load(formData);
importFormData(formData);
setEnabledPermission(new UpdateUserPermission());
}
}
The handler gets called in the UserForms constructor:
public UserForm() {
setHandler(new ViewHandler());
}
Best regards and thanks for your help in advance
yannek
|
|
|
Re: Get data for form from database [message #1817368 is a reply to message #1817346] |
Thu, 21 November 2019 09:32   |
Eclipse User |
|
|
|
The Scout backend knows the authenticated user. You could for instance call ServerSession.get().getUserId() in your backend to get the user-ID. The user-ID is set by the AccessControlService#getUserIdOfCurrentSubject. From there it's regular SQL logic: you can lookup the user in the USER_ACCOUNT by its ID. I don't know your data-model: maybe the "token" _is_ the ID? or you need to join over a TOKEN table to find which user-ID belongs to that token? Anyway, you don't need to pass the user from the client to the backend.
|
|
|
Re: Get data for form from database [message #1817378 is a reply to message #1817368] |
Thu, 21 November 2019 12:33   |
Eclipse User |
|
|
|
Thanks for the answer.
Unfortunately I don' need to know which user is currently working/clicking. I need to see details about every user, not only mine.

As you can see on the image, the UserNodePages are there as the UserTablePages children, but the field "Name" on the UserForm is empty because I don't know how to access the token (which is also the primary key of the user table in the database).
|
|
|
|
|
Re: Get data for form from database [message #1851200 is a reply to message #1817346] |
Wed, 30 March 2022 12:41  |
Eclipse User |
|
|
|
Try to see the content of your UserTablePage, UserNodePage, and for your UserForm. Look if there are any mistakes that you oversaw. What are the errors on display? I have a different way of categorizing the data. Last time SALVAGEDATA restored it after a stupid mistake. Don't exhaust the program with too many commands, especially if they are not clear, they can put the whole information in danger. I like the advice Andre gave you. Go to the section "adding form fields", and from there follow every step in detail. Send us some pics if nothing changes.
[Updated on: Fri, 01 April 2022 22:54] by Moderator Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03556 seconds