Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am embedding a VisualForce page with a form and some inputs in a standard page layout. My form mark-up:

<apex:page standardController="Contact" extensions="ContactControllerExt" action="{!init}" showHeader="false" sidebar="false" doctype="html-5.0">
    <apex:pagemessages />

    <apex:outputpanel rendered="{!showAssignPanelB}">
        <apex:form >
            <apex:selectList id="area" size="1" label="Area">
                <apex:selectOptions value="{!regionSelectList}" />
            </apex:selectList>      
            <apex:commandButton value="Assign" action="{!assignContact}"/><br/>
            <input type="text" name="reason" placeholder="Reason" />
        <apex:commandButton value="Not Approved" action="{!mediaBNotApprove}"/><br/>
        </apex:form>   
    </apex:outputpanel>
</apex:page>

If I replace the text input field with:

<apex:inputText id="reason"/>

the element renders as:

<input type="text" name="j_id0:j_id28:reason" id="j_id0:j_id28:reason" />

and I don't know how to look for that name in the page parameters in the controller. The <select ...> element also renders with an unpredictable name like j_id0:j_id28:area

How can I get the rendered names more predictable?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Short answer

Use the value attribute of the select list to bind your select list to a controller property, it'll then be accessible to apex code, without needing to look for it in the page parameters.

<apex:selectList value="{!yourControllerVar}" ...

Suggested Reading

Data binding is a fundamental feature of Visualforce and is very helpful to understand. You can read more about it in the Visualforce API Docs (search for "input") which sadly doesn't do a great job on the subject, but will hopefully get you going.

share|improve this answer
    
Hey! Waaay easier than picking around for form data in HTML headers. Thanks Ralph! –  JannieT Jan 22 at 6:29
add comment

The rendered names are going to show up like that when it converts the VF tags to HTML. You have a couple options:

Additionally, your use case might not necessarily require you to know the ID at run time. Is this something you could handle with data binding (as mentioned in @Ralph's answer)?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.