function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
开发商开发商 

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.
 


 
Jon Mountjoy_Jon Mountjoy_
Hi

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
开发商开发商
I get the correct behavior from the inputField on the page. When I click the commandButton I would like to use the inputField as the variable in the controller to write details about the user (name in the example) back to the "out" panelGroup
 
<apex:panelGroup id="out">
          hello: {!Value}
 </apex:panelGroup>
 
I am not sure how to code the controller to do this. How do you read the content of the inputField from the controller, use the inputField as the variable in sql, and pass the results back to the screen?
 
Thanks for your help.
jwetzlerjwetzler
Code:
public class extSearchDetail {
searchDetail__c sd;
public String value { get; set; }

 public extSearchDetail(ApexPages.StandardController controller) {
sd = (searchDetail__c) controller.getRecord();
} public void doSearch() { User2__c u = [select name from User2__c where id = :sd.user2__c];
value = u.name;
 } }

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
开发商开发商
Thank you Jill. This example is what I was looking for. I got my code to work.