• method onAction does not return desired type of page

    183 Views Asked by At

    TML

    <ul class="dropdown-menu">
        <li>            
            <!-- link should return /tracker -->
            <t:pagelink page="tracker" data-toggle="dropdown" class="dropdown-toggle disabled">
            <span>All Tickets</span>
            </t:pagelink>
        </li>
        <t:loop source="projectList" value="projectP1">
            <!-- link should return /tracker/# -->
            <li><t:pagelink page="tracker" context="${projectP1.id}">${projectP1.title}</t:pagelink></li>
        </t:loop>
    </ul>
    ...
    <t:actionlink t:id="followProject">
        <t:if test="isUserFollowingProject"> Unfollow</t:if> 
        <t:if test="!isUserFollowingProject"> Follow</t:if> 
    </t:actionlink>
    

    Java

    @Property
    private Project project;
    ...
    
    @PageLoaded
    void onPageLoad() {
        projectList = projectDao.loadAll();
        ticketList = ticketDao.loadAll();
    }
    
    void onActivate(Integer contextValue) {
        if (contextValue != null) {  
            project = projectDao.getByID(contextValue);
        }
        if (project != null) {
            List ticketListByProjectID = ticketDao.getTicketsByProjectID(project.getId());
            if (!ticketListByProjectID.isEmpty()) {
                ticketList = ticketListByProjectID;
            }           
        }
    }
    
    @CommitAfter
    void onActionFromFollowProject() {
    
    }
    

    So the problem is when I'm on project context with url like ../tracker/1, and I click on the actionlink, it returns me to /tracker home page with out /1 context, where instead, I want it to return /tracker/1, the same context as it was when I clicked on action link. How can I fix this, since I have two type of context, an empty one and with a number ?

    p.s. I tried following:

    Integer onPassivate() {
        return project != null ? project.getId() : null;
    }
    

    Now this works, and returns context with tracker/1 when I click on actionlink, however, my pagelink:

    <t:pagelink page="tracker" data-toggle="dropdown" class="dropdown-toggle disabled">
            <span>All Tickets</span>
    </t:pagelink>
    

    Now has value of tracker/1, instead of /tracker, when I added this onPassivate method

    UPDATE:

    I'm not using onPassivate method. Every other page link normally works, expect actionlink for follow/unfollow. So for code in tml

    <t:actionlink t:id="followProject" t:context="tracker/${project?.id}" class="btn btn-default btn-sm btn-default-gradient">
        <span class="glyphicon glyphicon-star"></span>
        <t:if test="isUserFollowingProject"> Unfollow</t:if> 
        <t:if test="!isUserFollowingProject"> Follow</t:if> 
    </t:actionlink>
    

    in developer tool on inspect that actionlink element I have following html code:

    <a class="btn btn-default btn-sm btn-default-gradient active" href="/IssueTracker/tracker.followproject/tracker$002f1"><span class="glyphicon glyphicon-star"></span> Unfollow</a>
    

    Does this href="/IssueTracker/tracker.followproject/tracker$002f1" tell you maybe something ? It stills returns me to /IssueTracker/tracker instead of IssueTracker/tracker/#1, 2, 3... page.

    1

    There are 1 best solutions below

    4
    joostschouten On

    You will need to tell the link itself to use the project as the context parameter. This should do the trick:

    <t:actionlink t:id="followProject" t:context="project">
        <t:if test="isUserFollowingProject"> Unfollow</t:if> 
        <t:if test="!isUserFollowingProject"> Follow</t:if> 
    </t:actionlink>
    

    The passivate option will add the value to all links linking to this page (like you experienced).