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
SamarthyaSamarthya 

apex:inputText - Fetch the text entered

I have defined a component that gets the values of indvidual text elements when <apex:commandButton> is pressed, but when I try to call some function using AJAX and use this object, it never gets filled (Still ooking for reasons..).

 

Only way left for me is to get these values individually create a new object with these values and use it in the function called for AJAX using apex:actionFunction + apex:param.

 

can anyone tell me how to get data from inputText and pass it, or best if someone can help me out how to pass an object with these values.

 

I am still quite new to topic but am learning every day.

 

- Samarthya

bob_buzzardbob_buzzard

If you are using an ActionFunction component, the inputfield value should be submitted back to the controller prior to the associated action method being invoked.

 

If you post your code you might get some further insight.

SamarthyaSamarthya

I am not using action function component. (if i understood correctly)

 

 

<apex:actionFunction id="callAFWS" immediate="true" name="callAFWS" action="{!callWSAJAX}" reRender="dataRecvd" status="statusWS">                                                                                 
                    </apex:actionFunction>

 This is what the action function does simply call a controller function.

 

 

<apex:outputPanel id="testAjax" onclick="callWS()" styleClass="btn"> Get Candidates 
</apex:outputPanel>
<apex:outputpanel id="dataRecvd">
<apex:actionStatus id="statusWS">
<apex:facet name="stop">Text {!strData} </apex:facet>                            
</apex:actionStatus>
</apex:outputpanel>

 The above is the call where I make a java script call that calls the actionFunction.

 

And I have a simple class address with few properties.

 

The corresponing controller for the TestPage is

 

public class TestpageController
{
    public Address address
    {
        get;
        set;
    }
    
    public PageReference submit()
    {
        if(address != null)
            address.street = 'not null';
        return null;
    }
    
    public PageReference reload()
    {
        return null;
    }
    
    public String strData
    {
        get;
        set;
    }
    
    private void convertToString()
    {
        strData = address.street + ' ' + address.country + ' ' +address.pincode;
    }
    
    public void callWSAJAX()
    {
        if((address == null) || (address.street == null) || (address.street.length() == 0))
        {
            address = new Address();
            address.street='new address';
            address.country='wonderland';
        }
        
        convertToString();
    }
}

 

 

When the outputPanel is cliked the address is set as null and that is my problem which I expect to put in value inserted in text boxes.

 

and this is the component I have defined.

 

 

<apex:component >
    <apex:attribute name="Address" type="Address"/>
        <div>
        <label for="AddressValue">{!$Label.Street}</label>
        <apex:inputText id="AddressValue" tabindex="1" styleClass="inputField"  value="{!Address.street}"/>
        <!-- ensure focus to this element after loading -->
        <script type="text/javascript">$(escId('{!$Component.AddressValue}')).focus();</script>
    </div>
    
    <div>
        <label for="Country" >{!$Label.Country}</label>
        <apex:inputText id="Country" tabindex="2" styleClass="inputField"  value="{!Address.country}"/>
    </div>
    
    <div >
        <label for="PinCode" >{!$Label.Pincode}</label>
        <apex:inputText id="PinCode" tabindex="3" styleClass="inputField"  value="{!Address.pincode}"/>
    </div>

        
    
</apex:component>

 

 

 

 

Pradeep_NavatarPradeep_Navatar

You can bind the inputText value to getter-setter property in controller, and after clicking the button it can be accessable in controller :

 

// Defined the property in controller

Public string name{get; set;}

// bind the inputText value in page to this property

<apex:inputText value=”{!name}” id=”xyz”/>

 

If you want to access this value within page and want to use in AJAX call, then you can get this value like this using java script :

 

Var name=document.getElementById(“{!$Component.xyz}”).value;

SamarthyaSamarthya

Thank you for the reply, I did find this in other solutions when I googled. But my problem is When I have a Apex class dedicated for the values I have defined using individual string values would be redundant and improper. That is why I was looking for some other candidate solution.

 

Also, please correct me if I am wrong. When I define a component and use it in a Apex Page the object is implictily initialized, that is; If I have a single object of a class defined (as in code above - Address) the setter is called with the value, but what if I define a object of similar type in the code say Address add2?

 

- Samarthya

SamarthyaSamarthya

Any help pointers anyone?