You need to sign in to do that
Don't have an account?
Mike Leach
Reading a Visualforce Parameter from Controller
Is there anyway to declare a customizable parameter in Visualforce that can be read from the controller?
The controller is a managed package global class that (ideally) derives behavior from declarative config values in the VF page template.
Something like:
<apex:Page controller="myController"> <apex:??? value="foo" id="myParam" /> </apex:Page> global class myController(){ public myController(){ string configParam = myParam.value; if(configParam == 'foo'){ //do this } else{ //do something else } } }
Right. What I'm proposing would break MVC orthogonality. I'll stick with custom settings.
Thanks again for the feedback!
-Mike
All Answers
You can do it this way. And I am not sure if this is what you are looking for
Thanks Srinivas. I did try a variation of your suggestion. A javascript post back to the controller from the client works, but I'd like to find out if the controller can get a VF page value on the server during initial page render.
I'll probably resort to using custom settings instead, but it was worth a try.
Thx!
-Mike
Yes. But you do not have to post back. Use this.
<apex:page controller="myController" sidebar="false" standardStylesheets="false">
<apex:form>
<apex:inputHidden value="{!paramVal}" id="myParam" />
<script>document.getElementById('{!$Component.myParam}').value = 'foo';</script>
<apex:actionFunction name="callLoadPage" action="{!loadPage}" reRender="dummyOP"/>
<apex:outputPanel id="dummyOP"></apex:outputPanel>
</apex:form>
<script>
callLoadPage();
</script>
</apex:page>
global class myController
{
public string paramVal
{ get;set; }
public void loadPage()
{
string configParam = paramVal;
System.debug('-------' + paramVal);
if(configParam == 'foo'){
//do this
}
else{
//do something else
}
}
}
If you are trying to provide a value to the controller on the initial page render you would have to either do it via custom settings or a database field, or via a query parameter that you add to the request.
Your controller can access query parameters via ApexPages.currentPage().getParameters()
Right. What I'm proposing would break MVC orthogonality. I'll stick with custom settings.
Thanks again for the feedback!
-Mike
are you thinking about doing something like
/apex/yourpage?yourParameter=yourValue
Then aballard's suggestion should work
This Site app runs without params. The type of configurable behaviors in this particular managed controller should not be accessible via params.
A Developer will need to specifically declare the custom setting. Because the Developer is already working in a VF page (in this case) I'd hoped to avoid the extra step of going to custom settings and just set a value in the page.
Not giving up entirely. It looks like there are some unused/deprecated attributes in <apex:page /> that might be readable from the controller.