0

I have a VisualForce input text box:

            <apex:inputText value="{!Address1}" id="Example1TextBox" html-placeholder="Example 1"/><br></br>

In the controller class I have:

public string Address1{
    get{
        Id myId = ApexPages.currentPage().getParameters().get('id');
        FedExLabelMethods job = new FedExLabelMethods();
        String AddressValue;
        List<String> compressedAddresses = FedExLabelMethods.getlistofAddresses(myId);
        for(integer i=0; i < compressedAddresses.size(); i++){
            String temp = compressedAddresses[i];
            if(temp.contains(returnAddressesValue)){
                string[] temparray = temp.split(',');
                AddressValue = temparray[1];
                AddressValue = AddressValue.substring(1);
                i = i + 10000000;
            } else {
            }
        }
        if (AddressValue == 'null'){
            AddressValue = '';
        }
        return AddressValue;
    }
    set;
}

Which is referencing a select list. Essentially the textbox will display a query value for whatever the selectlist has currently selected. However I have a problem: If the select list has nothing selected, or even if it does have something selected, and I want to change the value of the text box manually, then when the form is re-rendered it references the selectlist again and deletes whatever is in it to comply to the code.

Essentially, the text box only listens to the selectlist, whereas I want it to be somewhat like:

IF the textbox has text in it, THEN ignore the query and just set the text that is currently in it.

Is it possible to do this?

EDIT: By the way, the selectlist rerenders the form but I'm figuring i'll need to either add an actionsupport to the textbox to rerender the form or a button, I'm fine with either one.

  • Not directly related to your question, but if you want to make your code more readable and shorter, you can use the 'foreach' syntax (for (String temp: compressedAddresses)), remove the 'else' block, and instead of doing i + 10000000 (very ugly), just use break; – mkorman Jan 12 '16 at 19:10
1

At the beginning of the get section of the string:

if(Address1 != null){
            ApexPages.currentPage().getParameters().put('Address1',Address1);
            AddressValue = ApexPages.currentPage().getParameters().get('Address1');

then put all of the current code in the else statement and return the addressvalue!

Make sure to check and see if the selectlist is custom

0

I would use this address value inside a javascript block on the page and use it to fill the value of the input IF needed. ie:

<script>

    var address1 = '{!Address1}';
    var inputElements = document.getElementsByClassName('yourClass');
    var inputElement = inputElements[0];
    //you will have to verify that this works - this is just example code

    if (!inputElement.value){
        inputElement.value = address1;
    }
</script>

You can make sure this gets rerendered also by putting it in the page in an apex element.

Hope this helps.

  • This does help but I ended up doing what my answer is below. – JMK Jan 12 '16 at 19:53
  • Looks like a good solution – Caspar Harmer Jan 12 '16 at 19:58

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.