[SalesForce] Using a VF inputfield as a variable in a custom controller

I am in the process of learning APEX/VisualForce, and I'm working on a VF page that lists out all of the chatter posts from a specific record. Right now, the record that it displays the feed for is hard-coded into the controller like this:

global ConnectApi.FeedItemPage getNewsFeed() {
    return ConnectApi.ChatterFeeds.getFeedItemsFromFeed(null, ConnectApi.FeedType.Record, 'a00E0000006uAuB');
}

I would like to use an inputField on the VisualForce page where the user can input a record's Id, click a button, and have the outputPanel re-render displaying the given record's feed.

I have the button and the re-render working, but I can't figure out how to pass the value from the inputField to a variable in the controller without it having to have a field on an Object in the database.

Additionally, and in a similar vein, I want the outputPanel to render iff the variable (discussed above) is not equal to null, but again, I can't figure out how to reference either another field on the page or the variable on the controller.

Thanks in advance for any help! If you want to see some more code, let me know. Most of it is taken or adapted from a Connect in APEX tutorial found here.

Best Answer

You can use the apex:inputText component http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_inputText.htm

<apex:inputText value="{!inputValue}" id="theTextInput"/>

<apex:commandButton action="{!actionMethod}" reRender="theOutputPanel" />

<apex:outputPanel id="theOutPutPanel" rendered="{!inputValue != null}" />....

apex:inputField, as you rightly pointed out, is when you want to directly bind to sObject fields in the controller

As for re-rendering, this one is a great post.

Related Topic