4

I have a parent controller class with a string variable called source and two classes, Display and Basket, that inherit from it. Basket is used by a component embedded in the display page. On the display page I have

<apex:inputHidden val='{!source}'/>

and I set the value in Javascript. Now I would imagine the value would be set only in the Display controller but the logs say it's set in Basket as well. Is this a feature or a bug? From my previous experiments I remember that when SF get confused to which variable assign a value (child overrides parent's) it silently errors.

TO prove myself I'm not hallucinating : I click on an image within the component ant this invokes GoToBasket (page) action. (function defined in Parent). When I print out the source it's not null. It looks like SF matched it to both instances of ParentClass it had loaded onto the stack.

(862791000)|CODE_UNIT_FINISHED|DisplayController get(hasError)
(862982000)|CODE_UNIT_STARTED|[EXTERNAL]|01pe00000001eLY|BasketController invoke(GoToBasket)
(863035000)|SYSTEM_MODE_ENTER|false
(864396000)|METHOD_ENTRY|[49]|01pe00000001eDt|ParentController.__sfdc_src()
(864440000)|METHOD_EXIT|[49]|01pe00000001eDt|ParentController.__sfdc_src()
(864472000)|SYSTEM_METHOD_ENTRY|[49]|System.debug(ANY)
(864482000)|USER_DEBUG|[49]|DEBUG|*** PARENT CONTROLLER GO TO BASKET source=myvalue ***
(864489000)|SYSTEM_METHOD_EXIT|[49]|System.debug(ANY)
(864498000)|METHOD_ENTRY|[51]|01pe00000001eDt|ParentController.__sfdc_src()
(864512000)|METHOD_EXIT|[51]|01pe00000001eDt|ParentController.__sfdc_src()
…….. setting up page reference and redirecting…….
(865315000)|SYSTEM_METHOD_EXIT|[63]|System.PageReference.setRedirect(Boolean)
(865322000)|SYSTEM_MODE_EXIT|false
(865356000)|CODE_UNIT_FINISHED|BasketController invoke(GoToBasket)

  • Can you share the logs or at least a snippet of them? I think i didn't quite understand your question the first time round btw. ;-) – Andrew Fawcett Dec 5 '13 at 15:01
1

So its sounds like you have this...

public class ParentController
{
    public String source {get;set;}
}

public class DisplayPageController extends ParentController
{
}

public class BasketComponentController extends ParentController
{
}

And this page setup...

<apex:page controller="DisplayPageController">
    <c:basket/>
    <apex:inputHidden val='{!source}'/>
</apex:page>

If your expectation is that both controllers will share the value of 'source' thats incorrect I'm afraid. While they share the same base class, there exists two separate instances of that base class in the above use case. One for the page instance and one for the component instance on the page.

If you want to want communicate with between the page and component you need to use apex:attribute in your component and pass values that way, by rerendering the component once the page controller state has been updated, if you have JavaScript invovled on the page you may want to study the actionFunction VF component a bit more.

  • I don't expect I see it in my logs that's why I'm so amused. You are absolutely wright. Logic and OO paradigms say Basket and Display are different classes each should have their own instance of parent's template. But when I execute a method called from the component and print out the value of source it's set to what I assign in Display page. – user682217 Dec 5 '13 at 15:08
  • Thats is strange I agree, i known multiple pages can share the same controller instance, but not a controller instance shared with a component instance, which only share the same base type. Can you share your log somehow, i'm curious to see what is giving you this impression? – Andrew Fawcett Dec 5 '13 at 15:48

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.