Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Get data for form from database
Get data for form from database [message #1817346] Wed, 20 November 2019 17:34 Go to next message
Yannek Flick is currently offline Yannek FlickFriend
Messages: 2
Registered: November 2019
Junior Member
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 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
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.

Eclipse Scout Homepage | Documentation | GitHub
Re: Get data for form from database [message #1817378 is a reply to message #1817368] Thu, 21 November 2019 12:33 Go to previous messageGo to next message
Yannek Flick is currently offline Yannek FlickFriend
Messages: 2
Registered: November 2019
Junior Member
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.

https://i.imgur.com/CTTDxND.jpg

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 #1817390 is a reply to message #1817378] Thu, 21 November 2019 14:15 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
I see. Well that's exactly what is explained in the Scout Beginners Guide, Chapter 4.6. Adding a Form to Create/Edit Persons. . You should Take a look at the Contacts application, which does the same thing. The source-code is hosted here, check out the PersonForm. As you can see, the personId is passed to that Form and annotated with @FormData. In the execLoad() method a FormData with that personId is passed to the server, where you can access the personId again and use it in a SQL statement.

Eclipse Scout Homepage | Documentation | GitHub
Re: Get data for form from database [message #1850109 is a reply to message #1817390] Wed, 16 February 2022 09:12 Go to previous messageGo to next message
elane lown is currently offline elane lownFriend
Messages: 1
Registered: February 2022
Junior Member
Does UserTablePage show all user processes? Are you displaying users of different computers or users of the same computer?
Re: Get data for form from database [message #1851200 is a reply to message #1817346] Wed, 30 March 2022 12:41 Go to previous message
ferra  rutu is currently offline ferra rutuFriend
Messages: 1
Registered: March 2022
Junior Member
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]

Report message to a moderator

Previous Topic:AbstractSmartField - parsing for an exact value
Next Topic:AbstractDateTimeField with Milliseconds
Goto Forum:
  


Current Time: Thu Apr 25 09:39:14 GMT 2024

Powered by FUDForum. Page generated in 0.03313 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top