Java Code Examples for javax.faces.context.FacesContext#addMessage()
The following examples show how to use
javax.faces.context.FacesContext#addMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageSaver.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Restore saved messages. * * @param context * The current faces context. */ public static void restoreMessages(FacesContext context) { if (context == null) return; // look in the session HttpSession s = (HttpSession) context.getExternalContext().getSession(false); if (s == null) return; // get messages List msgs = (List) s.getAttribute(ATTR_MSGS); if (msgs != null) { // process each one - add it to this context's message set for (Iterator iMessages = msgs.iterator(); iMessages.hasNext();) { FacesMessage msg = (FacesMessage) iMessages.next(); // Note: attributed to no specific tree element context.addMessage(null, msg); } s.removeAttribute(ATTR_MSGS); } }
Example 2
Source File: Registration.java From pragmatic-microservices-lab with MIT License | 6 votes |
public String register() { String trackingId = null; try { if (!originUnlocode.equals(destinationUnlocode)) { trackingId = bookingServiceFacade.bookNewCargo( originUnlocode, destinationUnlocode, new SimpleDateFormat(FORMAT).parse(arrivalDeadline)); } else { // TODO See if this can be injected. FacesContext context = FacesContext.getCurrentInstance(); FacesMessage message = new FacesMessage( "Origin and destination cannot be the same."); message.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(null, message); return null; } } catch (ParseException e) { throw new RuntimeException("Error parsing date", e); } return "show.xhtml?faces-redirect=true&trackingId=" + trackingId; }
Example 3
Source File: CalculatedQuestionExtractListener.java From sakai with Educational Community License v2.0 | 6 votes |
/** * This listener will read in the instructions, parse any variables and * formula names it finds, and then check to see if there are any errors * in the configuration for the question. * * <p>Errors include <ul><li>no variables or formulas named in the instructions</li> * <li>variables and formulas sharing a name</li> * <li>variables with invalid ranges of values</li> * <li>formulas that are syntactically wrong</li></ul> * Any errors are written to the context messager * <p>The validate formula is also called directly from the ItemAddListner, before * saving a calculated question, to ensure any last minute changes are caught. */ public void processAction(ActionEvent arg0) throws AbortProcessingException { ItemAuthorBean itemauthorbean = (ItemAuthorBean) ContextUtil.lookupBean("itemauthor"); ItemBean item = itemauthorbean.getCurrentItem(); List<String> errors = this.validate(item,true); if (errors.size() > 0) { item.setOutcome("calculatedQuestion"); item.setPoolOutcome("calculatedQuestion"); FacesContext context=FacesContext.getCurrentInstance(); for (String error : errors) { context.addMessage(null, new FacesMessage(error)); } context.renderResponse(); } }
Example 4
Source File: UpdateAssessmentQuestionsOrder.java From sakai with Educational Community License v2.0 | 6 votes |
public void processAction(ActionEvent ae) throws AbortProcessingException { FacesContext context = FacesContext.getCurrentInstance(); AuthorBean author = (AuthorBean) ContextUtil.lookupBean("author"); assessmentBean = (AssessmentBean) ContextUtil.lookupBean("assessmentBean"); boolean isEditPendingAssessmentFlow = author.getIsEditPendingAssessmentFlow(); if (isEditPendingAssessmentFlow) { assessmentService = new AssessmentService(); itemService = new ItemService(); } else { assessmentService = new PublishedAssessmentService(); itemService = new PublishedItemService(); } if(reorderItems()){ String err = ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.AuthorMessages", "edit_order_warning"); context.addMessage(null, new FacesMessage(err)); } assessmentBean.setAssessment(assessmentService.getAssessment(Long.valueOf(assessmentBean.getAssessmentId()))); }
Example 5
Source File: SuTool.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Specialized Getters */ public boolean getAllowed() { Session sakaiSession = M_session.getCurrentSession(); FacesContext fc = FacesContext.getCurrentInstance(); //allow the user to access the tool if they are either a DA user or Super Admin if (!M_security.isSuperUser() && sakaiSession.getAttribute("delegatedaccess.accessmapflag") != null) { message = msgs.getString("unauthorized") + " " + sakaiSession.getUserId(); log.error("[SuTool] Fatal Error: " + message); fc.addMessage("allowed", new FacesMessage(FacesMessage.SEVERITY_FATAL, message, message)); allowed = false; } else { allowed = true; } return allowed; }
Example 6
Source File: Track.java From pragmatic-microservices-lab with MIT License | 6 votes |
public void onTrackById() { markersModel = new DefaultMapModel(); Cargo cargo = cargoRepository.find(new TrackingId(trackingId)); if (cargo != null) { List<HandlingEvent> handlingEvents = handlingEventRepository .lookupHandlingHistoryOfCargo(new TrackingId(trackingId)) .getDistinctEventsByCompletionTime(); this.cargo = new CargoTrackingViewAdapter(cargo, handlingEvents); this.destinationCoordinates = net.java.cargotracker.application.util.LocationUtil.getPortCoordinates(cargo.getRouteSpecification().getDestination().getUnLocode().getIdString()); } else { // TODO See if this can be injected. FacesContext context = FacesContext.getCurrentInstance(); FacesMessage message = new FacesMessage( "Cargo with tracking ID: " + trackingId + " not found."); message.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(null, message); this.cargo = null; } }
Example 7
Source File: AssessmentSettingsBean.java From sakai with Educational Community License v2.0 | 6 votes |
public String checkDate(){ FacesContext context=FacesContext.getCurrentInstance(); ResourceLoader rb = new ResourceLoader("org.sakaiproject.tool.assessment.bundle.AuthorMessages"); String err; if(AssessmentSettingsBean.error) { err=rb.getString("deliveryDate_error"); context.addMessage(null,new FacesMessage(err)); log.error("START DATE ADD MESSAGE"); return "deliveryDate_error"; } else { return "saveSettings"; } }
Example 8
Source File: AssessmentSettingsBean.java From sakai with Educational Community License v2.0 | 6 votes |
public void addExtendedTime() { ExtendedTime entry = this.extendedTime; if (StringUtils.isBlank(entry.getUser()) && StringUtils.isBlank(entry.getGroup())) { FacesContext context = FacesContext.getCurrentInstance(); String errorString = ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.AssessmentSettingsMessages", "extended_time_user_and_group_set"); context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, errorString, null)); } else { AssessmentAccessControlIfc accessControl = new AssessmentAccessControl(); accessControl.setStartDate(this.startDate); accessControl.setDueDate(this.dueDate); accessControl.setLateHandling(Integer.valueOf(this.lateHandling)); accessControl.setRetractDate(this.retractDate); this.extendedTime.syncDates(accessControl); this.extendedTimes.add(this.extendedTime); resetExtendedTime(); } }
Example 9
Source File: Tooltip.java From BootsFaces-OSP with Apache License 2.0 | 6 votes |
private static void verifyAndWriteTooltip(FacesContext context, ResponseWriter rw, String tooltip, String position, String container) throws IOException { if (null == position) position="bottom"; boolean ok = "top".equals(position); ok |= "bottom".equals(position); ok |= "right".equals(position); ok |= "left".equals(position); ok |= "auto".equals(position); ok |= "auto top".equals(position); ok |= "auto bottom".equals(position); ok |= "auto right".equals(position); ok |= "auto left".equals(position); if (!ok) { position = "bottom"; context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Wrong JSF markup", "Tooltip position must either be 'auto', 'top', 'bottom', 'left' or 'right'.")); } rw.writeAttribute("data-toggle", "tooltip", null); rw.writeAttribute("data-placement", position, "data-placement"); rw.writeAttribute("data-container", container, "data-container"); rw.writeAttribute("title", tooltip, null); }
Example 10
Source File: FacesMessages.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
private static void reportMessage(String refItem, FacesMessage facesMsg) { FacesContext context = FacesContext.getCurrentInstance(); refItem = resolveSearchExpressions(refItem); if (null != refItem) { String[] refItems = refItem.split(" "); for (String r : refItems) { context.addMessage(r, facesMsg); } } else { context.addMessage(null, facesMsg); } }
Example 11
Source File: SavePublishedSettingsListener.java From sakai with Educational Community License v2.0 | 5 votes |
public boolean checkScore(PublishedAssessmentSettingsBean assessmentSettings, PublishedAssessmentFacade assessment, FacesContext context) { // check if the score is > 0, Gradebook doesn't allow assessments with total // point = 0. boolean gbError = false; if (assessmentSettings.getToDefaultGradebook()) { if (assessment.getTotalScore() <= 0) { String gb_err = (String) ContextUtil.getLocalizedString( "org.sakaiproject.tool.assessment.bundle.AuthorMessages","gradebook_exception_min_points"); context.addMessage(null, new FacesMessage(gb_err)); gbError = true; } } return gbError; }
Example 12
Source File: DeliveryBean.java From sakai with Educational Community License v2.0 | 5 votes |
public boolean mediaIsValid() { boolean returnValue =true; // check if file is too big FacesContext context = FacesContext.getCurrentInstance(); ExternalContext external = context.getExternalContext(); Long fileSize = (Long)((ServletContext)external.getContext()).getAttribute("TEMP_FILEUPLOAD_SIZE"); Long maxSize = Long.valueOf(ServerConfigurationService.getInt("samigo.sizeMax", 40960)); ((ServletContext)external.getContext()).removeAttribute("TEMP_FILEUPLOAD_SIZE"); if (fileSize!=null){ float fileSize_float = fileSize.floatValue()/1024; int tmp = Math.round(fileSize_float * 10.0f); fileSize_float = (float)tmp / 10.0f; float maxSize_float = maxSize.floatValue()/1024; int tmp0 = Math.round(maxSize_float * 10.0f); maxSize_float = (float)tmp0 / 10.0f; String err1=(String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.DeliveryMessages", "file_upload_error"); String err2=(String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.DeliveryMessages", "file_uploaded"); String err3=(String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.DeliveryMessages", "max_size_allowed"); String err4=(String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.DeliveryMessages", "upload_again"); String err = err2 + fileSize_float + err3 + maxSize_float + err4; context.addMessage("file_upload_error",new FacesMessage(err1)); context.addMessage("file_upload_error",new FacesMessage(err)); returnValue = false; } return returnValue; }
Example 13
Source File: EditTemplateListener.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Standard processAction. * @param ae * @throws AbortProcessingException */ public void processAction(ActionEvent ae) throws AbortProcessingException { TemplateBean templateBean = (TemplateBean)ContextUtil.lookupBean("template"); templateBean.setOutcome("newTemplate"); String tempName=templateBean.getNewName(); AssessmentService assessmentService = new AssessmentService(); //IndexBean templateIndex = (IndexBean) ContextUtil.lookupBean( "templateIndex"); //ArrayList templates = new ArrayList(); // id=0 => new template boolean isUnique=assessmentService.assessmentTitleIsUnique("0",tempName,true); FacesContext context = FacesContext.getCurrentInstance(); if(tempName!=null && (tempName.trim()).equals("")){ String err1=ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.TemplateMessages","templateName_empty"); context.addMessage(null,new FacesMessage(err1)); templateBean.setOutcome("template"); return; } if (!isUnique){ String error=ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.TemplateMessages","duplicateName_error"); context.addMessage(null,new FacesMessage(error)); templateBean.setOutcome("template"); return; } templateBean.setTemplateName(tempName); templateBean.setIdString("0"); //new template templateBean.setTypeId(null); //new template templateBean.setValueMap(getMetaDataMap()); templateBean.setMarkForReview(Boolean.FALSE); }
Example 14
Source File: SiteListBean.java From sakai with Educational Community License v2.0 | 5 votes |
public boolean isAllowed() { allowed = authz.isUserAbleToViewUmem(M_tm.getCurrentPlacement().getContext()); if(!allowed){ FacesContext fc = FacesContext.getCurrentInstance(); message = msgs.getString("unauthorized"); fc.addMessage("allowed", new FacesMessage(FacesMessage.SEVERITY_FATAL, message, null)); allowed = false; } return allowed; }
Example 15
Source File: ItemAuthorBean.java From sakai with Educational Community License v2.0 | 5 votes |
public boolean mediaIsValid() { boolean returnValue =true; // check if file is too big FacesContext context = FacesContext.getCurrentInstance(); ExternalContext external = context.getExternalContext(); Long fileSize = (Long)((ServletContext)external.getContext()).getAttribute("TEMP_FILEUPLOAD_SIZE"); Long maxSize = Long.valueOf(ServerConfigurationService.getString("samigo.sizeMax", "40960")); ((ServletContext)external.getContext()).removeAttribute("TEMP_FILEUPLOAD_SIZE"); if (fileSize!=null){ float fileSize_float = fileSize.floatValue()/1024; int tmp = Math.round(fileSize_float * 10.0f); fileSize_float = (float)tmp / 10.0f; float maxSize_float = maxSize.floatValue()/1024; int tmp0 = Math.round(maxSize_float * 10.0f); maxSize_float = (float)tmp0 / 10.0f; String err1=(String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.DeliveryMessages", "file_upload_error"); String err2=(String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.DeliveryMessages", "file_uploaded"); String err3=(String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.DeliveryMessages", "max_size_allowed"); String err4=(String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.DeliveryMessages", "upload_again"); String err = err2 + fileSize_float + err3 + maxSize_float + err4; context.addMessage("file_upload_error",new FacesMessage(err1)); context.addMessage("file_upload_error",new FacesMessage(err)); returnValue = false; } return returnValue; }
Example 16
Source File: Messages.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
private static void addMessageId(FacesContext context, String id, FacesMessage.Severity severity, String message) { if (context != null) { UIComponent component = WebUtil.findComponentById(context.getViewRoot(), id); FacesMessage facesMessage = new FacesMessage(severity, message, null); if (component == null) { context.addMessage(null, facesMessage); } else { context.addMessage(component.getClientId(context), facesMessage); } } }
Example 17
Source File: ItemBean.java From sakai with Educational Community License v2.0 | 5 votes |
public String addChoicesAction() { // build a default list of 4 choices, a, b, c, d, String newvalue = getAdditionalChoices(); List<AnswerBean> list = getMultipleChoiceAnswers(); if (list!=null) { // add additional answer bean int currentsize = list.size(); int newlength = currentsize+ new Integer(newvalue).intValue(); if (newlength<=26){ for (int i=currentsize; i<newlength; i++){ AnswerBean answerbean = new AnswerBean(); answerbean.setSequence( Long.valueOf(i+1)); answerbean.setLabel(AnswerBean.getChoiceLabels()[i]); list.add(answerbean); } setMultipleChoiceAnswers(list); setAdditionalChoices("0"); // if mcmc, need to set corrAnswers if (TypeFacade.MULTIPLE_CORRECT.toString().equals(this.itemType) || TypeFacade.MULTIPLE_CORRECT_SINGLE_SELECTION.toString().equals(this.itemType)) { List<String> corranswersList = ContextUtil.paramArrayValueLike("mccheckboxes"); int corrsize = corranswersList.size(); int counter = 0; String[] corrchoices = new String[corrsize]; for(String currentcorrect : corranswersList){ corrchoices[counter++]= currentcorrect; } this.setCorrAnswers(corrchoices); } } else { //print error FacesContext context=FacesContext.getCurrentInstance(); context.addMessage(null,new FacesMessage(RB_AUTHOR_MESSAGES.getString("MCanswer_outofbound_error"))); } } return "multipleChoiceItem"; }
Example 18
Source File: BillingBean.java From development with Apache License 2.0 | 5 votes |
public void validateFromAndToDate(final FacesContext context, final UIComponent toValidate, final Object value) { validator.setToDate(toDate); validator.setFromDate(fromDate); try { validator.validate(context, toValidate, value); } catch (ValidatorException ex) { context.addMessage( toValidate.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, ex .getLocalizedMessage(), null)); } }
Example 19
Source File: EditAssessmentListener.java From sakai with Educational Community License v2.0 | 4 votes |
public void setPropertiesForPublishedAssessment(AuthorBean author) { FacesContext context = FacesContext.getCurrentInstance(); AssessmentBean assessmentBean = (AssessmentBean) ContextUtil.lookupBean("assessmentBean"); ItemAuthorBean itemauthorBean = (ItemAuthorBean) ContextUtil.lookupBean("itemauthor"); PublishedAssessmentService publishedAssessmentService = new PublishedAssessmentService(); PublishedAssessmentSettingsBean publishedAssessmentSettings = (PublishedAssessmentSettingsBean) ContextUtil.lookupBean("publishedSettings"); String publishedAssessmentId = assessmentBean.getAssessmentId(); PublishedAssessmentFacade publishedAssessment = publishedAssessmentService.getPublishedAssessment(publishedAssessmentId); // #1b - permission checking before proceeding - daisyf author.setOutcome("editAssessment"); AuthorizationBean authzBean = (AuthorizationBean) ContextUtil.lookupBean("authorization"); if (!authzBean.isUserAllowedToEditAssessment(publishedAssessmentId, publishedAssessment.getCreatedBy(), true)) { String err=(String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.AuthorMessages", "denied_edit_assessment_error"); context.addMessage(null,new FacesMessage(err)); author.setOutcome("author"); return; } GradingService gradingService = new GradingService(); boolean hasGradingData = gradingService.getHasGradingData(Long.valueOf(publishedAssessmentId)); if (author.getEditPubAssessmentRestricted() && hasGradingData) { author.setOutcome("editPublishedAssessmentError"); return; } assessmentBean.setHasGradingData(hasGradingData); // pass authz, move on author.setIsEditPendingAssessmentFlow(false); // Retract the published assessment for edit by updating the late submission date to now //AssessmentAccessControlIfc publishedAccessControl = publishedAssessmentService.loadPublishedAccessControl(Long.valueOf(publishedAssessmentId)); //publishedAccessControl.setRetractDate(new Date()); //publishedAssessmentService.saveOrUpdatePublishedAccessControl(publishedAccessControl); //Update the late submission date in the assessment bean //publishedAssessment.setAssessmentAccessControl(publishedAccessControl); publishedAssessment.setStatus(AssessmentBaseIfc.RETRACT_FOR_EDIT_STATUS); publishedAssessmentService.saveAssessment(publishedAssessment); publishedAssessmentSettings.setAssessment(publishedAssessment); assessmentBean.setAssessment(publishedAssessment); itemauthorBean.setTarget(ItemAuthorBean.FROM_ASSESSMENT); // save to assessment // initalize the itemtype itemauthorBean.setItemType(""); itemauthorBean.setItemTypeString(""); showPrintLink(assessmentBean); }
Example 20
Source File: AuthorSettingsListener.java From sakai with Educational Community License v2.0 | 4 votes |
public void processAction(ActionEvent ae) throws AbortProcessingException { FacesContext context = FacesContext.getCurrentInstance(); AssessmentSettingsBean assessmentSettings = (AssessmentSettingsBean) ContextUtil.lookupBean("assessmentSettings"); // #1a - load the assessment String assessmentId = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("assessmentId"); if (assessmentId == null){ assessmentId = assessmentSettings.getAssessmentId().toString(); } AssessmentService assessmentService = new AssessmentService(); AssessmentFacade assessment = assessmentService.getAssessment(assessmentId); //#1b - permission checking before proceeding - daisyf AuthorBean author = (AuthorBean) ContextUtil.lookupBean("author"); author.setOutcome("editAssessmentSettings"); AuthorizationBean authzBean = (AuthorizationBean) ContextUtil.lookupBean("authorization"); if (!authzBean.isUserAllowedToEditAssessment(assessmentId, assessment.getCreatedBy(), false)) { String err=(String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.AuthorMessages", "denied_edit_assessment_error"); context.addMessage(null,new FacesMessage(err)); author.setOutcome("author"); return; } // passed authz checks, move on author.setIsEditPendingAssessmentFlow(true); assessmentSettings.setAssessment(assessment); assessmentSettings.setAssessmentId(assessment.getAssessmentId()); assessmentSettings.setAttachmentList(((AssessmentIfc)assessment.getData()).getAssessmentAttachmentList()); assessmentSettings.setDisplayFormat(ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.GeneralMessages","output_data_picker_w_sec")); assessmentSettings.resetIsValidDate(); assessmentSettings.resetOriginalDateString(); assessmentSettings.setNoGroupSelectedError(false); assessmentSettings.setBlockDivs(""); // To convertFormattedTextToPlaintext for the fields that have been through convertPlaintextToFormattedTextNoHighUnicode FormattedText formattedText = ComponentManager.get(FormattedText.class); assessmentSettings.setTitle(formattedText.convertFormattedTextToPlaintext(assessment.getTitle())); assessmentSettings.setAuthors(formattedText.convertFormattedTextToPlaintext(assessment.getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.AUTHORS))); assessmentSettings.setFinalPageUrl(formattedText.convertFormattedTextToPlaintext(assessment.getAssessmentAccessControl().getFinalPageUrl())); assessmentSettings.setBgColor(formattedText.convertFormattedTextToPlaintext(assessment.getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.BGCOLOR))); assessmentSettings.setBgImage(formattedText.convertFormattedTextToPlaintext(assessment.getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.BGIMAGE))); assessmentSettings.setKeywords(formattedText.convertFormattedTextToPlaintext(assessment.getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.KEYWORDS))); assessmentSettings.setObjectives(formattedText.convertFormattedTextToPlaintext(assessment.getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.OBJECTIVES))); assessmentSettings.setRubrics(formattedText.convertFormattedTextToPlaintext(assessment.getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.RUBRICS))); assessmentSettings.setPassword(formattedText.convertFormattedTextToPlaintext(StringUtils.trim(assessment.getAssessmentAccessControl().getPassword()))); // else throw error // #1c - get question size int questionSize = assessmentService.getQuestionSize(assessmentId); if (questionSize > 0) assessmentSettings.setHasQuestions(true); else assessmentSettings.setHasQuestions(false); if (ae == null) { author.setFromPage("author"); } else { author.setFromPage("editAssessment"); } }