0

I am trying to reRender a block after the user clicks a commandLink that updates an object. Any help would be greatly appreciated.

Here is the code:

<apex:page controller=“ServiceSubscription" tabStyle="Account">

<apex:form>
    <apex:pageBlock title="Account Details">
            <apex:pageBlockSection>
                <apex:pageBlockSectionItem  dataStyle="width: 30%">
                    <apex:outputPanel>
                        <h2>IDs Associated With Account</h2>

                        <ul>
                            <li>
                                <apex:commandLink action="{!setUserForVisualForce}" reRender="accountData">
                                    111
                                    <apex:param assignTo="{!visualForceUserId}" name="Id" value="111"/>
                                </apex:commandLink>
                            </li>
                        </ul>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem dataStyle="width: 70%" id=“accountData">
                    <h2>Account Data</h2>

                    <table class="list">
                        <thead>
                            <tr class="headerRow">
                                <th>Account ID</th>
                                <th>Subscription ID</th>
                                <th>Max Records Available</th>
                                <th>Current Records Used</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr class="dataRow">
                                <td class="dataCell">{!userForVisualForce.id}</td>
                                <td class="dataCell">{!userForVisualForce.subscriptionId}</td>
                                <td class="dataCell">{!userForVisualForce.subscriptionMaxRecords}</td>
                                <td class="dataCell">{!userForVisualForce.currentRecords}</td>
                            </tr>
                        </tbody>
                    </table>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

public class ServiceSubscription {
    public ServiceAccount visualForceUser = new ServiceAccount();
    public String visualForceUserId {get; set;}

    public PageReference setUserForVisualForce() {
        if (this.visualForceUserId != null) {            
            this.visualForceUser    = this.get(Integer.valueOf(this.visualForceUserId));
            this.visualForceUserId  = null;
        }

        return null;
    }

    public ServiceAccount getUserForVisualForce() {
        return this.visualForceUser;
    }
}
4
  • What exactly your issue is Aug 30, 2017 at 21:13
  • When you remove the rerender attribute and add an <apex:pageMessages/> tag to the page - does it show you any errors in the messages output?
    – Mark Pond
    Aug 30, 2017 at 22:01
  • @SantanuBoral nothing happens once I click the link. I can see in the debug logs that the setSubscriptionId() line runs, but the table doesn't reflect the change.
    – Kenyon
    Aug 30, 2017 at 22:15
  • @MarkPond it does not show any error messages when I do that, nope.
    – Kenyon
    Aug 30, 2017 at 22:16

2 Answers 2

1

AssignTo attribute looks for the property defined in Controller. It will not assign object's instance value directly from it.

That is you are trying to assign value to visualForceUser.id by assignTo which will not work.

<apex:commandLink action="{!setUserForVisualForce}" reRender="accountData">
    111
    <apex:param assignTo="{!userid}" name="Id" value="111"/>
    <apex:param assignTo="{!subscriptionId}" name="subscriptionId" value=""/>
</apex:commandLink>

Controller

public String subscriptionId {get;set;}
public String userid {get;set;}
2
  • I changed it to work this way. And I can definitively say the now my this.visualForceUser variable is being assigned correctly and the values are right (used System.debug directly after the assignment to confirm). However, it still doesn't reRender the accountData section
    – Kenyon
    Aug 31, 2017 at 17:01
  • can you post your updated code in the question, I will look into that Aug 31, 2017 at 17:35
0

I have seen like this before most of the time <apex:pageBlockSectionItem> failed Re-render.

Alternative you can do have <apex:outputPanel> inside and render <apex:outputPanel> . i have tried similar to your code ,following code is working fine.

VisualForce Page :

<apex:page controller="cntr190500" >

    <apex:form >
    <apex:pageBlock title="Account Details">
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem dataStyle="width: 30%">
                    <apex:outputPanel >
                        <h2>IDs Associated With Account</h2>
                        <ul>
                            <li>
                                <apex:commandLink action="{!displayMsg}" reRender="accountData" value="{!msg}" >                                                            
                                    <apex:param assignTo="{!msg}" name="msg" value="msg from visulforce"/>
                                </apex:commandLink>
                            </li>
                        </ul>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem dataStyle="width: 70%" >
                    <apex:outputPanel id="accountData" >
                    <h2>Account Data</h2>

                    <table class="list">
                        <thead>
                            <tr class="headerRow">
                                <th>Account ID</th>
                                <th>Subscription ID</th>
                                <th>Max Records Available</th>
                                <th>Current Records Used</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr class="dataRow">
                                <td class="dataCell">{!msg}</td>
                                <td class="dataCell">{!msg}</td>
                                <td class="dataCell">{!msg}</td>
                                <td class="dataCell">{!msg}</td>
                            </tr>
                        </tbody>
                    </table>
                        </apex:outputPanel>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

Controller : cntr190500

public class cntr190500 {

    public string msg{get;set;}
    public cntr190500(){
        msg='click here';
    }
    public void displayMsg(){
        msg='New message from apex';
    }
}
6
  • This didn't work :(
    – Kenyon
    Aug 31, 2017 at 22:59
  • @Kenyon i have updated answers, it is working fine with me.
    – NITHESH K
    Sep 1, 2017 at 5:12
  • Can you share the controller you used? It isn't working for me :/
    – Kenyon
    Sep 1, 2017 at 21:02
  • @Kenyon I have updated code what i have tried similar to your code.
    – NITHESH K
    Sep 2, 2017 at 7:58
  • @Kenyon i can't try with your controller, because your controller is incomplete understand fully .
    – NITHESH K
    Sep 2, 2017 at 7:59

You must log in to answer this question.

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