1

I have an outputLink like this:

<apex:outputLink value="/apex/NewPage?id='xxxcccxxx'>
    <div class="link_class">
        <strong>Link</strong>
    </div>
</apex:outputLink> 

I want to pass an apex value through with this link to the next page, I'd like to pass it through s a hidden value if that's possible.

{!my_val}

And then catch it on the next page and throw it into a div.

I can't pass it in the URL as I need the URL to remain as it is.

Only using JS, html or APEX, is this possible?

2 Answers 2

2

If both pages use the same controller and extensions, you can actually pass the state of the page from the first to the second. You'd need to change the code from an apex:outputLink to a apex:commandLink to make this happen, though.

If you don't want to share the view state across pages (e.g. you need different controllers), you can also use localStorage or sessionStorage to store the variable in the browser's memory cache while you travel between pages. This will require cooperation on both pages, as the former will need to set the value (localStorage.setItem('somekey', 'value')), then retrieve it on NewPage (localStorage.getItem('somekey')). You can also use document.cookie for small values (less than about 4kb) for broader browser compatibility.

If you have no control over NewPage, then you're pretty much out of luck. You need a POST action for the variable to persist invisibly, which means the receiving page needs to be able to understand this POST request. Using apex:commandLink would be the easiest way to achieve your goal, especially if you can design both pages to use the same controller.

0

Here a small POC recipe. Hope this helps you for the previous answer from different member.

Page 1

<apex:page standardController="Account" extensions="onePageToAnotherCarryId">
    <script>
        
        function goTo1()
            //alert('HI');
            goTo2();            
        }
    </script>

    <apex:form >
        <apex:commandLink onclick="goTo1();">clickHere <br/>
            <apex:actionFunction action="{!goToVFPage2}" name="goTo2" reRender="content">
                <apex:param name="myParam" value=""/>
            </apex:actionFunction>
        </apex:commandLink>
    </apex:form>
</apex:page>

Page 2

<apex:page controller="onePageToAnotherCarryId">
  capture the value you passed from the previous page
</apex:page>

Controller

public class onePageToAnotherCarryId {
    public string myparam{get;set;}

    public onePageToAnotherCarryId() {
        string passedParam1 = Apexpages.currentPage().getParameters().get('myParam');
        system.debug('************1 Here you are in goto'+passedParam1);
    }

    public onePageToAnotherCarryId(ApexPages.StandardController controller) {
    }
    
    public PageReference goToVFPage2(){
        
        PageReference pageref = new PageReference('/apex/vfPage2');
        system.debug('*********2 Here you are in goto');
        pageref.setRedirect(true);
        system.debug('*********3 Here you are in goto'+pageref);
        return pageref;        
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .