Hey,
I have an application that consist of 2 entities and. The 2 entities are called Meeting and Participant.
The Meeting Entity:
The Participant entity:
What code can i use to automatically add the user who created the meeting as a participant of the meeting that has been created. The participant entry should be linked to the meeting that has just been created through the meeting_id attribute.
Regards
kxb_pro
(Kirill Khoroshilov)
December 29, 2017, 11:25am
#2
Hey!
Add new field participants (composition) to Meeting entity (one-to-many).
Add to meeting editor new nested collectionDataSource paticipantsDs use new field.
Inject to editor screenController this datasource.
Use preCommit() method in Meeting editor screen controller.
@Inject
protected CollectionDatasource<Participant, UUID> paticipantsDs;
@Override
protected boolean preCommit() {
Participant participant = metadata.create(Participant.class);
participant.setMeeting_id(getItem());
participant.setName(UserSession.getCurrentOrSubstitutedUser());
//set other entity fields
paticipantsDs.add(participant);
return true;
}
Hey,
It giving a null NullPointerException when you click OK to create the meeting.
Regards
kxb_pro
(Kirill Khoroshilov)
January 4, 2018, 12:33pm
#4
Hey, Susan!
Most likely you need to inject metadata into the screen controller
@Inject
protected Metadata metadata;
or post source code your meeting editor screen controller.
Hey,
Here is the source code in my meeting editor screen controller.
package com.company.agenda.web.meeting;
import java.util.Map;
import java.util.UUID;
import javax.inject.Inject;
import com.company.agenda.entity.Meeting;
import com.company.agenda.entity.Part_Type;
import com.company.agenda.entity.Participant;
import com.company.agenda.service.AgendaService;
import com.haulmont.cuba.gui.components.AbstractEditor;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.security.global.UserSession;
import com.vaadin.ui.Notification.Type;
import com.haulmont.cuba.core.global.Metadata;
public class MeetingEdit extends AbstractEditor<Meeting>
{
//@Inject
//WindowActionsFrame windowActions;
//@Inject
@Inject
private UserSession userSession;
@Inject
private Metadata metadata;
@Inject
private AgendaService agenda;
@Inject
protected CollectionDatasource<Participant, UUID> paticipantsDs;
@Inject
private Part_Type part_type;
public void init (Map<String , Object> param)
{
//addCloseListener(null);
}
@Override
protected boolean preCommit()
{
Participant participant = metadata.create(Participant.class);
participant.setMeeting_id(getItem());
participant.setName(userSession.getCurrentOrSubstitutedUser());
participant.setType(part_type.Secretary);
//set other entity fields
paticipantsDs.add(participant);//.add(participant);
return true;
}
public void onAddBtnClick()
{
//User user = userSession.getSubstitutedUser();
getDsContext().commit();
//Meeting meeting = null;
//agenda.DefaultParticipant(user, meeting);//Part_Type pt = null;
this.commitAndClose();
}
public void onCancelBtnClick()
{
this.close(CLOSE_ACTION_ID);
}
}
Regards,
kxb_pro
(Kirill Khoroshilov)
January 4, 2018, 3:39pm
#6
Susan.
part_type is enum?
kxb_pro
(Kirill Khoroshilov)
January 9, 2018, 8:00am
#8
Hey!
Remove this. Enum can be used without injection.