atg发电机-无法将数据保存到atg中的数据库中



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

TestProfileFormHandler.java

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;
}

register.jsp

<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>

TestProfileFormHandler.properties $class=com.tap.userprofiling.TestProfileFormHandler $scope=global sampleRepository=/com/tap/repository/SampleRepository dataSource=/atg/dynamo/service/jdbc/JTDataSource

要使刚刚创建的存储库项持久化,应调用addItem(justCreatedRepositoryItem)方法。由于您没有持久化您的新项目,所以在DB中看不到它。

另外请注意,addItem(MutableRepositoryItem pItem)返回一个新的存储库项目(可能具有不同的id),该项目表示存储库中的持久项目。所以为了在数据库中看到更新,新创建的项目应该用于修改。

相关内容

  • 没有找到相关文章

最新更新