2

I trying to pass a user input (text) into my SOQL statement. I'm using JavaScript to capture the user input then pass it into my controller. It compiles without error but there is no output. This is what I have so far. Thanks

Visualforce Page:

<apex:page controller="ControllerImpactPartsUpdate">

<apex:form >
    <apex:pageBlock title="Impact Catalog Update Module" mode="edit">            

          <table cellpadding="2" cellspacing="2">
              <tr>
                <td style="font-weight:bold;">Business Unit<br/>
                <input type="text" id="BU_v" onkeyup="doSearch();"/>
                </td>
              </tr>
          </table>

          <script type="text/javascript">
              function doSearch() {
               alert('call test');
                searchServer(
                  document.getElementById("BU_v").value,          
                  );
              }
          </script>

          <apex:actionFunction name="searchServer" action="{!UserInput}" rerender="out">
              <apex:param name="BU_v" value="" />       
          </apex:actionFunction>

    </apex:pageBlock>         

    <apex:commandButton value="Go!" action="{!UserInput}" onClick="doSearch();" rerender="out" status="status"/>

     <apex:pageBlock title="Catalog" mode="edit" id="out">
        <apex:pageBlockSection Title="Your Outputs">

            <apex:pageBlockTable value="{!StagingWrappers}" var="StagingWrap">
                <apex:column style="width:10%" headerValue="Remove">
                  <apex:inputCheckbox value="{!StagingWrap.selected}"/>
                </apex:column>                    
                <apex:column style="width:25%" >
                  <apex:facet name="header">
                    <apex:outputText styleclass="requiredHeader" value="{!$ObjectType.Impact_Catalog_Master__c.fields.PartNo__c.label}" />
                  </apex:facet>
                  <apex:inputField value="{!StagingWrap.Staging.PartNo__c}" required="false" />
                </apex:column>

            </apex:pageBlockTable>
        </apex:pageBlockSection>

    </apex:pageBlock>  

</apex:form>

Controller:

public class ControllerImpactPartsUpdate {


public String BU_v;


// wrapper classes for the Master being managed
public List<StagingKey1Wrapper> StagingWrappers {get; set;}
// the unique record key master value
public Integer mainKey {get; set;}
public Integer addItemCount {get; set;}


// runs the search with parameters passed via Javascript
public PageReference UserInput() {

String BU_v = Apexpages.currentPage().getParameters().get('BU_v');

// run the query again
GO();

return null;
}


public Void GO()

{
    mainKey=1;        
    stagingwrappers=new List<StagingKey1Wrapper>();

    List<Impact_Catalog_Master__c> Master_Data=[select ID, OPN__c from Catalog_Master__c    Where Business_Unit__c=:BU_v Limit 5];
    for (Impact_Catalog_Master__c Master : Master_Data)
    {
        Impact_Catalog__c staging_obj = new Impact_Catalog__c();             

        staging_obj.MasterID__c =  Master.ID;
        staging_obj.OPN__c =  Master.OPN__c;

        Stagingwrappers.add(new StagingKey1Wrapper(mainKey++, staging_obj));
    }          
}

public PageReference removeSelected()
{
    List<StagingKey1Wrapper> keep=new List<StagingKey1Wrapper>();
    for (StagingKey1Wrapper Wrap : Stagingwrappers)
    {
        if (!Wrap.selected)
        {
            keep.add(Wrap);
        }
    }

    Stagingwrappers=keep;

    return null;
}
}
1

Thank you all for looking at my codes. After banging my head against my desk for a while I realized the error was at my declaration of my BU_v variable. I've declared it twice, once as a public class variable and the other as a method variable. By removing the method variable it works!

| improve this answer | |
0

Is there a reason to use javascript if not I can post a one line fix that will kill all the JS. I do not know your complete code so making assumption that you are trying to pass the business unit text value to the controller and query data.

This should be your page :

<apex:page controller="ControllerImpactPartsUpdate">
<apex:pagemessages ></apex:pagemessages>
<apex:form >
    <apex:pageBlock title="Impact Catalog Update Module" mode="edit">            

<apex:inputText value="{!input_text}" />
    <apex:commandButton value="Go!" action="{!UserInput}" >
    <apex:param value="{!input_text}" assignTo="{!BU_v}"/>
    </apex:commandButton>
     <apex:pageBlock title="Catalog" mode="edit" id="out">
     <apex:pageBlockTable value="{!StagingWrappers}" var="StagingWrap">
      ....
      ....
//fill in other stuff
     </apex:pageblocktable>
    </apex:pageblock>
          </apex:pageblock>
    </apex:form>
</apex:page>

controller:

public string input_text{get;set;}

In your go method :

List Master_Data=[select ID, OPN__c from Catalog_Master__c Where Business_Unit__c=:input_text Limit 5];

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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