0

I'm new to ATG, i have created sample registration form with fields like first name,last name,gender etc. I want these data s to be saved in database. I've already created table in SQL Developer, user profile is also creating but whatever values i have entered is not adding into the database. If anyone knows please help me. Below is the sample code :

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

Ramya jois
  • 29
  • 5
  • You need to tell us what you tried and what failed. It's hard to help you like that. – David Gourde Jul 21 '16 at 09:14
  • What is the caching model on your `item-descriptor`? Unless the cache is disabled, you won't see the data being persisted immediately. – radimpe Jul 21 '16 at 09:44
  • Cache mode is disabled only. Is it possible to save data into database using *QueryBuilder*?if yes, how? – Ramya jois Jul 21 '16 at 10:40
  • I suggest you post your sample code here. When it comes to working with repository items, I'd be reluctant to use it in a non-standard way since you'll lose all benefit of using the repository in the first place. – radimpe Jul 22 '16 at 08:48

1 Answers1

1

To make just created repository item persistent addItem(justCreatedRepositoryItem) method should be called. As you didn't persist your new item, you don't see it in DB.

Also note, that addItem(MutableRepositoryItem pItem) returns a new repositoryitem (with potentially a different id) that represents a persistent item in the repository. So to see updates in DB newly created item should be used for modifications.

Yekaterina
  • 51
  • 3