You need to sign in to do that
Don't have an account?
question on <apex:inputText>..plz help!!!!
Hello
can anyone please throw some ideas..on how to solve the below issue ....many thanks in advance
My requirement is to display a text box with Account Name prefilled in it. And also users can edit the text in that texbox.
When search button is clicked, the text in the textbox should be passed to the controller to get the records.
How can i pass the textbox value to the controller.
i know we should pass the values like this...
<apex:inputText id="AcName" value="{!searchText}"/>
but since i need to prefilled with the Account name, i cannot go with the above way...please advise...
<apex:page tabStyle="Account" controller="Account_controller" action="{!init}">
<apex:form>
<apex:pageBlock title="Account Delete">
<apex:pageBlockSection title="Account Search">
<apex:pageBlockSectionItem >
<apex:panelGroup >
<apex:outputLabel for="AcName">Account Name: </apex:outputLabel>
<apex:inputText id="AcName" value="{!AccountName.Name}"/>
<apex:commandButton id="Search1" value=" Search " action="{!search}" reRender="AccountDetail" accesskey="\r\n"/>
</apex:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
public class Account_controller
{
private String searchText;
public Account acctName;
Id AcctId = ApexPages.currentPage().getparameters().get('id');
public Account getAccountName()
{
return acctName;
}
public string getSearchText()
{
return searchText;
}
public void setSearchText (String searchText)
{
this.searchText = searchText;
}
List<Account> AccountResults=null;
public List<Account> getAccountResults()
{
return AccountResults;
}
public PageReference init()
{
acctName=[Select Name from Account where id=:AcctId];
return null;
}
public void search()
{
try
{
// Account acName=[Select Name from Account where id=:AcctId];
// AccountResults= (List<Account>)[select Id, Name, Type, BillingStreet,Billingcity,BillingState,BillingPostalCode,Owner.Name from Account where Name like: acName.Name+'%'];
AccountResults= (List<Account>)[select Id, Name, Type, BillingStreet,Billingcity,BillingState,BillingPostalCode,Owner.Name from Account where Name like: searchText+'%'];
}
catch (Exception e)
{
AccountResults = (List<Account>)null;
System.Debug('Error in search criteria.');
}
}
}
U can still use
<apex:inputText id="AcName" value="{!searchText}"/>
Define a get and set method...
In the get method return Account.name.... This will ensure that the box is prefilled
In the set method store the value typed in a variable... Query using this variable...
Check this if you are not clear http://salesforceexperts.blogspot.com/2009/07/getter-and-setter-methods-what-are-they.html
Hope this helps...
All Answers
try it.
<apex:inputText id="AcName" value="{!account.Name}"/>
Thanks for the response.
I did already tried that. And it is working fine.
My question is, for example
Say the Account Name is Dunkin Donuts then i am able to display it in textbox.
When user deletes Donuts from Dunkin Donuts then the text will be Dunkin and i have to query using Dunkin not Dunkin Donuts.
if i write like this <apex:inputText id="AcName" value="{!account.Name}"/> then query will search with Account Name (Dunkin Donuts) and not Dunkin...
Please let me know if anything is unclear...thank you
1.What mechanism yours user is using to delete "Donuts"
2.After deleting r u saving the records in Account Object
U can still use
<apex:inputText id="AcName" value="{!searchText}"/>
Define a get and set method...
In the get method return Account.name.... This will ensure that the box is prefilled
In the set method store the value typed in a variable... Query using this variable...
Check this if you are not clear http://salesforceexperts.blogspot.com/2009/07/getter-and-setter-methods-what-are-they.html
Hope this helps...
Edwin -
Got you....thanks a bunch.. it worked.. the get set methods article was very explanatory...Now i really clearly understand about get set methods..
gv007 - Users just delete Donuts in the textbox using backspace or delete keys..and after deleting Donuts i am not saving it on Account Object..i just want to do a search using the text in the textbox
Here is the working code if any one have the same issue..
<apex:inputText id="AcName" value="{!searchText}" tabindex="0">
private String searchText;
public string AName;
public PageReference init()
{
acctName=[Select Name from Account where id=:AcctId];
AName=acctName.Name;
return null;
}
public string getSearchText()
{
return AName;
}
public void setSearchText (String searchText)
{
this.searchText = searchText;
}
Thanks again..