|
Re: AbstractForm newly created ID [message #1076119 is a reply to message #1075797] |
Tue, 30 July 2013 18:41 |
Jeremie Bresson Messages: 1252 Registered: October 2011 |
Senior Member |
|
|
For the server part, I think it really depends on your database engine.
With Derby, I have implemented it like this:
@Override
public QuestionFormData create(QuestionFormData formData) throws ProcessingException {
if (!ACCESS.check(new CreateQuestionPermission())) {
throw new VetoException(TEXTS.get("AuthorizationFailed"));
}
SQL.insert(" insert into questions (question_text, multiple_choices) " +
" values (:QuestionText, :MultipleChoices) ", formData);
SQL.selectInto(" values IDENTITY_VAL_LOCAL() " +
" into :QuestionNr", formData);
if (formData.getQuestionNr() == null) {
throw new ProcessingException("QuestionNr can not be null");
}
return formData;
}
With an oracle DB, we often select from a sequence before inserting.
The important point is to store the ID you want to access (QuestionNr in my case) in the FormData. If you are not sure, you can debug it or use System.out.println to test it (in the formData you return in the create function)
On the client, you will have something like this in your form handler:
public class NewHandler extends AbstractFormHandler {
@Override
public void execLoad() throws ProcessingException {
IQuestionProcessService service = SERVICES.getService(IQuestionProcessService.class);
QuestionFormData formData = new QuestionFormData();
exportFormData(formData);
formData = service.prepareCreate(formData);
importFormData(formData);
}
@Override
public void execStore() throws ProcessingException {
IQuestionProcessService service = SERVICES.getService(IQuestionProcessService.class);
QuestionFormData formData = new QuestionFormData();
exportFormData(formData);
formData = service.create(formData);
}
}
This is the code that is generated when you create a new form, so I assume you have something like this.
In the FormData that you get with "service.create(formData)" at the end of execStore() you should have the value that you are looking for.
A possibility: (but at this point you can do what you want with the value)
It is possible to import the values contained in the formData in the Form:
@Override
public void execStore() throws ProcessingException {
IQuestionProcessService service = SERVICES.getService(IQuestionProcessService.class);
QuestionFormData formData = new QuestionFormData();
exportFormData(formData);
formData = service.store(formData);
importFormData(formData); //<-- New line
}
This way, you will be able to get the value from the form:
@Override
protected void execAction() throws ProcessingException {
QuestionForm form = new QuestionForm();
form.startNew();
form.waitFor();
if (form.isFormStored()) {
System.out.println(form.getQuestionNr());//<-- The value is here [you could do setValue(..)]
reloadPage();
}
I hope this helps you to understand how it works.
Do not hesitate to ask if you need more informations.
[Updated on: Tue, 30 July 2013 18:41] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02974 seconds