Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 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: 80
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
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 message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 80
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
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
Previous Topic:How I can localize texts in ui javascript (frontend)
Next Topic:Form validation in Contacts Application
Goto Forum:
  


Current Time: Wed Feb 19 13:02:50 GMT 2020

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

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

Back to the top