无法将数据保存到ATG中的数据库中

时间:2016-07-21 08:56:27

标签: atg atg-dynamo

我是ATG的新手,我创建了样本注册表单,其中包含名字,姓氏,性别等字段。我希望将这些数据保存在数据库中。我已经在SQL Developer中创建了表,用户配置文件也在创建,但我输入的任何值都没有添加到数据库中。如果有人知道请帮助我。以下是示例代码:

TestProfileFormHandler.java

<div>decimal:  &#128512;</div>
<div>hex:      &#x1f600;</div>

register.jsp

public class TestProfileFormHandler extends GenericFormHandler{

protected ProfileTools mProfileTools;
private MutableRepository mSampleRepository;
private String mFirstName;
private String mLastName;
private String mLogin;
private String mCreateSuccessURL;
private String mCreateErrorURL;
private String mProfileType = "user";
private String mRepositoryId;

public boolean handleCreate(DynamoHttpServletRequest pRequest,DynamoHttpServletResponse pResponse)throws ServletException,IOException,RepositoryException{

    RepositoryItem newUser = createUser(pRequest,pResponse);
    if(newUser!=null){
        setRepositoryId(newUser.getRepositoryId());
    }
    return checkFormRedirect(getCreateSuccessURL(), getCreateErrorURL(), pRequest, pResponse);
}

protected RepositoryItem createUser(DynamoHttpServletRequest pRequest,DynamoHttpServletResponse pResponse)throws ServletException,IOException,RepositoryException{

    MutableRepository lSampleRepository = (MutableRepository) getSampleRepository();
    MutableRepositoryItem lItem = null;
    RepositoryItem lRepoItem = null;
    String lLogin = getLogin();
    lItem = createProfileItem(pRequest,pResponse);
    lItem.setPropertyValue("firstName",getFirstName());
    lItem.setPropertyValue("lastName", getLastName());
    lItem.setPropertyValue("login", getLogin());
    lSampleRepository.updateItem(lItem);
    return lSampleRepository.getItem(lItem.getRepositoryId(), getProfileType());
}
protected MutableRepositoryItem createProfileItem(DynamoHttpServletRequest pRequest,DynamoHttpServletResponse pResponse)throws ServletException,IOException,RepositoryException{

    MutableRepository lProfile = getSampleRepository();
    MutableRepositoryItem lMutItem = null;

        RepositoryItem lCurrentUser = lProfile.createItem(getProfileType());
        String lProfileId = lCurrentUser.getRepositoryId();
        lMutItem = lProfile.getItemForUpdate(lProfileId,getProfileType());
    return lMutItem;

}

TestProfileFormHandler.properties <dsp:page> <dsp:importbean bean="/atg/userprofiling/TestProfileFormHandler"/> <dsp:getvalueof id="success" param="added"/> <c:if test="${success eq true}"> Account created successfully. </c:if> <dsp:form name="registerForm" id="registerForm" method="post"> <div> <label>First Name</label> <span>*: </span> <dsp:input type="text" name="firstName" bean="TestProfileFormHandler.firstName" /> </div> <div> <label>Last Name</label> <span>*: </span> <dsp:input type="text" name="lastName" bean="TestProfileFormHandler.lastName" /> </div> <div> <label>Email Address</</label><span>*:</span> <dsp:input type="text" name="login" bean="TestProfileFormHandler.login" /> </div> <dsp:input type="hidden" value="/test/register.jsp?added=true" bean="TestProfileFormHandler.createSuccessURL"/> <dsp:input type="hidden" value="/test/register.jsp?added=false" bean="TestProfileFormHandler.createErrorURL"/> <dsp:input type="submit" value="Create Account" bean="TestProfileFormHandler.create"/> </dsp:form>

1 个答案:

答案 0 :(得分:1)

要使刚刚创建的存储库项持久 addItem(justCreatedRepositoryItem)方法应该被调用。由于您没有保留新项目,因此您无法在数据库中看到它。

另请注意, addItem(MutableRepositoryItem pItem)会返回一个新的repositoryitem(可能具有不同的id),表示存储库中的持久项。因此,要查看DB新创建的项目中的更新应该用于修改。