0

Has anyone else experienced issues with permission based elements on visualforce when rerendering a section?

For example I have a section that for administrators will provide a link but for common users it would just display the text like so:

<apex:repeat id="myRepeat">
    <apex:outpanel id="myWrapper"
    <!-- If user has admin permissions -->
    <apex:outputPanel rendered="{!$Permission.AdminPermission}">
        <a href="/{!record.Id}" target="_blank">
            <apex:outputPanel layout="block">Record# {!record.Id}</apex:outputPanel>
        </a>
    </apex:outputPanel>
    <!-- If user does NOT have admin permissions -->
    <apex:outputPanel rendered="{!!$Permission.AdminPermission}">
        <apex:outputPanel layout="block">Record# {!record.Id}</apex:outputPanel>
    </apex:outputPanel>
    <!-- Input text with onchange actionFunction method -->
    <apex:inputText value="{!rowUnits}" onChange="updateUnits(this)"/>
</apex:repeat>

<!-- Action Functions -->
<apex:actionFunction 
    action="{!setUnits}" 
    name="updateUnitsAction" 
    reRender="{!$Component.myRepeat.myWrapper}">
</apex:actionFunction>

<apex:commandButton value="Submit" action="{!process}" rerender="errors, {!$Component.myRepeat.myWrapper}/>

When the page first loads this works exactly as expected but then when I rerender the section that contains this portion of markup the permission that once worked (granting the link) is now false (showing just the text). If I refresh the page I again have the admin link.

Appreciate any feedback, thanks!

Edited with command button, inputtext onchange, and wrapper section markup

2
  • 1
    Just a couple comments, but better to use NOT inside a merge field than ! especially first thing. Also better to do {!URLFOR($Action.MyObject__c.View, record.Id)} than /{!record.Id}.
    – Adrian Larson
    Commented Jun 10, 2016 at 18:27
  • What happens if you store the results of that $Permission outside the repeat using an apex:variable tag? Might work...
    – Adrian Larson
    Commented Jun 10, 2016 at 18:28

2 Answers 2

2

Interesting... the comments and previous answer were very helpful (so thank you for them), I implemented them but the actual issue turned out to be because of the <apex:outputPanel>.

Apparently even without the permissions in play the hyperlink was being removed on rerender because the text was wrapped with an outputPanel. Luckily, I found another section where this was not an issue, it was using <apex:outputText> so I modified my scenario with that and it worked perfectly!

<!-- If user has admin permissions -->
<apex:outputPanel rendered="{!$Permission.AdminPermission}">
    <a href="{!URLFOR($Action.MyObject__c.View, record.Id)}" target="_blank">
        <apex:outputText value="Record# {!record.Id}"></apex:outputText>
    </a>
</apex:outputPanel>
<!-- If user does NOT have admin permissions -->
<apex:outputPanel rendered="{!NOT $Permission.AdminPermission}">
    <apex:outputText>Record# {!record.Id}</apex:outputText>
</apex:outputPanel>

Thanks for you help!

0

The problem is not there in this section of code which you have shared.

The issue lies how your are re-rendering this section. Are you using click event action function or controller action which is re-rendering these output panels?

If you mind to share the code on how you are re-rendering.

1
  • Edited my post, added with sharing to my controller as well but that didn't seem to fix anything Commented Jun 10, 2016 at 18:19

You must log in to answer this question.

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