0

我的对象是Consumer

这是一个Consumer对象具有以下字段并要创建记录。但是报空指针异常。

视觉力量页面:

<apex:page controller="signup1" >
<apex:form >
<h1>User SignUp</h1>
<apex:panelGrid columns="2" style="margin-top:2em;">
<p><b>Name :</b><br />
<apex:inputField id="name" value="{!con.Name}"/>
</p>
<p><b>Address :</b><br />
<apex:inputField id="address" value="{!con.address__c}"/>
</p>
<p><b>Email Id :</b><br />
<apex:inputField required="true" id="emailid" value="{!con.email_id__c}"/>
</p>
<p><b>Password :</b><br />
<apex:inputSecret id="password" value="{!con.password__c}"/>
</p>
<p><b>Confirm Password :</b><br />
<apex:inputSecret id="confirmpassword" value="{!con.Confirm_Password__c}"/>
</p>
<p><b>Security Question :</b><br />
<apex:inputField required="true" id="securityquestion" value="{!con.Security_Question__c}"/>
</p>
<p><b>Answer :</b><br />
<apex:inputField required="true" id="answer" value="{!con.Answer__c}" />
</p>
<p><b>Ph No :</b><br />
<apex:inputField required="true" id="phno" value="{!con.phone__c}"/>
</p>
<p><b>Pan Card No :</b><br />
<apex:inputField required="true" id="pancardno" value="{!con.Pan_Card_No__c}"/>
</p>
<p> <apex:commandButton action="{!registerUser}" value="SignUp" id="SignUp"/></p>
</apex:panelGrid>
</apex:form>
</apex:page>

controller :
public class signup1
{

    Consumer__c con = new Consumer__c();

    public void signup1()
    {
        con = [SELECT Name, address__c, email_id__c, password__c, Confirm_Password__c, Security_Question__c, Answer__c, phone__c from Consumer__c where  Name =: ApexPages.currentPage().getParameters().get('Name')];
    }

    public Consumer__c getcon()
    {
    return con;
    }

  public PageReference registerUser() 
  {
      try
      {
          insert Con;
      }
      catch(System.DMLException e)
      {
         ApexPages.addMessages(e);
         return null;
      }

      PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
      pageRef.setRedirect(true);
      return pageRef;
  } 
}

Consumer由于 null 异常,我无法将数据插入到对象中。

4

3 回答 3

0

您没有将从 VF 页面检索到的值设置到控制器中的任何参数中。首先设置它们。然后创建一个消费者类型的对象,然后将这些值从 VF 页面分配到对象的字段中。只有这样你才能插入骗局。

于 2015-04-09T12:45:26.617 回答
0

在您的 Visual Force 页面中无法访问消费者,因为它没有 getter 或 setter 方法。

public class signup1
{
   public Consumer__c con {get; set;}

   public signup1()
   {
     try
     {
       // Make sure 'ApexPages.currentPage().getParameters().get('Name')' is indeed not null.
       con = [SELECT Name, address__c, email_id__c, password__c, Confirm_Password__c, Security_Question__c, Answer__c, phone__c from Consumer__c where  Name =: ApexPages.currentPage().getParameters().get('Name')];
     }
     catch(Exception ex)
     {
        system.debug(ex.getMessage());
     }
   }
    ..............
}
于 2015-03-16T17:35:13.980 回答
0

这种编码完全错误。1. 从客户对象中提取字段 Name、address__c、email_id__c、password__c、Confirm_Password__c、Security_Question__c、Answer__c 和 phone__c 的目的是什么,仅作为输入字段。2. 为什么你没有客户对象上的标准控制器。3. 如果您是根据名称取值,您需要在名称字段旁边放置搜索按钮并取值。

问候,PK

于 2015-03-16T00:36:33.213 回答