2
votes

I have the following Visualforce page, and apex class as controller. I would like to pass valus in the input text boxes contain th ids inputText1 and InputText2 to the same variable in the following apex class.

Everytime, the inputText1 and inputText2 in the apex class is null, and I don't know why! Iv'e bin sitting on it all day long, and I couldn't figgure out why it happens!

Please help me with that, because I'm feeling hopeless with that.

<apex:page controller="LoginPages" rendered="true" showHeader="false" sidebar="false" standardStylesheets="true">
<apex:Pagemessages id="msg"/>
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlock >
<apex:form >
<p><b>Login Page</b><br /></p>
<apex:panelGrid columns="2" style="margin-top:1em;">
<p><b>UserName</b><br />
<apex:inputtext required="true" id="inputText1" value="{!inputText1}"/>
</p>
<p><b>Password</b><br />
<apex:inputtext id="inputText2" value="{!inputText2}"/>
</p>
 <apex:commandButton action="{!loginUser}" value="login" id="login"  immediate="true"/>
 </apex:panelGrid>
</apex:form>
</apex:pageBlock>

</apex:page>




public class LoginPages{


   public String inputText1;
    public String inputText2;

    public String getInputText1(){
        return inputText1;
    }

    public void setInputText1(String str1){
        inputText1 = str1;
    }

        public String getInputText2(){
        return inputText2;
    }

    public void setInputText2(String str2){
        inputText1 = str2;
    }



    public PageReference registerUser() {
        PageReference newPage = new PageReference('/apex/newPage');
        newPage.setRedirect(true);
        return newPage;
    }

    public void  loginUser() {
        ApexPages.Message mymsg = new ApexPages.Message(ApexPAges.Severity.INFO, 'sdsdf' +  inputText1);
        apexpages.addMessage(mymsg);
       // PageReference newPage = new PageReference('/apex/login');
       System.debug('sdfsdf' + inputText1);     

        List<User__c> users = [Select Name, Password__c from User__c Where Name = :inputText1];
        if (users.size() > 0){
            for (User__c user : users){
                if (user.Password__c == inputText2){
                           //newPage.setAnchor('/apex/catalog');
                        //newPage.setRedirect(true);

                }
            }   
        }
        //return newPage;

    }
}
1

1 Answers

4
votes

Remove immediate="true". "Immediate" results in no data being passed from the form to the server.

Also - you could write your variables bit simpler and then you won't need the explicit getXYZ/setXYZ methods:

public String inputText1 {get;set;}