Java Code Examples for javax.faces.context.FacesContext

The following are top voted examples for showing how to use javax.faces.context.FacesContext. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: myfaces-trinidad   File: SimpleInputColorRenderer.java   Source Code and License 7 votes vote down vote up
@Override
protected Integer getDefaultColumns(
  RenderingContext rc,
  UIComponent      component,
  FacesBean        bean)
{
  Integer columnsInteger = null;

  Converter converter = getConverter(component, bean);

  // Ignoring the "default" converter code is intentional;  we'll just
  // fall through to _DEFAULT_COLUMNS here to save time
  if (converter instanceof ColorConverter)
  {
    int columns = ((ColorConverter) converter).getColumns(FacesContext.getCurrentInstance());
    columnsInteger = columns;
  }
  else
  {
    columnsInteger = _DEFAULT_COLUMNS;
  }

  return columnsInteger;
}
 
Example 2
Project: myfaces-trinidad   File: ProgressStepsBean.java   Source Code and License 7 votes vote down vote up
public void onPoll(PollEvent event)
{
  if ( __model != null && (__model.getMaximum() <= __model.getValue()) )
  {
    //pu: This means the background task is complete.
    //  End the task and navigate off to a different page.
    endProcess();
    try
    {
      ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
      ec.redirect("../components/progressEnd.jspx?taskStatus=completed");
    }
    catch(IOException ioe)
    {
      _LOG.log(Level.WARNING, "Could not redirect", ioe);
    }
    catch (RuntimeException re)
    {
      _LOG.log(Level.SEVERE, "Could not redirect", re);
      throw re;
    }
  }
}
 
Example 3
Project: myfaces-trinidad   File: UIXComponentBase.java   Source Code and License 6 votes vote down vote up
@Override
public void encodeBegin(FacesContext context) throws IOException
{
  if (context == null)
    throw new NullPointerException();

  // Call UIComponent.pushComponentToEL(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
  pushComponentToEL(context, this);

  if (!isRendered())
    return;

  context.getApplication().publishEvent(context,  PreRenderComponentEvent.class, UIComponent.class, this);

  _cacheRenderer(context);
  Renderer renderer = getRenderer(context);

  // if there is a Renderer for this component
  if (renderer != null)
  {
    renderer.encodeBegin(context, this);
  }
}
 
Example 4
Project: myfaces-trinidad   File: SessionChangeManager.java   Source Code and License 6 votes vote down vote up
/**
 * Removes (if any) the previously added simple component change for the supplied component and 
 *  attribute 
 *  
 * @return The removed ComponentChange instance, or null if the ComponentChange was not removed
 */
private ComponentChange _removeSimpleComponentChange(
  FacesContext facesContext,
  UIComponent component,
  AttributeComponentChange componentChange)
{
  String sessionKey = _getSessionKey(facesContext);
  ChangesForView changesForView = _getChangesForView(facesContext, sessionKey, true);
  String logicalScopedId = 
    ComponentUtils.getLogicalScopedIdForComponent(component, facesContext.getViewRoot());

  // first remove from the simple component changes structure that we maintained for convenience
  changesForView.removeAttributeChange(logicalScopedId, componentChange);

  // next, remove (replace with null) any attribute change for this attribute from the global 
  //  changes list, handling the case where the component could have been moved after the 
  //  attribute change was added
  return _replaceAttributeChange(facesContext,
                                 component,
                                 componentChange.getAttributeName(),
                                 null,
                                 true);
}
 
Example 5
Project: oscm   File: TenantValidator.java   Source Code and License 6 votes vote down vote up
@Override
public void validate(FacesContext context, UIComponent uiComponent,
        Object input) throws ValidatorException {
    
    TenantService tenantService = serviceLocator.findService(TenantService.class);
    
    String tenantKey = input.toString();

    if (StringUtils.isBlank(tenantKey) || "0".equals(tenantKey)) {
        return;
    }

    try {
        tenantService.getTenantByKey(Long.parseLong(tenantKey));
    } catch (ObjectNotFoundException e) {

        String msg = JSFUtils
                .getText(BaseBean.ERROR_TENANT_NO_LONGER_EXISTS, null);
        FacesMessage facesMessage = new FacesMessage(
                FacesMessage.SEVERITY_ERROR, msg, null);
        throw new ValidatorException(facesMessage);
    }
}
 
Example 6
Project: myfaces-trinidad   File: ChangeBean.java   Source Code and License 6 votes vote down vote up
/**
 * Appends an image child to the panelGroup in the underlying JSP document
 */
public void appendChildToDocument(ActionEvent event)
{
  UIComponent eventSource = event.getComponent();
  UIComponent uic = eventSource.findComponent("pg1");
  
  // only allow the image to be added once
  if (_findChildById(uic,"oi3") != null)
    return;
    
  FacesContext fc = FacesContext.getCurrentInstance();

  DocumentFragment imageFragment = _createDocumentFragment(_IMAGE_MARK_UP);
  
  if (imageFragment != null)
  {
    DocumentChange change = new AddChildDocumentChange(imageFragment);
    
    ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
    
    apm.addDocumentChange(fc, uic, change);
  }
}
 
Example 7
Project: myfaces-trinidad   File: DateTimeRangeValidator.java   Source Code and License 6 votes vote down vote up
private FacesMessage _getMaximumMessage(
  FacesContext context,
  UIComponent component,
  Object value,
  Object max)
{
  Converter converter = _getConverter(context, component);

  Object cValue = _getConvertedValue(context, component, converter, value);
  Object cMax   = _getConvertedValue(context, component, converter, max);

  Object msg   = _getRawMaximumMessageDetail();
  Object label = ValidatorUtils.getComponentLabel(component);

  Object[] params = {label, cValue, cMax};

  return MessageFactory.getMessage(context,
                                   MAXIMUM_MESSAGE_ID,
                                   msg,
                                   params,
                                   component);
}
 
Example 8
Project: myfaces-trinidad   File: XhtmlRenderer.java   Source Code and License 6 votes vote down vote up
@Override
protected boolean skipDecode(FacesContext context)
{
  // =-=AEW HACK!  When executing a "dialog return" from the filter,
  // we've generally saved off the original parameters such that
  // decoding again isn't a problem.  But we can run into some problems:
  //  (1) A component that doesn't know about ReturnEvents:  it'll
  //    decode again, thereby firing the event again that launched
  //    the dialog (and you go right back to the dialog)
  //  (2) The component does know about ReturnEvents, but
  //      someone launches a dialog in response to the ReturnEvent,
  //      after setting the value of an input field.  But since
  //      we've still saved off the original parameters,
  //      now we're back in
  // The best fix would really be somehow skipping the Apply Request
  // Values phase altogether, while still queueing the ReturnEvent
  // properly.  But how the heck is that gonna happen?
  return TrinidadFilterImpl.isExecutingDialogReturn(context);
}
 
Example 9
Project: APacheSynapseSimplePOC   File: MyfacesTest.java   Source Code and License 6 votes vote down vote up
@Override
public Object call () throws Exception {
    java.lang.reflect.Method setFC = FacesContext.class.getDeclaredMethod("setCurrentInstance", FacesContext.class);
    setFC.setAccessible(true);
    ClassLoader oldTCCL = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
    FacesContext ctx = createMockFacesContext();
    try {
        setFC.invoke(null, ctx);
        return super.call();
    }
    finally {
        setFC.invoke(null, (FacesContext) null);
        Thread.currentThread().setContextClassLoader(oldTCCL);
    }
}
 
Example 10
Project: myfaces-trinidad   File: UIXTreeTemplate.java   Source Code and License 6 votes vote down vote up
@Override
public Object saveState(FacesContext context)
{
  RowKeySet rowKeys = (RowKeySet)super.getProperty(DISCLOSED_ROW_KEYS_KEY);
  if (rowKeys != null)
  {
    // make sure the set does not pin the model in memory
    rowKeys.setCollectionModel(null);
  }
  rowKeys = (RowKeySet)super.getProperty(SELECTED_ROW_KEYS_KEY);
  if (rowKeys != null)
  {
    // make sure the set does not pin the model in memory
    rowKeys.setCollectionModel(null);
  }
  return super.saveState(context);
}
 
Example 11
Project: tap17-muggl-javaee   File: GuardianConverter.java   Source Code and License 6 votes vote down vote up
@Override
public String getAsString(FacesContext context, UIComponent component, Object object) {
    if (object == null) {
        return "";
    }
    
    Guardian guardian = (Guardian) object;
    Long id = guardian.getId();
    if (id != null) {
        String stringId = String.valueOf(id.longValue());
        this.getViewMap(context).put(stringId, object);
        return stringId;
    } else {
        return "0";
    }
}
 
Example 12
Project: myfaces-trinidad   File: UIXDecorateCollectionTemplate.java   Source Code and License 6 votes vote down vote up
/**
 * Gets the client-id of this component, without any NamingContainers.
 * This id changes depending on the currency Object.
 * Because this implementation uses currency strings, the local client ID is
 * not stable for very long. Its lifetime is the same as that of a
 * currency string.
 * @see #getCurrencyString
 * @return the local clientId
 */
@Override
public final String getContainerClientId(FacesContext context)
{
  String id = getClientId(context);
  String key = getCurrencyString();
  if (key != null)
  {
    StringBuilder bld = __getSharedStringBuilder();
    bld.append(id).append(NamingContainer.SEPARATOR_CHAR).append(key);
    id = bld.toString();
  }

  return id;
}
 
Example 13
Project: Multicentro_Mascotas   File: ColumnManagerView.java   Source Code and License 6 votes vote down vote up
public void treeToTable()
/*     */   {
/*  77 */     Map params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
/*  78 */     String property = (String)params.get("property");
/*  79 */     String droppedColumnId = (String)params.get("droppedColumnId");
/*  80 */     String dropPos = (String)params.get("dropPos");
/*     */ 
/*  82 */     String[] droppedColumnTokens = droppedColumnId.split(":");
/*  83 */     int draggedColumnIndex = Integer.parseInt(droppedColumnTokens[(droppedColumnTokens.length - 1)]);
/*  84 */     int dropColumnIndex = draggedColumnIndex + Integer.parseInt(dropPos);
/*     */ 
/*  87 */     this.columns.add(dropColumnIndex, new ColumnModel(property.toUpperCase(), property));
/*     */ 
/*  90 */     TreeNode root = (TreeNode)this.availableColumns.getChildren().get(0);
/*  91 */     for (TreeNode node : root.getChildren()) {
/*  92 */       ColumnModel model = (ColumnModel)node.getData();
/*  93 */       if (model.getProperty().equals(property)) {
/*  94 */         root.getChildren().remove(node);
/*  95 */         break;
/*     */       }
/*     */     }
/*     */   }
 
Example 14
Project: myfaces-trinidad   File: FormElementRenderer.java   Source Code and License 6 votes vote down vote up
/**
 */
protected void renderShortDescAsHiddenLabel(
  FacesContext     context,
  RenderingContext rc,
  UIComponent      component,
  FacesBean        bean
  ) throws IOException
{
  if (HiddenLabelUtils.supportsHiddenLabels(rc) &&
      isHiddenLabelRequired(rc))
  {
    String clientId = getClientId(context, component);
    if (HiddenLabelUtils.wantsHiddenLabel(rc, clientId))
    {
      String hiddenLabel = getHiddenLabel(component, bean);
      if (hiddenLabel != null)
      {
        HiddenLabelUtils.outputHiddenLabel(context,
                                           rc,
                                           clientId,
                                           hiddenLabel,
                                           component);
      }
    }
  }
}
 
Example 15
Project: myfaces-trinidad   File: CoreRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * Coerces an object into an action URI, calling the view-handler.
 */
static public String toActionUri(FacesContext fc, Object o)
{
  if (o == null)
    return null;

  String uri = o.toString();

  // Treat two slashes as server-relative
  if (uri.startsWith("//"))
  {
    return uri.substring(1);
  }
  else
  {
    return fc.getApplication().getViewHandler().getActionURL(fc, uri);
  }
}
 
Example 16
Project: myfaces-trinidad   File: DesktopPanelPageHeaderRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * render a table row with the navigation2
 * @return void
 */
private void _renderNavigation2(
  FacesContext   context,
  ResponseWriter writer,
  UIComponent    navigation2,
  int            colSpan
  ) throws IOException
{
    writer.startElement("tr", null);
    writer.startElement("td", null);

    if (colSpan > 1)
      writer.writeAttribute("colspan", colSpan, null);

    writer.writeAttribute("width",
                          "100%", null);

    encodeChild( context, navigation2 );


    writer.endElement("td");
    writer.endElement("tr");
}
 
Example 17
Project: myfaces-trinidad   File: Scriptlet.java   Source Code and License 6 votes vote down vote up
/**
 * Outputs the scriptlet.
 */
protected void outputScriptletImpl(
  FacesContext        context,
  RenderingContext arc) throws IOException
{
  ResponseWriter writer = context.getResponseWriter();

  writer.startElement("script", null);
  XhtmlRenderer.renderScriptDeferAttribute(context, arc);
  // Bug #3426092:
  // Render the type="text/javascript" attribute in accessibility mode
  XhtmlRenderer.renderScriptTypeAttribute(context, arc);

  outputScriptletContent(context, arc);
  writer.endElement("script");
}
 
Example 18
Project: myfaces-trinidad   File: BodyRenderer.java   Source Code and License 6 votes vote down vote up
private void _renderNoScript(
  FacesContext     context,
  RenderingContext rc
  ) throws IOException
{
  // Some accessibility standards rather oddly claim that NOSCRIPT
  // tags are essential for compliance.  So, render NOSCRIPT, at
  // least when we're not in "inacessible" mode.
  //
  // But don't bother in design time mode - this check is
  // largely there for JDev 10.1.3 preview, which was rendering
  // the contents of any NOSCRIPT tags in the VE, but it's
  // a check that does no harm.
  if (!isInaccessibleMode(rc) && !rc.isDesignTime())
  {
    ResponseWriter writer = context.getResponseWriter();
    writer.startElement("noscript",null);
    String message = rc.getTranslatedString("NO_SCRIPT_MESSAGE");
    writer.writeText(message, null);
    writer.endElement("noscript");
  }
}
 
Example 19
Project: myfaces-trinidad   File: UIXTreeTableTemplate.java   Source Code and License 5 votes vote down vote up
/**
 * Override to update the container client id cache before validations
 */
@Override
public void processValidators(FacesContext context)
{
  _resetContainerClientIdCache();
  super.processValidators(context);
}
 
Example 20
Project: myfaces-trinidad   File: CoreResponseStateManager.java   Source Code and License 5 votes vote down vote up
private StateManager.SerializedView _getSerializedView(FacesContext context, Object state)
{

  StateManager.SerializedView view;
  if (state instanceof StateManager.SerializedView)
  {
    view = (StateManager.SerializedView) state;
  }
  else
  {
    if (state instanceof Object[])
    {
      Object[] stateArray = (Object[]) state;

      // in theory the state should be a black box, but the RI makes assumptions
      // that the state is an array of length 2
      if (stateArray.length == 2)
      {
        StateManager stateManager =
          context.getApplication().getStateManager();
        view =
            stateManager.new SerializedView(stateArray[0], stateArray[1]);
      }
      else
      {
        throw new IllegalArgumentException(_LOG.getMessage("UNEXPECTED_STATE"));
      }
    }
    else
    {
      throw new IllegalArgumentException(_LOG.getMessage("UNEXPECTED_STATE"));
    }
  }

  return view;
}
 
Example 21
Project: myfaces-trinidad   File: MethodBindingMethodExpression.java   Source Code and License 5 votes vote down vote up
public Object invoke(ELContext elContext, Object[] params)
{
  try
  {
    return _binding.invoke(FacesContext.getCurrentInstance(), params);
  }
  // Convert EvaluationExceptions into ELExceptions
  catch (EvaluationException ee)
  {
    throw new ELException(ee.getMessage(), ee.getCause());
  }
}
 
Example 22
Project: myfaces-trinidad   File: ValueExpressionValueBinding.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public Class getType(FacesContext facesContext)
{
  try
  {
    return _ve.getType(facesContext.getELContext());
  }
  // Convert EL exceptions into EvaluationExceptions
  catch (ELException ee)
  {
    throw new EvaluationException(ee.getMessage(), ee.getCause());
  }
}
 
Example 23
Project: myfaces-trinidad   File: LabelAndMessageRenderer.java   Source Code and License 5 votes vote down vote up
@Override
protected boolean shouldRenderId(
  FacesContext context,
  UIComponent  component)
{
  return false;
}
 
Example 24
Project: myfaces-trinidad   File: LongRangeValidator.java   Source Code and License 5 votes vote down vote up
private static String _getTrRangeValidator(
    FacesContext context,
    UIComponent component,
    String max,
    String min,
    Map<String, String> messages)
{
  StringBuilder outBuffer = new StringBuilder();
  outBuffer.append("new TrRangeValidator(");
  outBuffer.append(max);
  outBuffer.append(',');
  outBuffer.append(min);
  outBuffer.append(',');
  if(messages == null)
  {
    outBuffer.append("null");
  }
  else
  {
    try
    {
      JsonUtils.writeMap(outBuffer, messages, false);
    }
    catch (IOException e)
    {
      outBuffer.append("null");
    }
  }
  outBuffer.append(")");

  return outBuffer.toString();
}
 
Example 25
Project: myfaces-trinidad   File: PollRenderer.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void decode(
  FacesContext facesContext,
  UIComponent  component,
  @SuppressWarnings("unused")
  FacesBean    facesBean,
  String       clientId)
{
  Map<String, String> parameters =
    facesContext.getExternalContext().getRequestParameterMap();

  Object event = parameters.get(XhtmlConstants.EVENT_PARAM);
  if (XhtmlConstants.POLL_EVENT.equals(event))
  {
    Object source = parameters.get(XhtmlConstants.SOURCE_PARAM);
    String id = clientId == null ? component.getClientId(facesContext) : clientId;

    if (id.equals(source))
    {
      // This component always uses PPR (unless not supported at all)
      PartialPageUtils.forcePartialRendering(facesContext);

      // And forcibly re-render ourselves - because that's how
      // we get the poll re-started
      RequestContext.getCurrentInstance().addPartialTarget(component);

      UIXPoll poll = (UIXPoll) component;
      (new PollEvent(component)).queue();
      if (poll.isImmediate())
        facesContext.renderResponse();
    }
  }
}
 
Example 26
Project: myfaces-trinidad   File: StyleContextImpl.java   Source Code and License 5 votes vote down vote up
public boolean checkStylesModified()
{
  FacesContext context = FacesContext.getCurrentInstance();
  String checkTimestamp =
    context.getExternalContext().getInitParameter(Configuration.CHECK_TIMESTAMP_PARAM);

  // in production stage we don't want TRUE here;
  // a WARNING will be triggered by the ViewHandlerImpl.java
  return "true".equals(checkTimestamp);
}
 
Example 27
Project: chr-krenn-fhj-ws2017-sd17-pse   File: LoginBean.java   Source Code and License 5 votes vote down vote up
public String logout() {
    FacesContext.getCurrentInstance().getExternalContext().invalidateSession();

    //TODO return isn`t needed in case each class has the handling if no session exists
    return "/login.xhtml?faces-redirect=true";

    //TODO smarter would be the next line without return a string - at the moment the instance of LoginBean is new create so the errorMsg isn`t shown
}
 
Example 28
Project: myfaces-trinidad   File: ValueExpressionValueBinding.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public Object getValue(FacesContext facesContext)
{
  try
  {
    return _ve.getValue(facesContext.getELContext());
  }
  // Convert EL exceptions into EvaluationExceptions
  catch (ELException ee)
  {
    throw new EvaluationException(ee.getMessage(), ee.getCause());
  }    
}
 
Example 29
Project: DocIT   File: EmployeeBean.java   Source Code and License 5 votes vote down vote up
/** Creates a new instance of EmployeeBean */
public EmployeeBean() {
    HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

    String id = request.getParameter("employeeId");
    currentEmployee = Long.valueOf(id);
    
    loadEmployee(currentEmployee);
}
 
Example 30
Project: ctsms   File: SketchPadRenderer.java   Source Code and License 5 votes vote down vote up
private void encodeColorPicker(FacesContext context, SketchPad sketchPad) throws IOException {
	ResponseWriter writer = context.getResponseWriter();
	String colorPickerId = getInputId(sketchPad, context) + "_colorPicker";
	writer.startElement("td", null);
	writer.startElement("input", null);
	writer.writeAttribute("type", "text", null);
	writer.writeAttribute("id", colorPickerId, null);
	writer.writeAttribute("name", colorPickerId, null);
	writer.endElement("input");
	writer.endElement("td");
}
 
Example 31
Project: myfaces-trinidad   File: NavigationBarRenderer.java   Source Code and License 5 votes vote down vote up
protected String getIconURI(
  UIXRenderingContext context,
  boolean          isBack,
  boolean          isEnabled
)
{
  // get the image location
  String iconName;

  if (isBack)
  {
    if (isEnabled)
    {
      iconName   = AF_TABLE_NB_PREV_ICON_NAME;
    }
    else
    {
      iconName   = AF_TABLE_NB_PREV_DISABLED_ICON_NAME;
    }
  }
  else
  {
    if (isEnabled)
    {
      iconName   = AF_TABLE_NB_NEXT_ICON_NAME;
    }
    else
    {
      iconName   = AF_TABLE_NB_NEXT_DISABLED_ICON_NAME;
    }
  }
  Skin skin = context.getSkin();
  RenderingContext arc = RenderingContext.getCurrentInstance();
  FacesContext fContext = context.getFacesContext();

  String iconURI = (String)(skin.getIcon(
                                        iconName).getImageURI(fContext, arc));

  return iconURI;
}
 
Example 32
Project: myfaces-trinidad   File: PageFlowScopeMap.java   Source Code and License 5 votes vote down vote up
static private TokenCache _getRootTokenCache(FacesContext context,
                                             int lifetime)
{
  return TokenCache.getTokenCacheFromSession(context.getExternalContext(),
                                             _PAGE_FLOW_SCOPE_CACHE,
                                             true,
                                             lifetime);
}
 
Example 33
Project: myfaces-trinidad   File: PartialPageUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Mark that PPR is in fact active during rendering.
 */
@SuppressWarnings("unchecked")
public static void markPPRActive(FacesContext context)
{
  Map<String, Object> requestScope =
    context.getExternalContext().getRequestMap();
  
  requestScope.put(_PPR_ACTIVE_FLAG_NAME, Boolean.TRUE);
}
 
Example 34
Project: myfaces-trinidad   File: DoubleRangeValidator.java   Source Code and License 5 votes vote down vote up
private static String _getTrRangeValidator(
    FacesContext context,
    UIComponent component,
    String max,
    String min,
    Map<String, String> messages)
{
  StringBuilder outBuffer = new StringBuilder();
  outBuffer.append("new TrRangeValidator(");
  outBuffer.append(max);
  outBuffer.append(',');
  outBuffer.append(min);
  outBuffer.append(',');
  if(messages == null)
  {
    outBuffer.append("null");
  }
  else
  {
    try
    {
      JsonUtils.writeMap(outBuffer, messages, false);
    }
    catch (IOException e)
    {
      outBuffer.append("null");
    }
  }
  outBuffer.append(')');

  return outBuffer.toString();
}
 
Example 35
Project: myfaces-trinidad   File: SimpleSelectBooleanRadioRenderer.java   Source Code and License 5 votes vote down vote up
/**
 * Returns true if the component should render the ID as a name.
 * By default, don't if the component is readonly.
 */
@Override
protected boolean shouldRenderName(
  FacesContext context,
  UIComponent  component)
{
  return false;
}
 
Example 36
Project: myfaces-trinidad   File: FacesRenderingContext.java   Source Code and License 5 votes vote down vote up
/**
 * Gets the current RenderingContext.
 * @todo Rename to getCurrentInstance()
 * @todo Why are passing a UIComponent?  In some places,
 *   we're passing null for the component!
 */
static public UIXRenderingContext getRenderingContext(
  FacesContext fContext,
  UIComponent  component) throws IOException
{
  return getRenderingContext(fContext, component, true);
}
 
Example 37
Project: myfaces-trinidad   File: UIXComponentBase.java   Source Code and License 5 votes vote down vote up
@Override
public void restoreState(FacesContext context, Object state)
{
  if (state == null)
  {
    return;
  }

  Object[] stateArr = (Object[]) state;
  Object saved = stateArr[0];

  _delegate = (ComponentSystemEventListener) ((saved == null) ? UIComponent .getCurrentComponent(context)
                                            : StateUtils.restoreStateHolder(context, saved));
  _componentClass = (Class<?>)stateArr[1];
}
 
Example 38
Project: myfaces-trinidad   File: ColumnGroupRenderer.java   Source Code and License 5 votes vote down vote up
/**
 * @todo Will need to support TREE_NODE_STAGE
 */
@Override
protected void encodeAll(
  FacesContext     context,
  RenderingContext rc,
  UIComponent      component,
  FacesBean        bean
  ) throws IOException
{
  TableRenderingContext tContext =
    TableRenderingContext.getCurrentInstance();

  RenderStage rs = tContext.getRenderStage();
  int stage = rs.getStage();
  switch (stage)
  {
  case RenderStage.INITIAL_STAGE:
    _computeMode(context, tContext, component);
    break;
  case RenderStage.COLUMN_HEADER_STAGE:
    _renderHeaderMode(context, rc, tContext, component);
    break;
  // For these stages, simply render the children; we
  // need no special processing at the column group level
  case RenderStage.DATA_STAGE:
  case RenderStage.START_ROW_STAGE:
  case RenderStage.COLUMN_FOOTER_STAGE:
    _renderChildren(context, component, null /*parentNode*/);
    break;
  case RenderStage.END_STAGE:
    // Do nothing.  =-=AEW This is only legit because we happen
    // to know that ColumnRenderer does nothing here too.
    break;
  default:
    throw new AssertionError("Bad renderStage:"+stage);
  }
}
 
Example 39
Project: myfaces-trinidad   File: AliasedScriptlet.java   Source Code and License 5 votes vote down vote up
@Override
protected void outputScriptletImpl(
  FacesContext        context,
  RenderingContext arc) throws IOException
{
  if (_dependencies != null)
  {
    for (int i = 0; i < _dependencies.length; i++)
      outputDependency(context, arc, _dependencies[i]);
  }

  outputDependency(context, arc, _actualLibrary);
}
 
Example 40
Project: myfaces-trinidad   File: DesktopTableRenderer.java   Source Code and License 5 votes vote down vote up
private void _renderEmptyTable(FacesContext context, RenderingContext rc, TableRenderingContext tContext)
  throws IOException
{
  int specialCols = tContext.hasSelection()? 1: 0;
  if (tContext.getDetail() != null)
    specialCols++;
  renderEmptyTableRow(context, rc, tContext, specialCols);
}
 
Example 41
Project: chr-krenn-fhj-ws2017-sd17-pse   File: CommunityOverviewBean.java   Source Code and License 5 votes vote down vote up
public void gotoCom() {
    LOG.info("In Method gotoCom");
    if (selectedCommunity != null) {
        LOG.info("Selected Community: " + selectedCommunity.getId() + " " + selectedCommunity.getDescription());

        FacesContext context = FacesContext.getCurrentInstance();
        context.getExternalContext().getSessionMap().put("communityId", selectedCommunity.getId());

        try {
            context.getExternalContext().redirect("/pse/communityprofile.xhtml");
        } catch (IOException e) {
            LOG.error("Can't redirect to /pse/communityprofile.xhtml");
        }
    }
}
 
Example 42
Project: ProjetoFinalInitium   File: ProvaBean.java   Source Code and License 5 votes vote down vote up
public void adicionarMensagem(String mensagem, Severity tipoMensagem) {
	FacesContext fc = FacesContext.getCurrentInstance();
	FacesMessage fm = new FacesMessage(mensagem);
	fm.setSeverity(tipoMensagem);
	fc.addMessage(null, fm);

}
 
Example 43
Project: myfaces-trinidad   File: ScriptRenderer.java   Source Code and License 5 votes vote down vote up
protected String getSource(
  FacesContext context,
  UIComponent  component,
  FacesBean    bean)
{
  return toResourceUri(context, bean.getProperty(_sourceKey));
}
 
Example 44
Project: oscm-app   File: JSFUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Verifies that the view locale is equal to the user's locale
 * 
 */
public static void verifyViewLocale() {
    FacesContext fc = FacesContext.getCurrentInstance();

    HttpServletRequest request = (HttpServletRequest) fc
            .getExternalContext().getRequest();
    HttpSession session = request.getSession();
    String localeString = null;
    if (session != null) {
        localeString = (String) session
                .getAttribute(SessionConstants.SESSION_USER_LOCALE);
    }

    // if the view locale differs from the users locale change the view
    // locale
    Locale locale = fc.getViewRoot().getLocale();
    if (localeString != null && !locale.toString().equals(localeString)) {
        Iterator<Locale> it = fc.getApplication().getSupportedLocales();
        while (it.hasNext()) {
            locale = it.next();
            if (locale.toString().equals(localeString)) {
                fc.getViewRoot().setLocale(locale);
                return;
            }
        }
        // we use the default locale if the requested locale was not
        // found
        if (!fc.getViewRoot().getLocale()
                .equals(fc.getApplication().getDefaultLocale())) {
            fc.getViewRoot().setLocale(
                    fc.getApplication().getDefaultLocale());
        }
    }
}
 
Example 45
Project: myfaces-trinidad   File: SelectManyShuttleRenderer.java   Source Code and License 5 votes vote down vote up
private void _addTranslations(
  FacesContext     context,
  RenderingContext rc
  ) throws IOException
{
  // Add needed translations
  if (!rc.getProperties().containsKey(_TRANSLATED_VARS_EXIST_PROPERTY_KEY))
  {
    ResponseWriter rw = context.getResponseWriter();
    rc.getProperties().put(_TRANSLATED_VARS_EXIST_PROPERTY_KEY,
                           Boolean.TRUE);
    rw.startElement("script", null);
    renderScriptDeferAttribute(context, rc);
    // Bug #3426092:
    // render the type="text/javascript" attribute in accessibility mode
    renderScriptTypeAttribute(context, rc);

    String noItems = rc.getTranslatedString(_SHUTTLE_NO_ITEMS_FEEDBACK_KEY);
    String noItemsSelected =
      rc.getTranslatedString(_SHUTTLE_NO_ITEM_SELECTED_FEEDBACK_KEY);

    rw.writeText(_TRANSLATED_JS_FEEDBACK_NO_ITEMS, null);
    if (noItems != null)
      rw.writeText(XhtmlUtils.escapeJS(noItems, true), null);

    rw.writeText("';", null);
    rw.writeText(_TRANSLATED_JS_FEEDBACK_NO_ITEMS_SELECTED, null);
    if (noItemsSelected != null )
    {
      rw.writeText(XhtmlUtils.escapeJS(noItemsSelected, true), null);
    }
    rw.writeText("';", null);
    rw.endElement("script");
  }
}
 
Example 46
Project: myfaces-trinidad   File: LabelAndMessageRenderer.java   Source Code and License 5 votes vote down vote up
/**
 * Renders footer contents if isFooterPresent() is true.
 * @param context   the FacesContext
 * @param rc        the RenderingContext
 * @param component the component to render
 * @param bean      the FacesBean of the component to render
 * @throws IOException if there are problems rendering the contents
 */
protected void renderFieldFooterContents(
  FacesContext     context,
  RenderingContext rc,
  UIComponent      component,
  FacesBean        bean
  ) throws IOException
{
  // render nothing by default
}
 
Example 47
Project: myfaces-trinidad   File: GoLinkRenderer.java   Source Code and License 5 votes vote down vote up
protected String getOnblur(
  UIComponent component,
  FacesBean   bean)
{
  if (_onblurKey == null)
    return null;

  return XhtmlUtils.getClientEventHandler(FacesContext.getCurrentInstance(), component,
           "blur", null, toString(bean.getProperty(_onblurKey)), null);
}
 
Example 48
Project: myfaces-trinidad   File: EditableValueRenderer.java   Source Code and License 5 votes vote down vote up
/**
 * All editable components need IDs.
 */
@Override
protected boolean shouldRenderId(
  FacesContext context,
  UIComponent  component)
{
  return true;
}
 
Example 49
Project: aws-photosharing-example   File: AlbumController.java   Source Code and License 5 votes vote down vote up
public void loadAlbum() {
	setAlbum(getFacade().findAlbum(getAlbum().getId()));
	getFacade().done();
	if (getAlbum() == null) {
		try {
			FacesContext.getCurrentInstance().getExternalContext().responseSendError(HttpServletResponse.SC_NOT_FOUND, null);
			FacesContext.getCurrentInstance().responseComplete();
		} catch (IOException e) {
			//e.printStackTrace();
		}
	}
}
 
Example 50
Project: myfaces-trinidad   File: SelectRangeChoiceBarRenderer.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void decode(
  FacesContext facesContext,
  UIComponent  component,
  @SuppressWarnings("unused")
  FacesBean    facesBean,
  String       clientId)
{
  Map<String, String> parameters =
    facesContext.getExternalContext().getRequestParameterMap();

  Object event = parameters.get(XhtmlConstants.EVENT_PARAM);

  // get the goto event parameter values and queue a RangeChangeEvent.
  if (XhtmlConstants.GOTO_EVENT.equals(event))
  {
    Object source = parameters.get(XhtmlConstants.SOURCE_PARAM);
    String id = clientId == null ? component.getClientId(facesContext) : clientId;
    if (id.equals(source))
    {
      UIXSelectRange choiceBar = (UIXSelectRange)component;
      Object valueParam = parameters.get(XhtmlConstants.VALUE_PARAM);
      RangeChangeEvent rce = _createRangeChangeEvent(choiceBar, valueParam);
      rce.queue();

      if (choiceBar.isImmediate())
        facesContext.renderResponse();

      RequestContext.getCurrentInstance().addPartialTarget(component);
    }
  }
}
 
Example 51
Project: myfaces-trinidad   File: StampState.java   Source Code and License 5 votes vote down vote up
/**
 * save the stamp state of just the children of the given component
 * in the given table.
 */
@SuppressWarnings("unchecked")
public static Object saveChildStampState(
  FacesContext context,
  UIComponent   stamp,
  UIXCollection table)
{
  int childCount = stamp.getChildCount();
  // If we have any children, iterate through the map,
  // saving state
  if (childCount == 0)
    return null;

  Map<String, Object> childStateMap = null;
  List<UIComponent> children = stamp.getChildren();
  for(int i=0; i < childCount; i++)
  {
    UIComponent child = children.get(i);
    Object childState = table.saveStampState(context, child);

    // Until we have one non-null entry, don't allocate the map.
    // So: allocate the map if we encounter our first
    // non-null childState

    if (childState == null)
      continue;

    if (childStateMap == null)
    {
      childStateMap = new HashMap<String, Object>(childCount);
    }

    // Store a value into the array
    childStateMap.put(child.getId(), childState);
  }

  return childStateMap;
}
 
Example 52
Project: myfaces-trinidad   File: PanelBoxRenderer.java   Source Code and License 5 votes vote down vote up
@Override
protected void renderAllAttributes(
  FacesContext     context,
  RenderingContext rc,
  UIComponent      component,
  FacesBean        bean
  ) throws IOException
{
  super.renderAllAttributes(context, rc, component, bean);
  OutputUtils.renderLayoutTableAttributes(context, rc, "0", null);
}
 
Example 53
Project: NICON   File: AcidentePGBean.java   Source Code and License 5 votes vote down vote up
public void verificarDados()
{
   String pattern="dd-MM-yyyy";
   String dataNasc;
   FacesContext context = FacesContext.getCurrentInstance();
   String estadoCampo = context.getExternalContext().getRequestParameterMap().get("campos");
   getAcidentePG().setNumeroApolice(context.getExternalContext().getRequestParameterMap().get("apolice"));
   getAcidentePG().setNumeroRegistro(context.getExternalContext().getRequestParameterMap().get("numeroRegistro"));
   getAcidentePG().setMoeda(context.getExternalContext().getRequestParameterMap().get("moeda"));
   getAcidentePG().setDefeitosFisicosCampo(context.getExternalContext().getRequestParameterMap().get("defeitosCampo"));
   getAcidentePG().setAcidenteUltimos(context.getExternalContext().getRequestParameterMap().get("acidente3AnosCampo"));
   getAcidentePG().setNome(context.getExternalContext().getRequestParameterMap().get("nome"));
   getAcidentePG().setProfissao(context.getExternalContext().getRequestParameterMap().get("profissão"));
   getAcidentePG().setCategoria(context.getExternalContext().getRequestParameterMap().get("categoria"));
   dataNasc = context.getExternalContext().getRequestParameterMap().get("dataNasc");
   getAcidentePG().setDataNascimento(OperacaoData.stringFormatToDate(dataNasc, pattern));
   getAcidentePG().setValorMorte(context.getExternalContext().getRequestParameterMap().get("valorMorte"));
   getAcidentePG().setTaxaMorte(context.getExternalContext().getRequestParameterMap().get("taxaMorte"));
   getAcidentePG().setIncapacidadeTotalTemporaria(context.getExternalContext().getRequestParameterMap().get("incapacidadeTemp"));
   getAcidentePG().setTaxaIncapacidadeTemporaria(context.getExternalContext().getRequestParameterMap().get("taxaIncapacidadeTemp"));
   getAcidentePG().setIncapacidadeTotal(context.getExternalContext().getRequestParameterMap().get("incapacidadePerm"));
   getAcidentePG().setTaxaIncapacidadePermanente(context.getExternalContext().getRequestParameterMap().get("taxaIncapPermanente"));
   getAcidentePG().setDespesaMedica(context.getExternalContext().getRequestParameterMap().get("despesaMedica"));
   getAcidentePG().setTaxaDespesaMedica(context.getExternalContext().getRequestParameterMap().get("taxaDespesaMedica"));
   getAcidentePG().setCustoRepatriamento(context.getExternalContext().getRequestParameterMap().get("custoRep"));
   getAcidentePG().setTaxaCustoRepatriamento(context.getExternalContext().getRequestParameterMap().get("taxaCustoRep"));
   
    System.out.println(acidentePG.toString());
   if(!estadoCampo.equals("vazio"))
        if(existNumeroRegistro() == true)
            AdicionarTabela();
}
 
Example 54
Project: oscm   File: BaseBean.java   Source Code and License 5 votes vote down vote up
/**
 * Return the current user language or browser language if user is not
 * logged in.
 */
protected String getUserLanguage() {
    FacesContext fc = getFacesContext();
    if (fc == null) {
        return "en";
    }
    VOUserDetails voUserDetails = getUserFromSessionWithoutException(fc);
    if (voUserDetails == null) {
        return fc.getViewRoot().getLocale().getLanguage();
    }
    return voUserDetails.getLocale();
}
 
Example 55
Project: myfaces-trinidad   File: CoreRenderer.java   Source Code and License 5 votes vote down vote up
protected void renderEncodedActionURI(
 FacesContext context,
 String       name,
 Object       value) throws IOException
{
  if (value != null)
  {
    value = context.getExternalContext().encodeActionURL(value.toString());
    context.getResponseWriter().writeURIAttribute(name, value, null);
  }
}
 
Example 56
Project: admin-template   File: CustomExceptionHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void handle() throws FacesException {
    FacesContext context = FacesContext.getCurrentInstance();
    findErrorMessages(context);
    handleException(context);
    wrapped.handle();
}
 
Example 57
Project: myfaces-trinidad   File: LongConverter.java   Source Code and License 5 votes vote down vote up
/**
 * @param context
 * @return
 */
public String getClientConversion(
  FacesContext context,
  UIComponent component)
{
  return _getTrLongConverter(context, component, _LONG_MAX, _LONG_MIN);
}
 
Example 58
Project: myfaces-trinidad   File: StateManagerImpl.java   Source Code and License 5 votes vote down vote up
/**
 * Tests whether to send a small string token, or the entire
 * serialized component state to the client-side.
 * @return true, if the small string token is to be sent to the client-side.
 * @see #_calculateTokenStateSaving
 */
private boolean _saveAsToken(FacesContext context, boolean checkRequestToken)
{
  // the setPerViewStateSaving() method stores the PER_PAGE_STATE_SAVING value on the
  // FacesContext attribute map, during rendering
  Map<Object, Object> attrMap = FacesContext.getCurrentInstance().getAttributes();
  StateSaving stateSaving = (StateSaving) attrMap.get(_PER_PAGE_STATE_SAVING);

  // if the <document> 'stateSaving' attribute said "client" we need to return FALSE
  // in order to do "full" client-side-state saving.
  Boolean forceStateSavingPerView = null;

  if (StateSaving.CLIENT.equals(stateSaving))
  {
   forceStateSavingPerView = Boolean.FALSE;
  }
  // for "server" we return TRUE here, as we want client-side
  // state-saving to be turned OFF, regardless of the configuration
  // settings.
  else if (StateSaving.SERVER.equals(stateSaving))
  {
    forceStateSavingPerView = Boolean.TRUE;
  }

  // for the stateSaving "defaul" we just let go and do what it
  // normally would do...
  if (forceStateSavingPerView != null)
  {
    return forceStateSavingPerView.booleanValue();
  }

  return _calculateTokenStateSaving(context.getExternalContext(), checkRequestToken);
}
 
Example 59
Project: myfaces-trinidad   File: FormElementRenderer.java   Source Code and License 5 votes vote down vote up
protected void renderFormEventHandlers(
  FacesContext context,
  UIComponent  component,
  FacesBean    bean
  ) throws IOException
{
  ResponseWriter rw = context.getResponseWriter();
  rw.writeAttribute("onblur", getOnblur(component, bean),  "onblur");
  rw.writeAttribute("onfocus", getOnfocus(component, bean),  "onfocus");
  rw.writeAttribute("onchange", getOnchange(component, bean),  "onchange");
}
 
Example 60
Project: myfaces-trinidad   File: TokenCacheDebugUtils.java   Source Code and License 5 votes vote down vote up
/**
 * In order to provide human readable information there is a map which 
 * has token to viewId information.
 * 
 * Add the token passed in and associate it in the map with the current view id. 
 * 
 * This method should only be called when debugTokenCache() is true
 */
public static void addTokenToViewIdMap(String token)
{
  if (!_DEBUG_TOKEN_CACHE)
    throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
  
  FacesContext context = FacesContext.getCurrentInstance();
  Map<String,String> tokenToViewIdMap = _getTokenToViewIdMap(context);      
  UIViewRoot root = context.getViewRoot();
  String viewId = root.getViewId();    
  tokenToViewIdMap.put(token, viewId);

  StringBuffer logBuffer = _getLogBuffer(context);
  logBuffer.append("\nADDING ").append(_getTokenToViewIdString(tokenToViewIdMap, token));
}