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
javierjiesjavierjies 

how to send data from VF Page

hello everyone!!

 

I have a VF Page where I want to let people log in.

 

With an Input I want to write the Username, and then clic in a log-in button where I call a function.

 

I've done a Page like this:

 

<apex: page showHeader="false" controller="LogInLogOut">
  <apex:form >
        <apex: outputLabel for="InputText" value="UserName: " />
        <apex:inputText title="UserName" value="{!User}" id="theUserName"/>
   </apex:form>

</apex: page>

 

And the class LogInLogOut is like this:

 

public class LogInLogOut{

public void LogInLogOut(ApexPages.StandardController stdController) {   
}

public String User{get;set;}

public PageReference LogIn()
{

    boolean  alreadyUser=false;
    for(Account C:[select UserName__c from Account limit 1])
    {
        if(C.UserName__c==User)
        {
            alreadyUser=true;
        }
    }

}

 

 

But It doesn't work!!

 

Any idea?!?!?

 

Thanks in advance!!!!!

Message Edited by javierjies on 10-06-2009 12:07 AM
Best Answer chosen by Admin (Salesforce Developers) 
prageethprageeth

Your code worked properly when I did following changes. I have marked those with green color.

Controller: 

global class LogInLogOut{

public void LogInLogOut(ApexPages.StandardController stdController) {}

public String User{get;set;}

public pageReference LogIn() {

boolean alreadyUser = false;

for(Account C:[select UserName__c from Account limit 1]){

if(C.UserName__c == User){

alreadyUser=true;

return page.successPageName;//name of the page that you want to move if user name is correct

}

}

return null;//nothing happens if userName is incorrect

} 

 

Page: 

<apex:page showHeader="false" controller="LogInLogOut">

<apex:form>

<apex:outputLabel for="InputText" value="UserName: " />

<apex:inputText title="UserName" value="{!User}" id="theUserName"/>

<apex:commandButton value="Click to Login" action="{!logIn}"/>

</apex:form> 

</apex:page> 

 

If this doesn't solve your problem please supply more info. 

All Answers

XactiumBenXactiumBen

Don't you need to query the Account, trying to match the User variable with a.Username__c?

 

To do that you would do something like:

 

public PageReference LogIn() { boolean alreadyUser=false; List<Account> accs = [select UserName__c from Account where UserName__c = :User limit 1]; if (accs.size() == 1) alreadyUser = true; }

 

prageethprageeth

Your code worked properly when I did following changes. I have marked those with green color.

Controller: 

global class LogInLogOut{

public void LogInLogOut(ApexPages.StandardController stdController) {}

public String User{get;set;}

public pageReference LogIn() {

boolean alreadyUser = false;

for(Account C:[select UserName__c from Account limit 1]){

if(C.UserName__c == User){

alreadyUser=true;

return page.successPageName;//name of the page that you want to move if user name is correct

}

}

return null;//nothing happens if userName is incorrect

} 

 

Page: 

<apex:page showHeader="false" controller="LogInLogOut">

<apex:form>

<apex:outputLabel for="InputText" value="UserName: " />

<apex:inputText title="UserName" value="{!User}" id="theUserName"/>

<apex:commandButton value="Click to Login" action="{!logIn}"/>

</apex:form> 

</apex:page> 

 

If this doesn't solve your problem please supply more info. 

This was selected as the best answer
javierjiesjavierjies

Thanks prageeth,It works perfectly!!

 

Now I want to do the same with a picklist. I have the object Person__c and I want to select his job. In the class I have:

Public Person__c Info{get;set;}

 

 

And the Page;

 

<apex:form >

 

<apex:selectList value="{!Info.Job_Category__c}" multiselect="false" size="1">
                <Option value=''>-- Select an option --</Option>
               
                 <option value='Manager'>Account Manager</option>
               
                 <option value='Senior Manager'>Senior Manager</option>
               
                 <option value='Executive'>Executive</option>
                
                 <option value='Senior Executive'>Senior Executive</option>
               
                </apex:selectList>

<apex:commandButton action="{!WhatHisJob}" value="Continue" id="submit" /> 

</apex:form >

 

 

Any idea?!?!?

 

Thanks!!!!!!!

Message Edited by javierjies on 10-06-2009 07:31 AM
prageethprageeth

Hello 

 

    I don't know whether I have understood you question correctly.  However sometimes following code will help you.

If this is not the answere that you expected, please tell us what you really want to do. 

 

Controller:

global class JobSelect{

Public Person__c Info{get;set;}

public JobSelect() {

Info = [select Job_Category__c from Person__c limit 1];

}

 

public void WhatHisJob() {

update Info;//This is needed only if you want to save the new job

//your code here

}

 

public List<SelectOption> getJobList() {

List<SelectOption> options = new List<SelectOption>();

options.add(new SelectOption('No Job','-- Select an option --'));

options.add(new SelectOption('Manager','Account Manager'));

options.add(new SelectOption('Senior Manager','Senior Manager'));

options.add(new SelectOption('Executive','Executive'));

options.add(new SelectOption('Senior Executive','Senior Executive'));

return options;

}

 

VF Page: 

 

<apex:page Controller="JobSelect" >

<apex:form >

<apex:selectList value="{!Info.Job_Category__c}" multiselect="false" size="1">

<apex:selectOptions value="{!jobList}"></apex:selectOptions>

</apex:selectList>

<apex:commandButton action="{!WhatHisJob}" value="Continue" id="submit" />

</apex:form >

current job = {!Info.Job_Category__c} 

</apex:page>