javax.faces.context.FacesContext Java Examples
The following examples show how to use
javax.faces.context.FacesContext.
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: ItemAuthorBean.java From sakai with Educational Community License v2.0 | 6 votes |
public String doit() { if ("searchQuestionBank".equals(outcome)) { try { ExternalContext context = FacesContext.getCurrentInstance() .getExternalContext(); context .redirect("sakai.questionbank.client.helper/authorIndex"); } catch (Exception e) { log.error("fail to redirect to question bank: " + e.getMessage()); } } // navigation for ItemModifyListener return outcome; }
Example #2
Source File: AgentResults.java From sakai with Educational Community License v2.0 | 6 votes |
public String addAttachmentsRedirect() { // 1. redirect to add attachment try { List filePickerList = new ArrayList(); if (itemGradingAttachmentList != null) { AttachmentUtil attachmentUtil = new AttachmentUtil(); filePickerList = attachmentUtil.prepareReferenceList(itemGradingAttachmentList); } ToolSession currentToolSession = SessionManager.getCurrentToolSession(); currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList); currentToolSession.setAttribute("itemGradingId", itemGradingId); ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); context.redirect("sakai.filepicker.helper/tool"); } catch (Exception e) { log.error("fail to redirect to attachment page: " + e.getMessage()); } return "sakai.filepicker.helper"; }
Example #3
Source File: MobileRequestCustomizerFactory.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
private boolean isMobilePage(FacesContext context) { ExternalContext o = context.getExternalContext(); HttpServletRequest r = (javax.servlet.http.HttpServletRequest) o.getRequest(); String path = r.getServletPath(); ApplicationEx app = ApplicationEx.getInstance(context); String prefix = app.getApplicationProperty(MobileConstants.XSP_THEME_MOBILE_PAGEPREFIX, null); if (prefix == null) { return false; } else if (prefix.equals("*")) { // $NON-NLS-1$ return true; } else { return path.startsWith("/" + prefix); // $NON-NLS-1$ } }
Example #4
Source File: InputTextRenderer.java From BootsFaces-OSP with Apache License 2.0 | 6 votes |
/** * Add script to enable the input mask. If the mask attribute starts with {@code {}} the value is expected to be a * JSON object (and can for example be used to set a regular expression: {@code {regex:'[0-9\u0600-\u06FF]*'}}). * * See https://github.com/RobinHerbots/Inputmask. * * @param context * @param inputText * @param fieldId * @param rw * * @throws IOException */ protected void encodeMask(FacesContext context, InputText inputText, String fieldId, ResponseWriter rw) throws IOException { if (inputText.getMask() != null && !inputText.getMask().isEmpty()) { rw.startElement("script", inputText); rw.writeText("Inputmask(", null); if (inputText.getMask().trim().startsWith("{")) { rw.writeText(inputText.getMask().trim(), null); } else { rw.writeText(String.format("\"%s\"", inputText.getMask().replace("\"", "\\\"")), null); } rw.writeText(").mask(document.getElementById(\"", null); rw.writeText(fieldId, null); rw.writeText("\"));", null); rw.endElement("script"); } }
Example #5
Source File: JsfMessageResolver.java From deltaspike with Apache License 2.0 | 6 votes |
@Override protected List<String> getMessageSources(MessageContext messageContext) { List<String> result = new ArrayList<String>(super.getMessageSources(messageContext) /*unmodifiable-list*/); FacesContext facesContext = FacesContext.getCurrentInstance(); if (facesContext == null || facesContext.getCurrentPhaseId() == null) { return result; } String bundleName = facesContext.getApplication().getMessageBundle(); if (bundleName != null) { result.add(bundleName); } result.add(FacesMessage.FACES_MESSAGES); //default messages from jsf return result; }
Example #6
Source File: SketchPadRenderer.java From ctsms with GNU Lesser General Public License v2.1 | 6 votes |
private void encodeTooltip(FacesContext context, String targetId, String tooltipText) throws IOException { if (Settings.getBoolean(SettingCodes.ENABLE_TOOLTIPS, Bundle.SETTINGS, DefaultSettings.ENABLE_TOOLTIPS)) { String tooltipId = targetId + "_tooltip"; ResponseWriter writer = context.getResponseWriter(); writer.startElement("div", null); writer.writeAttribute("id", tooltipId, null); writer.writeAttribute("class", Tooltip.CONTAINER_CLASS, null); writer.writeText(tooltipText, null); writer.endElement("div"); startScript(writer, tooltipId + "_script"); writer.write("$(function() {"); writer.write("PrimeFaces.cw('Tooltip','" + "widget_" + tooltipId + "',{"); writer.write("id:'" + tooltipId + "'"); writer.write(",target:'" + targetId + "'"); writer.write(",showEffect:'fade'"); writer.write(",hideEffect:'fade'"); writer.write("});});"); endScript(writer); } }
Example #7
Source File: TestScriptsBean.java From sailfish-core with Apache License 2.0 | 6 votes |
public void goEditMatrix() { long id = Long.parseLong(BeanUtil.getRequestParam("id")); logger.info("goEditMatrix invoked {} id[{}]", BeanUtil.getUser(), id); MatrixAdapter matrixAdapter = getMatrixAdapterById(id); if (matrixAdapter == null) { BeanUtil.showMessage(FacesMessage.SEVERITY_ERROR, "Matrix not found", ""); return; } try { onChange(matrixAdapter); setMatrixToEdit(matrixAdapter); FacesContext.getCurrentInstance().getExternalContext().redirect(EXCEL_EDITOR); } catch (Exception e) { logger.error(e.getMessage(), e); BeanUtil.showMessage(FacesMessage.SEVERITY_ERROR, "Error", e.getMessage()); } }
Example #8
Source File: AbstractDataView.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
@Override public Object saveState(FacesContext context) { Object[] values = new Object[12]; values[0] = super.saveState(context); values[1] = showItemsFlat; values[2] = StateHolderUtil.saveObjectState(context, summaryColumn); values[3] = collapsibleDetail; values[4] = detailsOnClient; values[5] = disableHideRow; values[6] = pageName; values[7] = openDocAsReadonly; values[8] = style; values[9] = styleClass; values[10] = rowStyle; values[11] = rowStyleClass; return values; }
Example #9
Source File: OneUIv302ForumViewRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
@Override protected void writeHeaderPagerArea(FacesContext context, ResponseWriter w, AbstractDataView c, ViewDefinition viewDef, UIComponent pagerTop, UIComponent pagerTopLeft, UIComponent pagerTopRight) throws IOException { String tag = (String)getProperty(PROP_HEADER_PAGER_AREA_TAG); if(StringUtil.isNotEmpty(tag)) { startElement(w, tag, PROP_HEADERSTYLE, PROP_HEADERCLASS, PROP_HEADERDOJOTYPE); w.writeAttribute("role","navigation", null); // $NON-NLS-1$ $NON-NLS-2$ w.writeAttribute("aria-label", "Paging", null); // $NON-NLS-1$ $NLS-OneUIv302ForumViewRenderer.Paging-2$ } writeHeaderLeft(context, w, c, viewDef, pagerTopLeft); writeHeaderMiddle(context, w, c, viewDef, pagerTop); writeHeaderRight(context, w, c, viewDef, pagerTopRight); if(StringUtil.isNotEmpty(tag)) { w.endElement(tag); } newLine(w); }
Example #10
Source File: TestProject.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
public static FacesContext createFacesContext(AbstractXspTest test, HttpServletRequest request) throws Exception { FacesController controller = (FacesController) test.getTestLocalVars().get("controller"); if( null == controller ){ bootstrap(test); controller = (FacesController) test.getTestLocalVars().get("controller"); } LocalServletContext servletContext = (LocalServletContext) test.getTestLocalVars().get("servletContext"); HttpServletResponse response = new LocalHttpServletResponse(servletContext, null); FacesContextFactory factory1 = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); FacesContext context = factory1.getFacesContext(servletContext, request, response, controller.getLifecycle()); String sessionId = request.getSession().getId(); SessionUtil.setSessionId(context, sessionId); test.getTestLocalVars().put("facesContext", context); return context; }
Example #11
Source File: TagUtil.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Set a MethodBinding on a component - used by tags setProperties() method. */ public static void setMethodBinding(UIComponent component, String name, String value, Class[] paramTypes) { if (value == null) { return; } if (UIComponentTag.isValueReference(value)) { FacesContext context = FacesContext.getCurrentInstance(); Application app = context.getApplication(); MethodBinding mb = app.createMethodBinding(value, paramTypes); component.getAttributes().put(name, mb); } }
Example #12
Source File: TocTreeTag.java From sakai with Educational Community License v2.0 | 6 votes |
/** * @see javax.faces.webapp.UIComponentTag#setProperties(javax.faces.component.UIComponent) */ protected void setProperties(UIComponent component) { super.setProperties(component); FacesContext context = getFacesContext(); if (value != null) { ValueBinding vb = context.getApplication().createValueBinding(value); component.setValueBinding("value", vb); } if (var != null) { ((UIData) component).setVar(var); } }
Example #13
Source File: CustomExceptionHandler.java From admin-template with MIT License | 6 votes |
/** * @param context * @throws Throwable */ private void handleException(FacesContext context) { Iterator<ExceptionQueuedEvent> unhandledExceptionQueuedEvents = getUnhandledExceptionQueuedEvents().iterator(); if (unhandledExceptionQueuedEvents.hasNext()) { Throwable exception = unhandledExceptionQueuedEvents.next().getContext().getException(); unhandledExceptionQueuedEvents.remove(); Throwable rootCause = Exceptions.unwrap(exception); if (rootCause instanceof BusinessException) { handleBusinessException(context, (BusinessException) rootCause); return; } //send user to error page when unexpected exceptions are raised goToErrorPage(context, rootCause); } }
Example #14
Source File: DateTimeConverter.java From BootsFaces-OSP with Apache License 2.0 | 6 votes |
private String getAsStringValue(FacesContext facesContext, UIComponent uiComponent, Object value) { if (facesContext == null) { throw new NullPointerException("facesContext"); } if (uiComponent == null) { throw new NullPointerException("uiComponent"); } if (value == null) { return ""; } if (value instanceof String) { return (String) value; } DateTimeFormatter format = getDateFormat(uiComponent); try { return format.print((ReadableInstant) value); } catch (Exception e) { throw new ConverterException("Cannot convert value '" + value + "'"); } }
Example #15
Source File: SakaiNavigationHandler.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Handle the navigation * * @param context * The Faces context. * @param fromAction * The action string that triggered the action. * @param outcome * The logical outcome string, which is the new tool mode, or if null, the mode does not change. */ public void handleNavigation(FacesContext context, String fromAction, String outcome) { m_chain.handleNavigation(context, fromAction, outcome); // if we have a redirect scheduled, we need to preserve the messages // if we are coming from the Sakai RequestFilter, and a redirect was requested, the request object // will have this attribute set. HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest(); if (req.getAttribute("sakai.redirect") != null) { // save messages from the context for restoration on the next rendering MessageSaver.saveMessages(context); } }
Example #16
Source File: ViewScopeTest.java From joinfaces with Apache License 2.0 | 5 votes |
@Test public void testRegisterDestructionCallback() { UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); doCallRealMethod().when(viewRoot).subscribeToViewEvent(any(), any()); doCallRealMethod().when(viewRoot).unsubscribeFromViewEvent(any(), any()); when(viewRoot.getViewListenersForEventClass(any())).thenCallRealMethod(); this.viewScope.registerDestructionCallback(KEY, () -> { }); this.viewScope.remove(KEY); }
Example #17
Source File: BootsFacesTagDecorator.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
public BootsFacesTagDecorator() { String isActive = BsfUtils.getInitParam("net.bootsfaces.defaults.decorator", FacesContext.getCurrentInstance()); if ("false".equalsIgnoreCase(isActive)) { activeByDefault=false; } else { activeByDefault=true; } }
Example #18
Source File: UIDojoFormWidgetBase.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
public String getOnKeyUp() { if (null != this.onKeyUp) { return this.onKeyUp; } ValueBinding _vb = getValueBinding("onKeyUp"); //$NON-NLS-1$ if (_vb != null) { return (java.lang.String) _vb.getValue(FacesContext.getCurrentInstance()); } else { return null; } }
Example #19
Source File: UIApplication.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
@Override public void restoreState(FacesContext _context, Object _state) { Object _values[] = (Object[]) _state; super.restoreState(_context, _values[0]); this.selectedPageName = (String)_values[1]; this.onOrientationChange = (String) _values[2]; this.onResize = (String) _values[3]; }
Example #20
Source File: WorkbookService.java From Html5_Spreadsheet_Editor_by_Aspose.Cells_for_Java with MIT License | 5 votes |
@PostConstruct /*private*/ void init() { String requestedSourceUrl = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("url"); if (requestedSourceUrl != null) { try { this.sourceUrl = new URL(requestedSourceUrl).toString(); this.loadFromUrl(); } catch (MalformedURLException x) { LOGGER.throwing(null, null, x); msg.sendMessageDialog("The specified URL is invalid", requestedSourceUrl); } } }
Example #21
Source File: PostemTool.java From sakai with Educational Community License v2.0 | 5 votes |
public String processCreateNew() { try { if (!this.checkAccess()) { throw new PermissionException(SessionManager.getCurrentSessionUserId(), "syllabus_access_athz", ""); } } catch (PermissionException e) { // logger.info(this + ".getEntries() in PostemTool " + e); FacesContext.getCurrentInstance().addMessage( null, MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR, "error_permission", (new Object[] { e.toString() }), FacesContext .getCurrentInstance())); return "permission_error"; } this.userId = SessionManager.getCurrentSessionUserId(); this.siteId = ToolManager.getCurrentPlacement().getContext(); this.currentGradebook = gradebookManager.createEmptyGradebook(this.userId, this.siteId); this.oldGradebook = gradebookManager.createEmptyGradebook(this.userId, this.siteId); this.csv = null; this.newTemplate = null; this.delimiter = COMMA_DELIM_STR; return "create_gradebook"; }
Example #22
Source File: EvaluationManagementBackingBean.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
private void initializeDegreeFilter() { Map map = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); UIComponent filterComponent = findComponent(FacesContext.getCurrentInstance().getViewRoot(), "degreeFilter"); if (filterComponent != null) { String clientId = filterComponent.getClientId(FacesContext.getCurrentInstance()); degreeFilter = (String) map.get(clientId); } else { degreeFilter = FILTER_ALL; } }
Example #23
Source File: RedirectPhoneRule.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
@Override public String getRedirectURL(FacesContext context) { HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); if(isPhone(request)) { return computeRedirectURL(context); } else { return null; } }
Example #24
Source File: ScrollSpy.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException { if (isAutoUpdate()) { if (FacesContext.getCurrentInstance().isPostback()) { FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add(getClientId()); } super.processEvent(event); } }
Example #25
Source File: MobileFormTableRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
protected void calculateFormLabelWidth(FacesContext context, UIComponent component) { StringBuilder script = new StringBuilder(); script.append("XSP.addOnLoad(function(){XSP.resizeForm("); //$NON-NLS-1$ JavaScriptUtil.addString(script, component.getClientId(context)); script.append(")});"); //$NON-NLS-1$ ExtLibUtil.addScript(context, script.toString()); }
Example #26
Source File: PagerRenderer.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Save the new paging state back to the given component (adjusting firstItem and lastItem first if necessary) */ private static void adjustState(FacesContext context, UIComponent component, int firstItem, int lastItem, int pageSize, int totalItems, int newFirstItem, int newLastItem, int newPageSize) { // recalculate last item newLastItem = Math.min(newFirstItem + newPageSize, totalItems); if (newPageSize <= 0) { // if displaying all items newFirstItem = 0; newLastItem = totalItems; } // we don't count lastItem changing as a full state change (value of this component doesn't change) if (newLastItem != lastItem) RendererUtil.setAttribute(context, component, "lastItem", new Integer(newLastItem)); // send the newly changed values where they need to go if (newPageSize != pageSize) RendererUtil.setAttribute(context, component, "pageSize", new Integer(newPageSize)); if (newFirstItem != firstItem) RendererUtil.setAttribute(context, component, "firstItem", new Integer(newFirstItem)); // Set value, which causes registered valueChangeListener to be called EditableValueHolder evh = (EditableValueHolder) component; String newValue = formatValue(newFirstItem, newPageSize); Object oldValue = (String)evh.getValue(); if (!newValue.equals(oldValue)) { if (oldValue != null) { evh.setSubmittedValue(newValue); evh.setValid(true); } else { // Need to initialize value string based on initial parameters. if (log.isDebugEnabled()) log.debug("initializing value to " + newValue); evh.setValue(newValue); } } }
Example #27
Source File: DialogRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
public void dialogEncodeChildren(FacesContext context, UIComponent component) throws IOException { // The UIDialog.PopupContent can add dynamically add some children to the dialog (EventHandler), // which means that the collection size can change. We cannot then use the FacesUtil.renderChildren // method as it assumes that the number of children is constant. List<?> children = component.getChildren(); for (int i=0; i<children.size(); i++) { UIComponent child = (UIComponent)children.get(i); FacesUtil.renderComponent(context, child); } }
Example #28
Source File: OneUIv302WidgetContainerRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
protected void writeSubHeader(FacesContext context, ResponseWriter w, UIWidgetContainer c) throws IOException { UIComponent header = c.getFacet(UIWidgetContainer.FACET_HEADER); if(header!=null) { w.startElement("div", c); // $NON-NLS-1$ String clsSection = (String)getProperty(PROP_SECTION_SUBHEADER_CSS); if(StringUtil.isNotEmpty(clsSection)) { w.writeAttribute("class", clsSection, null); // $NON-NLS-1$ } // Manage the section state boolean closed = c.isClosed(); if(closed){ w.writeAttribute("style", _DISPLAY_NONE, null); // $NON-NLS-1$ } else { w.writeAttribute("style", _DISPLAY_BLOCK, null); // $NON-NLS-1$ } String tag = (String)getProperty(PROP_TAGHEADER); w.startElement(tag, c); String clsSubheader = (String)getProperty(PROP_CSSSUBHEADER); if(StringUtil.isNotEmpty(clsSubheader)) { w.writeAttribute("class", clsSubheader, null); // $NON-NLS-1$ } FacesUtil.renderChildren(context, header); //close header tag w.endElement(tag); //close sub-header section w.endElement("div"); // $NON-NLS-1$ } }
Example #29
Source File: CarouselRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
@Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ResponseWriter w = context.getResponseWriter(); UICarousel c = (UICarousel) component; if (!c.isRendered()) { return; } writeCarousel(context, w, c); }
Example #30
Source File: UserManager.java From jsf-primefaces with MIT License | 5 votes |
public String logout() { String identifier = userId; // invalidate the session LOGGER.debug("invalidating session for '{}'", identifier); FacesContext.getCurrentInstance().getExternalContext() .invalidateSession(); LOGGER.info("logout successful for '{}'", identifier); return LOGOUT_PAGE_REDIRECT; }