Skyve non persistent homepage with server action on select goes in infinite loop

Viewed 30

Using Skyve 7.0.2.

I have a non-persistent home page document that contains a tree in its view. When the tree is populated I get an infinite loop of client-server requests.

The edit.xml (used when using HomeRef=edit) shows my tree of file system folders. What I want to do is on selecting a line from the tree, to display on the same page the files within that folder. I have a LoadFiles action, called from the onSelectedHandlers. Indeed this loads and shows the files, but then the tree starts continually refreshing, and I see in the traffic continuously requests for the tree content (qFolders query) and the LoadFiles action. So a continuous loop. I tried several things, but can not find out what causes the loop and how to prevent it. If anyone can give a hint that would be most helpful.

src/main/java/modules/mymod/Homepage/Homepage.xml

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="http://www.skyve.org/xml/document" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Homepage" xsi:schemaLocation="http://www.skyve.org/xml/document ../../../schemas/document.xsd">
    <singularAlias>Home</singularAlias>
    <pluralAlias>Homepages</pluralAlias>
    <iconStyleClass>fa fa-file-text</iconStyleClass>
    <parentDocument/>
    <bizKey expression="Home - {name}"/>
    <attributes>
        <text name="name">
            <displayName>Name</displayName>
            <length>250</length>
        </text>
        <id name="selectedFolderId">
            <displayName>SelectedFolder ID</displayName>
        </id>
        <association type="aggregation" name="selectedFolder">
            <displayName>Selected folder</displayName>
            <documentName>Folder</documentName>
        </association>
        <collection type="aggregation" name="files">
            <displayName>Files</displayName>
            <documentName>File</documentName>
            <minCardinality>0</minCardinality>
            <ordering/>
        </collection>
    </attributes>
    <conditions>
        <condition name="hasSelectedFolder">
            <description>If folder is set</description>
            <expression>
                <![CDATA[selectedFolder != null]]>
            </expression>
        </condition>
    </conditions>
</document>

src/main/java/modules/mymod/Homepage/views/edit.xml

<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="edit" title="Home" xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
    <hbox>
        <treeGrid title="Folder hierarchy" percentageWidth="30" responsiveWidth="4"
                  query="qFolders"
                  continueConversation="true"
                     selectedIdBinding="selectedFolderId" autoPopulate="true">
                <onSelectedHandlers>
                    <server action="LoadFiles"/>
                </onSelectedHandlers>
        </treeGrid>
        <vbox borderTitle="Files in current folder">
            <dataGrid title="Files" binding="selectedFolder.files">
                <boundColumn binding="name"/>
                <boundColumn binding="publisher"/>
                <onEditedHandlers/>
                <onSelectedHandlers/>
            </dataGrid>
        </vbox>
    </hbox>
    <actions>
       <defaults/>
       <action className="LoadFiles" clientValidation="false" displayName="LoadFiles" inActionPanel="false"></action>
    </actions>
</view>

src/main/java/modules/mymod/Homepage/actions/LoadFiles.java

package modules.mymod.Homepage.actions;

import org.skyve.CORE;
import org.skyve.metadata.controller.ServerSideAction;
import org.skyve.metadata.controller.ServerSideActionResult;
import org.skyve.web.WebContext;

import modules.mymod.domain.Folder;
import modules.mymod.domain.Homepage;

public class LoadFiles implements ServerSideAction<Homepage> {

    /**
     * For serialization.
     */
    private static final long serialVersionUID = 2165829726729411782L;

    @Override
    public ServerSideActionResult<Homepage> execute(Homepage bean, WebContext webContext) throws Exception {
        if (bean.getSelectedFolderId() != null) {
            if (bean.getSelectedFolder() == null || bean.getSelectedFolder().getBizId() != bean.getSelectedFolderId()) {
                Folder folder =
                        CORE.getPersistence().retrieve(Folder.MODULE_NAME, Folder.DOCUMENT_NAME, bean.getSelectedFolderId());
                bean.setSelectedFolder(folder);
            }
            bean.setSelectedFolderId(null);
        }
        return new ServerSideActionResult<Homepage>(bean);
    }
}

and for completeness, also the mymod.xml, Folder.xml and File.xml

src/main/java/modules/mymod/mymod.xml

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="http://www.skyve.org/xml/module" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" title="mymod" prototype="true" name="mymod" xsi:schemaLocation="http://www.skyve.org/xml/module .
./../schemas/module.xsd">
    <homeRef>edit</homeRef>
    <homeDocument>Homepage</homeDocument>
    <documents>
        <document ref="Folder"/>
        <document ref="File"/>
        <document ref="Homepage"/>
    </documents>
    <roles>
        <role name="Viewer">
            <description><![CDATA[Enough privileges to view documents.]]></description>
            <privileges>
                <document name="Folder" permission="_R__C"/>
                <document name="File" permission="_R__C"/>
                <document name="Homepage" permission="_R__C"/>
            </privileges>
        </role>
        <role name="Maintainer">
            <description><![CDATA[Enough privileges to create and edit documents.]]></description>
            <privileges>
                <document name="Folder" permission="CRUDC"/>
                <document name="File" permission="CRUDC"/>
                <document name="Homepage" permission="CRUDC"/>
            </privileges>
        </role>
    </roles>
    <menu>
        <edit document="Homepage" name="Home">
            <role name="Maintainer"/>
            <role name="Viewer"/>
        </edit>
        <tree autoPopulate="true" document="Folder" name="Folders">
            <role name="Maintainer"/>
            <role name="Viewer"/>
        </tree>
        <list autoPopulate="true" document="File" name="Files">
            <role name="Maintainer"/>
            <role name="Viewer"/>
        </list>
    </menu>
    <queries>
                <query name="qFolders" documentName="Folder">
                        <description>Folder Structure</description>
                        <columns>
                                <column binding="name" sortOrder="ascending"/>
                        </columns>
                </query>
    </queries>
</module>

src/main/java/modules/mymod/Folder/Folder.xml

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="http://www.skyve.org/xml/document" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Folder" xsi:schemaLocation="http://www.skyve.org/xml/document ../../../schemas/document.xsd">
    <abstract>false</abstract>
    <persistent name="DOC_Folder"/>
    <singularAlias>Folder</singularAlias>
    <pluralAlias>Folders</pluralAlias>
    <audited>true</audited>
    <iconStyleClass>fa fa-folder</iconStyleClass>
    <parentDocument databaseIndex="true">Folder</parentDocument>
    <bizKey expression="Folder - {name}"/>
    <attributes>
        <text required="true" trackChanges="true" name="name">
            <displayName>Name</displayName>
            <length>50</length>
        </text>
        <collection type="child" name="files">
            <displayName>Files</displayName>
            <documentName>File</documentName>
            <minCardinality>0</minCardinality>
            <ordering/>
        </collection>
    </attributes>
</document>

src/main/java/modules/mymod/File/File.xml

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="http://www.skyve.org/xml/document" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="File" xsi:schemaLocation="http://www.skyve.org/xml/document ../../../schemas/document.xsd">
    <persistent name="DOC_File"/>
    <singularAlias>File</singularAlias>
    <pluralAlias>Files</pluralAlias>
    <iconStyleClass>fa fa-file-text</iconStyleClass>
    <parentDocument>Folder</parentDocument>
    <bizKey expression="File - {name}"/>
    <attributes>
        <text name="name">
            <displayName>Name</displayName>
            <length>250</length>
        </text>
        <text name="publisher">
            <displayName>Publisher</displayName>
            <length>250</length>
        </text>
    </attributes>
</document>
1 Answers

So I think what is happening is that when you select an item in the tree, the onSelectedHandler is calling your LoadFiles action, which is causing the tree to re-render when the server processes your action and sends the response back to the client.

Skyve provides a postRefresh attribute to control whether the tree should re-render after a post, so you could try setting postRefresh="false" on your treeGrid.

You could also try setting continueConversation="false" on the treeGrid as navigation does not progress via the tree and need to continue the user conversation.

Related