You need to sign in to do that
Don't have an account?
开发商
My controller:
I am not sure how to code the controller so I can reference the inputField, query the User table, and return the name.
inputField controller help
I am just starting VisualForce and have lost my way with inputField. I have a custom object searchDetail__c with a lookup field named User2__c. I want to lookup the user using inputField, press a button, and have the name written back to the screen. I have no interest in saving the record.
My page:
Code:
<apex:page renderAs="html" standardController="searchDetail__c" extensions="extSearchDetail"> <apex:form > <apex:pageBlock mode="edit" id="block" title=""> <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:panelBar > <apex:panelBarItem label="Search"> <apex:panelGroup > <apex:inputField id="u" value="{!searchDetail__c.User2__c}"/><BR/> <apex:commandButton value="Go!" action="{!doSearch}" rerender="out" status="status"/> </apex:panelGroup> </apex:panelBarItem> </apex:panelBar> <apex:panelBar > <apex:panelBarItem label="name"> <apex:panelGroup id="out"> hello: {!Value} </apex:panelGroup> </apex:panelBarItem> </apex:panelBar> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
My controller:
Code:
public class extSearchDetail { public extSearchDetail(ApexPages.StandardController controller) { } public PageReference doSearch() { // please help } public String getValue() { // please help } }
I am not sure how to code the controller so I can reference the inputField, query the User table, and return the name.
Any help is appreciated.
I'm not quite sure I understand your question. If you want a standard input box so that you click on a button and look up the related object, then I believe you get that for free by just including:
<apex:inputField id="u" value="{!searchDetail__c.User2__c}"/>
as you have done.
In other words, try removing your commandButton - don't you get the behaviour you want out of the box?
Regards,
Jon
Message Edited by Jon Mountjoy_ on 07-29-2008 03:01 AM
hello: {!Value}
</apex:panelGroup>
Also you should remove the "status" from your commandButton, I'm not sure what you're trying to do with that but you don't need it.
Message Edited by dchasman on 07-29-2008 03:08 PM