I have 2 parameters sent from menu followed by from List Screen to the detail screen which is working fine. However, it is not working in the following use case -
I am sending url in generated email for the detail screen for the user to open it directly. It is working for other screens but not this one.
Here is the controller code of list screen from where it is working smoothly:
protected String userType;
protected String waType;
@Autowired
private Dialogs dialogs;
@Override
public void beforeEnter(BeforeEnterEvent event) {
Map<String, List<String>> parameters = event.getLocation().getQueryParameters().getParameters();
if (parameters.containsKey("userType")) {
parameters.get("userType").stream()
.findAny()
.ifPresent(this::setUserType);
}
if (parameters.containsKey("waType")) {
parameters.get("waType").stream()
.findAny()
.ifPresent(this::setWaType);
}
super.beforeEnter(event);
}
public void setUserType(String uType) {
this.userType = uType;
}
public void setWaType(String wType) {
this.waType = wType;
}
@Subscribe
public void onQueryParametersChange(QueryParametersChangeEvent event) {
QueryParameters queryParameters = event.getQueryParameters();
// Extract userType from query parameters
String newUserType = queryParameters.getParameters().getOrDefault("userType", List.of()).stream()
.findFirst()
.orElse(null);
if (newUserType != null) {
userType = newUserType;
}
workAwayOfficesDl.setQuery(null);
// Reload data with the updated userType
loadListData();
}
private void loadListData() {
if ("hr".equals(userType)) {
workAwayOfficesDl.removeParameter("employeeProfileId");
List<UUID> companyIdList = inteaccMDGGeneralBean.getCompanyIdListAuthorized();
List<UUID> operatingLocationIdList = inteaccMDGGeneralBean.getOperatingLocIdListAuthorized();
List<UUID> funcAreaIdList = inteaccMDGGeneralBean.getFunctionalAreaIdListAuthorized();
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("companyIdList", companyIdList);
queryParams.put("workAwayType", waType.equalsIgnoreCase("wfa")? WorkAwayType.WORK_FROM_ANYWHERE : WorkAwayType.VISIT);
queryParams.put("operatingLocationIdList", operatingLocationIdList);
// Only include `functionalAreaList` if it's not empty
if (!funcAreaIdList.isEmpty()) {
queryParams.put("functionalAreaList", funcAreaIdList);
}
// Ensure the query dynamically handles `functionalAreaList`
workAwayOfficesDl.setQuery("select e from hr_WorkAwayOffice e " +
"where e.employeeProfile.company.id in :companyIdList " +
"and e.employeeProfile.operatingLocation.id in :operatingLocationIdList " +
"and e.workAwayType = :workAwayType " +
"and (:functionalAreaList is null or e.employeeProfile.functionalArea.id in :functionalAreaList)");
workAwayOfficesDl.setParameters(queryParams);
workAwayOfficesDl.load();
} else if ("employee".equals(userType)) {
workAwayOfficesDl.removeParameter("functionalAreaList");
workAwayOfficesDl.removeParameter("companyIdList");
workAwayOfficesDl.removeParameter("operatingLocationIdList");
UUID emplId = (UUID) sessionData.getAttribute("emplProfileId");
if (emplId == null) {
throw new IllegalStateException("Employee Profile ID is missing from session data");
}
workAwayOfficesDl.setQuery("select e from hr_WorkAwayOffice e " +
"where e.employeeProfile.id = :employeeProfileId and e.workAwayType = :workAwayType");
workAwayOfficesDl.setParameters(ParamsMap.of("employeeProfileId", emplId, "workAwayType", waType.equalsIgnoreCase("wfa") ? WorkAwayType.WORK_FROM_ANYWHERE : WorkAwayType.VISIT));
workAwayOfficesDl.load();
}
}
Here is what I have in email sending method:
(…MainServiceBean)
} else if (workflowStatus.equals(WorkflowStatus.RETURNED_FOR_CORRECTION)) {
subject = messages.getMessage("ApplicationReturnedSubject") + workflowTask.getWorkflow().getName();
// bodyText = "Your application no. " + workflowTask.getDocNumber() + " has been returned for correction ";
//Email link
String screenName = this.getScreenNameFromEntityName(workflowTask.getEntityName());
String fullurl = "";
String waType="";
if(workflow.getWfCategory().equals(WfCategory.WORK_FROM_ANYWHERE)){
fullurl = inteaccWorkflowServiceBean.getBaseUrl() + "/" + screenName + "/" + workflowTask.getEntityId() + "?&userType=employee&waType=wfa";
}else if(workflow.getWfCategory().equals(WfCategory.VISIT)){
fullurl = inteaccWorkflowServiceBean.getBaseUrl() + "/" + screenName + "/" + workflowTask.getEntityId() + "?&userType=employee&waType=visit";
}else {
fullurl = inteaccWorkflowServiceBean.getBaseUrl() + "/" + screenName + "/" + workflowTask.getEntityId() + "?&userType=employee";
}
String linkText = "Please click on the link below to display the application:\n\n" + fullurl +"\n\n\nThank you.";
log.info("fullurl " +fullurl);
bodyText = messages.getMessage("ApplicationReturned") + workflow.getName() +", Application no. "+ workflowTask.getDocNumber() +"\n\n"+linkText;
}
emailServiceBean.sendEmailToEmployee(subject, bodyText, workflowTask.getEmplProfile().getId());
This is the url generated:
http://localhost:8081/workAwayOffices/01961dec-16e5-7e2b-a58f-a9dabc04ecc3?&userType=employee&waType=wfa
When I click on the generated url, I get the following error:
Here is detail screen controller code:
protected String userType;
protected String waType;
public void setUserType(String uType) {
userType = uType;
}
public void setWaType(String wType) {
waType = wType;
}
protected boolean recallAppl;
public void setRecallAppl(boolean recallAppl1) {
recallAppl = recallAppl1;
}
EmployeeProfile employeeProfileApplicant = null;
@ViewComponent("tabSheet.tabDoc")
private Tab tabSheetTabDoc;
@Subscribe
public void onInit(final InitEvent event) {
workAwayOfficeLineDataGrid.addClassName("styling");
workAwayOfficeLineDataGrid.setPartNameGenerator(person -> {
if (person.getWeekendOrHoliday()==true) {
return "low-rating";
}
return null;
});
}
@Subscribe
public void onBeforeShow(final BeforeShowEvent event) {
if (entityStates.isNew(getEditedEntity())) {
getEditedEntity().setProcessState(ProcessState.DRAFT);
getEditedEntity().setDocDate(LocalDate.now());
getEditedEntity().setDestinationType(DestinationType.DOMESTIC);
final LeaveYear leaveYear = unconstrainedDataManager.load(LeaveYear.class)
.query("select l from mdg_LeaveYear l where l.currentLeaveYear = true")
.optional().orElse(null);
if (leaveYear != null) {
getEditedEntity().setLeaveYear(leaveYear);
} else {
notifications.create("You don't have access to leave year, please consult your admin")
.withDuration(3000)
.withCloseable(false)
.withType(Notifications.Type.ERROR)
.show();
}
if (userType==null || userType.equalsIgnoreCase("employee")) {
UUID emplId = (UUID) sessionData.getAttribute("emplProfileId");
if (emplId != null) {
loadEmployeeData();
}
} else { //hr
loadEmployeeList();
//If the transaction is created by HR user, approve it automatically and hide the workflow button
getEditedEntity().setProcessState(ProcessState.APPROVED);
initWorkflowBtn.setVisible(false);
}
} else {
if(recallAppl==false) {
employeeProfileField.setReadOnly(true);
if (getEditedEntity().getProcessState().equals(ProcessState.APPROVED) || getEditedEntity().getProcessState().equals(ProcessState.APPROVAL_IN_PROGRESS)
|| getEditedEntity().getProcessState().equals(ProcessState.REJECTED) || getEditedEntity().getProcessState().equals(ProcessState.CANCELLED))
this.setReadOnly(true);
}else{
if(recallAppl){
getEditedEntity().setProcessState(ProcessState.DRAFT);
}else{
if (getEditedEntity().getProcessState().equals(ProcessState.APPROVED) || getEditedEntity().getProcessState().equals(ProcessState.APPROVAL_IN_PROGRESS)
|| getEditedEntity().getProcessState().equals(ProcessState.REJECTED) || getEditedEntity().getProcessState().equals(ProcessState.CANCELLED))
this.setReadOnly(true);
}
}
this.displayFile();
}
if (userType==null || userType.equalsIgnoreCase("employee")) {
companyField.setReadOnly(true);
operatingLocationField.setReadOnly(true);
employeeProfileField.setReadOnly(true);
if (getEditedEntity().getProcessState().equals(ProcessState.APPROVED))
this.setReadOnly(true);
}
initWorkflowBtn.setVisible(true);
//For Workflow
if (inteaccWorkflowServiceBean.findWorkflowProfileByWfCategory(WfCategory.WORK_FROM_ANYWHERE, null) == null) {
initWorkflowBtn.setVisible(false);
} else {
if (getEditedEntity().getProcessState() == ProcessState.APPROVAL_IN_PROGRESS) {
saveAndCloseBtn.setVisible(false);
closeBtn.setText("CLOSE");
initWorkflowBtn.setVisible(false);
} else if (getEditedEntity().getProcessState() == ProcessState.APPROVED) {
if (entityStates.isNew(getEditedEntity())) {
//saveAndCloseBtn.setEnabled(false);
saveAndCloseBtn.setText("APPROVE");
initWorkflowBtn.setVisible(false);
} else {
saveAndCloseBtn.setEnabled(false);
saveAndCloseBtn.setText("APPROVED");
initWorkflowBtn.setVisible(false);
}
} else if (getEditedEntity().getProcessState() == ProcessState.REJECTED) {
saveAndCloseBtn.setEnabled(false);
saveAndCloseBtn.setText("REJECTED");
initWorkflowBtn.setVisible(false);
} else {
saveAndCloseBtn.setVisible(false);
if (userType != null && userType.equalsIgnoreCase("employee")) {
initWorkflowBtn.setText("SUBMIT");
}
if (getEditedEntity().getProcessState() == ProcessState.RETURNED_FOR_CORRECTION ||
getEditedEntity().getProcessState() == ProcessState.RECALLED_FOR_CORRECTION) {
initWorkflowBtn.setText("RE-SUBMIT");
this.setReadOnly(false);
}
}
//Show or hide workflow Task status
//----------------------------------
if (!entityStates.isNew(getEditedEntity())) {
tabSheetTabApproval.setVisible(true);
workflowTaskLinesDl.setParameters(ParamsMap.of("entityName", metadata.getClass(getEditedEntity()).getName(), "entityId", getEditedEntity().getId()));
workflowTaskLinesDl.load();
} else {
tabSheetTabApproval.setVisible(false);
}
}
if (getEditedEntity().getWorkAwayType()!=null && getEditedEntity().getWorkAwayType().equals(WorkAwayType.VISIT)) {
DataGrid.Column<?> column = workAwayOfficeLineDataGrid.getColumnByKey("visitLocation");
if (column != null) {
column.setHeader("Visit Location");
}
deliverablesField.setLabel("Visit Purpose");
// workAddressField.setLabel("Visit Address");
}else{
DataGrid.Column<?> column = workAwayOfficeLineDataGrid.getColumnByKey("visitLocation");
if (column != null) {
column.setHeader("Location");
}
}
if (this.isReadOnly()) {
addDatesBtn.setVisible(false);
Action addDatesAction = workflowTaskLinesDataGrid.getAction("addDates");
if (addDatesAction != null) {
addDatesAction.setEnabled(false);
}
}
}
@Subscribe
public void onReady(final ReadyEvent event) {
if(entityStates.isNew(getEditedEntity())){
if(waType!=null) {
if (waType.equalsIgnoreCase("wfa")) {
getEditedEntity().setWorkAwayType(WorkAwayType.WORK_FROM_ANYWHERE);
deliverablesField.setLabel("Deliverables");
visitStartTimeField.setVisible(false);
visitEndTimeField.setVisible(false);
} else {
getEditedEntity().setWorkAwayType(WorkAwayType.VISIT);
deliverablesField.setLabel("Visit Purpose");
workAddressField.setLabel("Visit Address");
// log.info("WorkAwayType.VISIT ");
}
}else{
notifications.create("waType is null")
.show();
}
}else{
if (waType.equalsIgnoreCase("wfa")) {
deliverablesField.setLabel("Deliverables");
visitStartTimeField.setVisible(false);
visitEndTimeField.setVisible(false);
} else {
deliverablesField.setLabel("Visit Purpose");
workAddressField.setLabel("Visit Address");
}
}
this.showHideFields();
}
How can I solve the problem related to null query parameter value?