[SalesForce] How to use a VisualForce page to set a custom setting field

I'm trying to create a VisualForce configuration page for my managed package. I have a hierarchal custom setting field for an authentication key which is needed to access a remote service. I can read this value with "{!$Setup.prefix__Settings__c.prefix__Key__c}"

however, if I try making an input field for it using

<apex:inputField value="{!$Setup.prefix__Settings__c.prefix__Key__c}"/>

it says that only sObjects work for inputField values.

I thought merge fields worked too…anyway, how can I let the user type in a key and save that value to the custom settings record? Also, would using a List custom setting be easier or better?

Best Answer

You can set them via Apex controller. Here is some documentation

So it would be something like this (for hierarchy settings):

Apex:

public String myValueFromPage{get; set;}

public void saveMyValue() {
    prefix__MySettings__c settings = prefix__MySettings__c.getInstance();
    settings.prefix__myField__c = myValueFromPage;
    upsert settings;
}

Visualforce:

<apex:inputText value="{!myValueFromPage}">
<apex:commandButton action="{!saveMyValue}" value="Save Input"/>