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
ShaikAShaikA 

How to pass user enter values to visualforce component from apex controller

Hi All,

I have a requirement, where i have to send email notification along with vf page as attachement for this i have create visualforce component, visualforce email template and visualfroce page with having Send Email button.
everything working as expected but here i am facing a challenge to pass user enter inputs on vf page to visualforce component, please help how i can pass location, selecteddate,otherRequest values to visualforce component. 

My vf page:
<apex:page controller="emailattachementController" sidebar="false" showHeader="false" cache="true" docType="html-5.0">
  <html lang="en">
<head>
<style>
table {
    border-collapse: collapse;
     width: 100%;
}

table, td, th {
    border: 1px solid black;
}
</style>
<script>
function sentemail(){
    asentEmail();
}
</script>
</head>

<body>
<apex:form >
<apex:actionFunction name="asentEmail" action="{!sendEmail}" />

<div class="container-fluid">
<div class="row">
    <div class="col-sm-12">
        <apex:commandlink onclick="sentemail(); return false;"  style="Margin-right:35px"  styleclass="btn btn-info navbar-right css-m-right--small css-m-top--small" type="button" >
            <i class="fa fa-envelope" aria-hidden="true"></i> Sent Email
        </apex:commandLink> 
    </div>
</div>
</div>
<p><apex:outPutText value="Account Information"/></p>
<table >
<tr>
    <td><apex:outputText value="Name" /></td>
    <td><apex:outputText value="{!acclist.Name}" /></td>
</tr>
<tr>
    <td><apex:outputText value="Type" /></td>
    <td><apex:outputText value="{!acclist.Type}" /></td>
</tr>
<tr>
    <td><apex:outputText value="Date & Location of Meeting" /></td>
    <td><apex:input type="date" value="{!selectedDate}" html-placeholder="Click here to enter a date."/></td>
    <td><apex:inputText value="{!location}" html-placeholder="Location"/></td>
</tr>
<tr>
    <td><apex:outputText value="Other Requests:" /></td>
    <td colspan="2"><apex:inputText value="{!otherRequest}"/></td>
</tr>
</table>
</apex:form>
</body>
</html>
</apex:page>

Controller:
Public class emailattachementController{
public Account acclist{get;set;}
public Date selectedDate{get;set;}
public string location{get;set;}
public string otherRequest{get;set;}
public Id urlaccId {get;set;}
Public string Received_String {get;set;}

public emailattachementController(){
    urlaccId =ApexPages.currentPage().getParameters().get('Id');
    acclist=[select id, Name,Type,Owner.Name,Owner.Phone From Account Where id=:urlaccId limit 1];
        Received_String='testinggggg';
}

public void sendEmail(){
system.debug('selectedDate>>'+selectedDate);
system.debug('exeName>>'+exeName);
system.debug('otherRequest>>'+otherRequest);

    emailtemplate template=[select id,Name,FolderId,Subject,Description from EmailTemplate where Name=:'My Email Template'];
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setTargetObjectId(UserInfo.getUserId());//this is for whom  you want send email
    mail.setTemplateId(template.id);
    mail.setSaveAsActivity(false);
    mail.setToAddresses( new List<String>{ 'sfdc@gmail.com'} );
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}

Visualforce Component:
<apex:component controller="emailattachementController" access="global" >
<apex:attribute name="InputString" type="String" assignTo="{!Received_String}" description="teeeee"/>

  <html lang="en">
<head>
 
<style>
table {
    border-collapse: collapse;
     width: 100%;
}

table, td, th {
    border: 1px solid black;
}

</style>

</head>

<body>
<p><apex:outPutText value="Account Information"/></p>
<table >
<tr>
    <td><apex:outputText value="Name" /></td>
    <td><apex:outputText value="{!acclist.Name}" /></td>
</tr>
<tr>
    <td><apex:outputText value="Type" /></td>
    <td><apex:outputText value="{!acclist.Type}" /></td>
</tr>
<tr>
    <td><apex:outputText value="Date & Location of Meeting" /></td>
    <td><apex:input type="date" value="{!selectedDate}" html-placeholder="Click here to enter a date."/></td>
    <td><apex:inputText value="{!location}" html-placeholder="Location"/></td>
</tr>
<tr>
    <td><apex:outputText value="Other Requests:" /></td>
    <td colspan="2"><apex:inputText value="{!otherRequest}"/></td>
</tr>
</table>
</body>
</html>
</apex:component>

Visualforce email Template:
<messaging:emailTemplate subject="testing subject" recipientType="User" relatedToType="Account">
<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody> 
<messaging:attachment renderAs="pdf" filename="testing.pdf">
<c:emailTemplateComponent />
    </messaging:attachment>
</messaging:emailTemplate>

Thanks in advance,
Shaik