1

I am running into a strange issue, I've created the following function in my visualforce controller for testing:

public void willFail()
{
    Account acc = null;
    acc.Name = 'test';
    update acc;
}

Now i have this piece in my visualforce code:

<apex:commandButton value="will fail" action="{!willFail}" />
<apex:repeat value="{!report}" var="row">
</apex:repeat>

When i click the button, as expected i get a null reference error.

However, if i put the command button inside the repeat like so:

<apex:repeat value="{!report}" var="row">
<apex:commandButton value="will fail" action="{!willFail}" />
</apex:repeat>

Now the page just refreshes with no error. I've tried other variations of my testing function where i send emails, or add page messages, but it appears that if I put the button inside the apex repeat, that the action is not called at all. I can put an javascript function on the "onComplete" attribute of the command button, and the javascript function will be executed no matter if the button is in the repeat or not, but the action of the command button is never executed inside the repeat.

Now the issue appears to be that the "Report" value used in the value of the repeat is a Transient Variable. When I change the repeat to use a non transient variable, the button will work correctly. Is it impossible to use command buttons on apex repeat, if the variable for repeating is transient?

1 Answer 1

1

This isn't documented behavior, but it is also not surprising. The controller only knows about its form inputs and view state. A transient variable won't have any view state. You can still work with this in some situations by having the value bound to an input control of some sort (e.g. an apex:selectList), but you should not depend on this behavior. You must either make the variable non-transient and non-static (i.e. an instance variable), or you must calculate the results each time (e.g. getReport() being a method bound to value="{!report}").

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.