+ Start a Discussion

Referencing the value of another visualforce component on the same page

I have a visualforce page that needs to be able to set the owner of a custom object to either a queue OR a user. The standard apex:inputField tag will only pull up users as it's a custom object and not a true case object.


I have the controller side fully working, when I pass in ownerType via a GET property in the URL everything works as I'd like it to, but I can't quite get it working without having to refresh the page.


Fundamentally, my issue is that I can't figure out how to reference the value of the Owner Type selectList.

Here's the relevant snippet of visualforce: 



              <apex:pageblockSection id="ownerList">

              <apex:pageblockSectionItem >

              <apex:outputText value="{!ownerType}" />

              <apex:selectList value="{!problem.ownerId}"  size="1">

              <apex:selectOptions value="{!owners}" />



              <apex:pageblockSectionItem >

              <apex:outputText value="Owner Type"/>

              <apex:selectList id="ownerType" value="{!ownerType}" size="1">

              <apex:actionSupport event="onchange" rerender="ownerList" immediate="true" status="status">

              <apex:param name="ownerType" value="{!$CurrentPage.parameters.ownerType}" assignTo="{!ownerType}" />


              <apex:selectOption itemValue="user" itemLabel="User"/>

              <apex:selectOption itemValue="group" itemLabel="Group"/>





I'm rather sure that the problem is in the apex:param tag, but I can't figure out what to set the value of the param tag to. I tried $CurrentPage.parameters.ownerType but it came back null when the ownerList pageblock was rerendered.


Thanks for the wonderful support community! 




I haven't used the parameter tag before.  However, I would suggest working in the page controller constructor to pull the URL param and then use a getter / setter method for your OwnerType property, this will ensure to set it when the page loads.



Remove the "immediate" attribute on your action support.  Immediate causes the controller to ignore post data.

Ah, good to know. Thanks for that.


Even with that it's still not working as expected, but the scope of this page has changed, and I need to change how this is being done anyways.  


Ultimately I'm going to end up using a custom component and controller so that it can be easily re-used across my app. 


Edit: nevermind it not working still, another dev had changed the controller code in a way that broke it. 

Message Edited by cpeterson on 08-05-2009 06:26 PM