@Override
  public void decode(FacesContext context, UIComponent component) {
    ExternalContext external = context.getExternalContext();
    Map requestParams = external.getRequestParameterMap();
    UIInputListOfValues inputLov = (UIInputListOfValues) component;
    String clientId = inputLov.getClientId(context);
    String id = (String) inputLov.getAttributes().get("objectName");
    String nameId = clientId;
    if (id != null) {
      clientId = id + "Id";
      nameId = id + "Name";
    }

    String submittedValue = (String) requestParams.get(clientId);
    String nameValue = (String) requestParams.get(nameId);
    if (submittedValue != null) inputLov.setSubmittedValue(submittedValue);

    if (JSFUtil.isNotEmpty(submittedValue)) {
      inputLov.setValueName(nameValue);
      inputLov.setValueId(submittedValue);
      inputLov.setValid(true);
    } else {
      inputLov.setValueName(null);
      inputLov.setValueId(null);
    }
  }
예제 #2
0
  // Decodes Behaviors if any match the behavior source/event.
  // As a convenience, returns component id, but only if it
  // was retrieved.  This allows us to avoid duplicating
  // calls to getClientId(), which can be expensive for
  // deep component trees.
  protected final String decodeBehaviors(FacesContext context, UIComponent component) {

    if (!(component instanceof ClientBehaviorHolder)) {
      return null;
    }

    ClientBehaviorHolder holder = (ClientBehaviorHolder) component;
    Map<String, List<ClientBehavior>> behaviors = holder.getClientBehaviors();
    if (behaviors.isEmpty()) {
      return null;
    }

    ExternalContext external = context.getExternalContext();
    Map<String, String> params = external.getRequestParameterMap();
    String behaviorEvent = params.get("javax.faces.behavior.event");

    if (null != behaviorEvent) {
      List<ClientBehavior> behaviorsForEvent = behaviors.get(behaviorEvent);

      if (behaviorsForEvent != null && behaviorsForEvent.size() > 0) {
        String behaviorSource = params.get("javax.faces.source");
        String clientId = component.getClientId();
        if (isBehaviorSource(context, behaviorSource, clientId)) {
          for (ClientBehavior behavior : behaviorsForEvent) {
            behavior.decode(context, component);
          }
        }

        return clientId;
      }
    }

    return null;
  }
예제 #3
0
 private String getViewParameter(String name) {
   FacesContext facesContext = FacesContext.getCurrentInstance();
   ExternalContext externalContext = facesContext.getExternalContext();
   String param = (String) externalContext.getRequestParameterMap().get(name);
   if (param != null && param.trim().length() > 0) return param;
   return null;
 }
예제 #4
0
  public static String getParam(String paramName) {
    ExternalContext ext = FacesUtils.extContext();
    Map<String, String> p = ext.getRequestParameterMap();
    if (p.containsKey(paramName)) return p.get(paramName);

    return null;
  }
예제 #5
0
  @PostConstruct
  public void controllerSetup() {
    logger.debug("Start init of EntityController");
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
    String entity = extContext.getRequestParameterMap().get("entityClassName");
    this.setEntityClassName(entity);
    ejb.setEntityClass(this.getEntityClassName());
    this.entityClass = ejb.getEntityClass();
    Properties props = this.ejb.getEntityProperties(this.getEntityClass());

    if (props != null) {
      columns = new ArrayList<ColumnModel>();
      Enumeration<?> i = props.keys();

      while (i.hasMoreElements()) {
        String key = (String) i.nextElement();
        columns.add(new ColumnModel(props.getProperty(key), key));
      }
    }

    this.getLazyDataModel().setEntityClass(entity);
    this.getLazyDataModel().init();
    logger.debug("Data filled for entity " + entity);
    this.setCurrentEntity(null);
  }
예제 #6
0
 private void decodeFocusTracking(FacesContext facesContext) {
   if (!isAutoFocusTrackingEnabled(facesContext)) return;
   ExternalContext externalContext = facesContext.getExternalContext();
   Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
   String focusedComponentId = requestParameterMap.get(FOCUS_TRACKER_FIELD_ID);
   Map<String, Object> requestMap = externalContext.getRequestMap();
   requestMap.put(FOCUSED_COMPONENT_ID_KEY, focusedComponentId);
 }
  private String getRequestToken(ExternalContext externalContext) {
    String requestToken = externalContext.getRequestParameterMap().get(DELTASPIKE_REQUEST_TOKEN);
    if (requestToken != null) {
      return requestToken;
    }

    return "";
  }
예제 #8
0
 private void decodeScrollPosTracking(FacesContext facesContext) {
   if (!isAutoScrollPosTrackingEnabled(facesContext)) return;
   ExternalContext externalContext = facesContext.getExternalContext();
   Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
   String focusedComponentId = requestParameterMap.get(SCROLL_POS_TRACKER_FIELD_ID);
   Map<String, Object> requestMap = externalContext.getRequestMap();
   requestMap.put(SCROLL_POS_KEY, focusedComponentId);
 }
 /**
  * Registers the file server in this gateway given parameters ip and port
  *
  * @return IP address and port of the file server
  */
 public String register() {
   FacesContext fc = FacesContext.getCurrentInstance();
   ExternalContext ec = fc.getExternalContext();
   Map<String, String> parameter = ec.getRequestParameterMap();
   ServerInfo server =
       new ServerInfo(parameter.get("ip"), Integer.parseInt(parameter.get("port")));
   servers.add(server);
   System.out.println("server is add: " + server);
   return server.toString();
 }
예제 #10
0
  /** Decodes the data from the form. */
  @Override
  public void decode(FacesContext context, UIComponent component) {
    String clientId = component.getClientId(context);

    ExternalContext ext = context.getExternalContext();
    Map<String, String> paramMap = ext.getRequestParameterMap();

    String value = paramMap.get(clientId);

    if (value != null) ((EditableValueHolder) component).setSubmittedValue(value);
  }
  public void treeNodeSelected(ActionEvent actionEvent) {

    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    long folderId = LongHelper.toLong(externalContext.getRequestParameterMap().get("folderId"), 0L);
    FolderTreeNode folderTreeNode =
        docLibModelBean.getFolderTreeModel().findFolderTreeNode(folderId);
    FolderUserObject folderUserObject = folderTreeNode.getFolderUserObject();
    docLibModelBean.setSelectedUserObject(folderUserObject);
    permittedToAddFolder = null;
    permittedToAddDocument = null;
  }
예제 #12
0
  public PerfilProfesor() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    Map params = externalContext.getRequestParameterMap();
    String correo = (String) params.get("username");

    try {
      profesor = Retorno.getProfesor(correo);
    } catch (DAOException ex) {
      System.out.println("error cargando el profesor " + ex);
    }
  }
예제 #13
0
  @Override
  public UIViewRoot createView(FacesContext context, String viewId) {
    UIViewRoot root = null;

    try {
      root = super.createView(context, viewId);
    } catch (RuntimeException e) {
      if (AjaxUtil.isAjaxRequest(context)) {
        // If exception was caught during our ajax request then we need to process it
        // and send ajax response with details about exception.
        CommonAjaxViewRoot.processExceptionDuringAjax(context, e);
        Log.log(context, e.getMessage(), e);
      } else {
        // We need to rethrow exception.
        throw new RuntimeException(e);
      }
    } catch (Error e) {
      if (AjaxUtil.isAjaxRequest(context)) {
        // If exception was caught during our ajax request then we need to process it
        // and send ajax response with details about exception.
        CommonAjaxViewRoot.processExceptionDuringAjax(context, e);
        Log.log(context, e.getMessage(), e);
      } else {
        // We need to rethrow exception.
        throw new Error(e);
      }
    }

    // If created instance of UIViewRoot does not implement our interface WrappedAjaxRoot
    // then we need to wrap it with our AjaxViewRoot
    UIViewRoot riRoot;
    if (null == root || root instanceof WrappedAjaxRoot) {
      riRoot = root;
    } else {
      riRoot = getAjaxViewRoot(root, context);
    }

    ExternalContext externalContext = context.getExternalContext();
    Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
    Map<String, Object> requestMap = externalContext.getRequestMap();
    if (requestParameterMap.containsKey("of_sessionExpiration")
        && requestParameterMap.containsKey(AjaxUtil.AJAX_REQUEST_MARKER)) {
      if (!requestMap.containsKey(SESSION_EXPIRATION_PROCESSING)) {
        requestMap.put(SESSION_EXPIRATION_PROCESSING, Boolean.TRUE);

        String actionURL = getActionURL(context, viewId);
        actionURL = externalContext.encodeActionURL(actionURL);
        requestMap.put(LOCATION_HEADER, actionURL);
      }
    }

    return riRoot;
  }
 public void initializeCloseLink(FacesContext context, UIInputListOfValues component)
     throws IOException {
   String type = (String) component.getAttributes().get("type");
   Boolean srts = (Boolean) component.getAttributes().get("sendRequestToServer");
   Object parentId = component.getAttributes().get("pid");
   Object pValueText = component.getAttributes().get("pValueText");
   String styleClass = (String) component.getAttributes().get("styleClass");
   Object objectNameAttr = component.getObjectName();
   Object extraInfo = component.getAttributes().get("extraInfo");
   Boolean autoNumeric = (Boolean) component.getAttributes().get("autoNumeric");
   Object data = component.getAttributes().get("data");
   Object onCloseLink = component.getAttributes().get("onCloseLink");
   extraInfo = extraInfo == null ? "" : extraInfo;
   if (type != null && "link".equalsIgnoreCase(type)) {
     ResponseWriter writer = context.getResponseWriter();
     ExternalContext external = context.getExternalContext();
     Map requestParams = external.getRequestParameterMap();
     String objectName = (String) requestParams.get("objectName");
     if (objectName == null) objectName = (String) objectNameAttr;
     if (srts != null && srts) {
       writer.startElement("a", component);
       String view = (String) component.getAttributes().get("view");
       String onclick =
           String.format(
               "Richfaces.colorboxControl.extendedRequestClose(%s, '%s', '%s', '%s');",
               parentId, pValueText, objectName, view);
       getUtils().writeAttribute(writer, "onclick", onclick);
       getUtils().writeAttribute(writer, "style", "cursor:pointer;");
       if (JSFUtil.isNotEmpty(styleClass)) getUtils().writeAttribute(writer, "class", styleClass);
       writer.write(String.valueOf(getSelectedTextConvertedValue(context, component)));
       writer.endElement("a");
     }
     if (objectName != null && objectName.trim().length() > 0) {
       writer.startElement("a", component);
       String onclick =
           String.format(
               "Richfaces.colorboxControl.extendedClose(%s, '%s', '%s', '%s');",
               parentId, pValueText, objectName, extraInfo);
       if (autoNumeric)
         onclick +=
             String.format("Richfaces.colorboxControl.applyAutoNumeric('%s');", objectNameAttr);
       onclick += "Richfaces.colorboxControl.extendedCloseBox();";
       if (data != null && onCloseLink != null)
         onclick += onCloseLink + "('" + objectName + "','" + data + "');";
       else if (onCloseLink != null) onclick += onCloseLink + "('" + objectName + "');";
       getUtils().writeAttribute(writer, "onclick", onclick);
       getUtils().writeAttribute(writer, "style", "cursor:pointer;");
       if (JSFUtil.isNotEmpty(styleClass)) getUtils().writeAttribute(writer, "class", styleClass);
       writer.write(String.valueOf(getSelectedTextConvertedValue(context, component)));
       writer.endElement("a");
     }
   }
 }
  public DatosBean() {

    System.out.println("entramos al contructor");
    valores = new Integer[4];

    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    Map params = externalContext.getRequestParameterMap();
    // Integer categorySelected = new Integer((String) params.get("username" ));

    for (int i = 1; i < valores.length; i++) {
      valores[i] = 0;
    }
  }
예제 #16
0
  private static boolean symbolParam(String key) {
    ExternalContext ext = FacesUtils.extContext();
    boolean result = false;
    Map<String, Object> requestMap = ext.getRequestMap();
    Object value = requestMap.get(key);
    if (value != null && "true".equalsIgnoreCase(value.toString())) {
      return true;
    }

    Map<String, String> params = ext.getRequestParameterMap();
    value = params.get(key);
    if (value != null && "true".equalsIgnoreCase(value.toString())) {
      requestMap.put(key, Boolean.TRUE);
      result = true;
    }
    return result;
  }
예제 #17
0
  public static boolean isPostBack() {
    ExternalContext ext = FacesUtils.extContext();
    boolean result = false;
    Map<String, Object> requestMap = ext.getRequestMap();
    Object value = requestMap.get(VIEW_STATE_KEY);
    if (!Strings.isEmpty(value)) {
      return true;
    }

    Map<String, String> params = ext.getRequestParameterMap();
    value = params.get(VIEW_STATE_KEY);
    if (!Strings.isEmpty(value)) {
      requestMap.put(VIEW_STATE_KEY, Boolean.TRUE);
      result = true;
    }
    return result;
  }
  @Override
  public void decode(FacesContext facesContext, UIComponent uiComponent) {

    ExternalContext externalContext = facesContext.getExternalContext();
    Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
    String clientId = uiComponent.getClientId();
    char separatorChar = UINamingContainer.getSeparatorChar(facesContext);
    String escapedEditorName = clientId.replace(separatorChar, '_').concat("_jsptag");

    String submittedValue = requestParameterMap.get(escapedEditorName + "_bbcodeInput");

    if (submittedValue == null) {
      submittedValue = requestParameterMap.get(escapedEditorName);
    }

    InputRichText inputRichText = (InputRichText) uiComponent;
    inputRichText.setSubmittedValue(submittedValue);
  }
예제 #19
0
 public StreamedContent getFileContent() {
   logger.trace("Entered method getFileContent.");
   ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
   String photoId = externalContext.getRequestParameterMap().get("photo_id");
   if (photoId == null || photoId.equals("")) {
     fileContent = defaultFileContent;
     logger.info("Id was null or empty. Retrieved default file content.");
   } else {
     int parsedId = Integer.parseInt(photoId);
     if (parsedId < 0 || parsedId > ImageBean.MAX_IMAGE_COUNT) {
       fileContent = defaultFileContent;
       logger.info("Invalid Id. Retrieved default file content.");
     }
     ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
     InputStream inputStream =
         contextClassLoader.getResourceAsStream("resources/images/Photo - " + parsedId + ".png");
     fileContent = new DefaultStreamedContent(inputStream, "image/png");
     logger.info("Retrieved file content for image {}.", parsedId);
   }
   logger.trace("Exited method getFileContent.");
   return fileContent;
 }
 @Override
 public void beforePhase(PhaseEvent event) {
   FacesContext facesContext = event.getFacesContext();
   ExternalContext externalContext = facesContext.getExternalContext();
   HttpSession httpSession = (HttpSession) externalContext.getSession(false);
   boolean newSession = (httpSession == null) || (httpSession.isNew());
   boolean postBack = !externalContext.getRequestParameterMap().isEmpty();
   boolean timedOut = postBack && newSession;
   if (timedOut) {
     Application application = facesContext.getApplication();
     ViewHandler viewHandler = application.getViewHandler();
     UIViewRoot view = viewHandler.createView(facesContext, "/main.xhtml");
     facesContext.setViewRoot(view);
     facesContext.renderResponse();
     try {
       viewHandler.renderView(facesContext, view);
       facesContext.responseComplete();
     } catch (Exception e) {
       throw new FacesException("Session timed out", e);
     }
   }
 }
예제 #21
0
  @Override
  public void decode(FacesContext context, UIComponent component) {

    rendererParamsNotNull(context, component);

    if (!shouldDecode(component)) {
      return;
    }

    String clientId = decodeBehaviors(context, component);

    if (clientId == null) {
      clientId = component.getClientId(context);
    }

    assert (clientId != null);
    ExternalContext externalContext = context.getExternalContext();
    Map<String, String> requestMap = externalContext.getRequestParameterMap();

    if (requestMap.containsKey(clientId)) {
      setSubmittedValue(component, requestMap.get(clientId));
    }

    HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
    try {
      Collection<Part> parts = request.getParts();
      List<Part> multiple = new ArrayList<>();
      for (Part cur : parts) {
        if (clientId.equals(cur.getName())) {
          component.setTransient(true);
          multiple.add(cur);
        }
      }
      this.setSubmittedValue(component, multiple);
    } catch (IOException | ServletException ioe) {
      throw new FacesException(ioe);
    }
  }
예제 #22
0
  public static String decodeBehaviors(FacesContext context, UIComponent component) {
    if (!(component instanceof ClientBehaviorHolder)) {
      return null;
    }

    ClientBehaviorHolder holder = (ClientBehaviorHolder) component;
    Map<String, List<ClientBehavior>> behaviors = holder.getClientBehaviors();

    if (behaviors == null || behaviors.isEmpty()) {
      return null;
    }

    ExternalContext externalContext = context.getExternalContext();
    Map<String, String> parametersMap = externalContext.getRequestParameterMap();
    String behaviorEvent = parametersMap.get(BEHAVIOR_EVENT_NAME);

    if (behaviorEvent == null) {
      return null;
    }

    List<ClientBehavior> behaviorsForEvent = behaviors.get(behaviorEvent);
    String behaviorSource = parametersMap.get(BEHAVIOR_SOURCE_ID);
    String clientId = component.getClientId(context);

    if (behaviorSource != null && behaviorSource.equals(clientId)) {
      if (behaviorsForEvent != null && !behaviorsForEvent.isEmpty()) {
        for (ClientBehavior behavior : behaviorsForEvent) {
          behavior.decode(context, component);
        }

        return behaviorEvent;
      }
    }

    return null;
  }
  /**
   * Saves the state of the FacesContext as required by section 5.1.2 of the JSR 329 spec. This
   * method is designed to be called during the ACTION_PHASE of the portlet lifecycle.
   *
   * @param facesContext The current faces context.
   */
  public void preserveScopedData(FacesContext facesContext) {

    logger.debug("preserveScopedData(facesContext)");

    // Get the ExternalContext.
    ExternalContext externalContext = facesContext.getExternalContext();

    // Save the view root.
    setAttribute(BRIDGE_REQ_SCOPE_ATTR_FACES_VIEW_ROOT, facesContext.getViewRoot());

    // If the PortletMode hasn't changed, then preserve the "javax.faces.ViewState" request
    // parameter value.
    if (!portletModeChanged) {
      PortletResponse portletResponse =
          (PortletResponse) facesContext.getExternalContext().getResponse();

      if (portletResponse instanceof ActionResponse) {
        String viewState =
            facesContext
                .getExternalContext()
                .getRequestParameterMap()
                .get(ResponseStateManager.VIEW_STATE_PARAM);

        if (viewState != null) {

          // NOTE: Although it is possible to save this as a render parameter, can't use that
          // approach because
          // portlet containers like Pluto will add the "javax.faces.ViewState" parameter to any
          // ResourceURLs
          // that are created during the RENDER_PHASE of the portlet lifecycle.
          setAttribute(ResponseStateManager.VIEW_STATE_PARAM, viewState);
        }
      }
    }

    // If specified in the WEB-INF/portlet.xml descriptor, then preserve the action parameters.
    BridgeContext bridgeContext =
        (BridgeContext) facesContext.getAttributes().get(BridgeExt.BRIDGE_CONTEXT_ATTRIBUTE);

    if (bridgeContext.isPreserveActionParams()) {
      Map<String, String> actionRequestParameterMap =
          new HashMap<String, String>(externalContext.getRequestParameterMap());
      actionRequestParameterMap.remove(ResponseStateManager.VIEW_STATE_PARAM);
      actionRequestParameterMap.remove(JAVAX_FACES_ENCODED_URL_PARAM);
      setAttribute(BRIDGE_REQ_SCOPE_ATTR_ACTION_PARAMS, actionRequestParameterMap);
    }

    // Save the list of faces messages.
    List<FacesMessageWrapper> facesMessageWrappers = new ArrayList<FacesMessageWrapper>();
    Iterator<String> clientIds = facesContext.getClientIdsWithMessages();

    while (clientIds.hasNext()) {
      String clientId = clientIds.next();
      Iterator<FacesMessage> facesMessages = facesContext.getMessages(clientId);

      while (facesMessages.hasNext()) {
        FacesMessage facesMessage = facesMessages.next();
        FacesMessageWrapper facesMessageWrapper = new FacesMessageWrapper(clientId, facesMessage);
        facesMessageWrappers.add(facesMessageWrapper);
      }
    }

    if (facesMessageWrappers.size() > 0) {
      setAttribute(BRIDGE_REQ_SCOPE_ATTR_FACES_MESSAGES, facesMessageWrappers);
    } else {
      logger.trace("Not saving any faces messages");
    }

    // Save the non-excluded request attributes. This would include, for example, managed-bean
    // instances that may
    // have been created during the ACTION_PHASE that need to survive to the RENDER_PHASE.
    if ((!redirect) && (!portletModeChanged)) {
      Map<String, Object> currentRequestAttributes = externalContext.getRequestMap();

      if (currentRequestAttributes != null) {
        List<RequestAttribute> savedRequestAttributes = new ArrayList<RequestAttribute>();
        Iterator<Map.Entry<String, Object>> itr = currentRequestAttributes.entrySet().iterator();

        if (itr != null) {

          while (itr.hasNext()) {
            Map.Entry<String, Object> mapEntry = itr.next();
            String name = mapEntry.getKey();
            Object value = mapEntry.getValue();

            if (isExcludedRequestAttribute(name, value)) {
              logger.trace("Not saving EXCLUDED attribute name=[{0}]", name);
            } else if ((value != null)
                && (value.getClass().getAnnotation(ExcludeFromManagedRequestScope.class) != null)) {
              logger.trace(
                  "Not saving EXCLUDED attribute name=[{0}] due to ExcludeFromManagedRequestScope annotation",
                  name);
            } else {
              logger.trace(
                  "Saving non-excluded request attribute name=[{0}] value=[{1}]", name, value);
              savedRequestAttributes.add(new RequestAttribute(name, value));
            }
          }

          if (savedRequestAttributes.size() > 0) {
            setAttribute(BRIDGE_REQ_SCOPE_ATTR_REQUEST_ATTRIBUTES, savedRequestAttributes);
          } else {
            logger.trace("Not saving any non-excluded request attributes");
          }
        }
      } else {
        logger.trace(
            "Not saving any non-excluded request attributes because there are no request attributes!");
      }
    } else {
      logger.trace("Not saving any non-excluded request attributes due to redirect");
    }

    // NOTE: PROPOSED-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-203 Build
    // up a list of
    // attributes found in the FacesContext attribute map and save them. It has to be copied in this
    // manner because
    // the Faces implementation likely calls the clear() method during the call to its
    // FacesContextImpl.release()
    // method.
    Map<Object, Object> currentFacesContextAttributes = facesContext.getAttributes();
    int mapSize = currentFacesContextAttributes.size();
    List<FacesContextAttribute> savedFacesContextAttributes =
        new ArrayList<FacesContextAttribute>(mapSize);
    Iterator<Map.Entry<Object, Object>> itr = currentFacesContextAttributes.entrySet().iterator();

    while (itr.hasNext()) {
      Map.Entry<Object, Object> mapEntry = itr.next();
      Object name = mapEntry.getKey();
      Object value = mapEntry.getValue();
      logger.trace("Saving FacesContext attribute name=[{0}] value=[{1}]", name, value);
      savedFacesContextAttributes.add(new FacesContextAttribute(name, value));
    }

    setAttribute(BRIDGE_REQ_SCOPE_ATTR_FACES_CONTEXT_ATTRIBUTES, savedFacesContextAttributes);
  }
예제 #24
0
@ManagedBean(name = "UserMB")
@RequestScoped
public class UserMB implements Serializable {

  public int id;

  // public String name,mobileno,emailid,password;

  private static final long serialVersionUID = 1L;
  ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
  Map<String, String> requestParams = ec.getRequestParameterMap();
  // for registration
  public String name = requestParams.get("name");
  public String emailid = requestParams.get("emailid");
  public String mobileno = requestParams.get("mobileno");
  public String password = requestParams.get("password");

  // for login
  public String loginemailid = requestParams.get("loginemailid");
  public String loginpassword = requestParams.get("loginpassword");

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getMobileno() {
    return mobileno;
  }

  public void setMobileno(String mobileno) {
    this.mobileno = mobileno;
  }

  public String getEmailid() {
    return emailid;
  }

  public void setEmailid(String emailid) {
    this.emailid = emailid;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getLoginemailid() {
    return loginemailid;
  }

  public void setLoginemailid(String loginemailid) {
    this.loginemailid = loginemailid;
  }

  public String getLoginpassword() {
    return loginpassword;
  }

  public void setLoginpassword(String loginpassword) {
    this.loginpassword = loginpassword;
  }

  public String save() {

    Session session = HibernateUtil.getSessionFactory().openSession();
    Users u = new Users();
    // u.setId(1);
    u.setEmailid(emailid);
    u.setName(name);
    u.setMobileno(mobileno);
    u.setPassword(password);
    session.beginTransaction();
    session.save(u);
    session.getTransaction().commit();
    session.close();
    return "true";
  }

  public String validate() throws SQLException {
    if (loginemailid != null && loginpassword != null) {
      Session session = HibernateUtil.getSessionFactory().openSession();
      session.beginTransaction();

      Query sql = session.createQuery("from Users");
      List<Users> list = sql.list();
      Iterator<Users> itr = list.iterator();
      while (itr.hasNext()) {
        Users q = itr.next();
        // System.out.println("emailid Name: "+q.getEmailid()+"password:"******"welcome");
          return "success";
        }
      }
      session.getTransaction().commit();
      session.close();
    }
    return "fail";
  }

  public void logout() {
    FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
    FacesContext.getCurrentInstance()
        .getApplication()
        .getNavigationHandler()
        .handleNavigation(FacesContext.getCurrentInstance(), null, "/LoginPage.xhtml");
  }
}
예제 #25
0
 @Produces
 @RequestParameterMap
 public Map<String, String> getRequestParameterMap(ExternalContext externalContext) {
   return externalContext.getRequestParameterMap();
 }
  /**
   * Saves the state of the FacesContext as required by section 5.1.2 of the JSR 329 spec. This
   * method is designed to be called during the ACTION_PHASE of the portlet lifecycle.
   *
   * @param facesContext The current faces context.
   */
  public void saveState(FacesContext facesContext) {

    logger.debug("saveState(facesContext)");

    // Get the ExternalContext and PortletResponse.
    BridgeContext bridgeContext = BridgeContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    PortletResponse portletResponse =
        (PortletResponse) facesContext.getExternalContext().getResponse();

    if ((beganInPhase == Bridge.PortletPhase.ACTION_PHASE)
        || (beganInPhase == Bridge.PortletPhase.EVENT_PHASE)
        || (beganInPhase == Bridge.PortletPhase.RESOURCE_PHASE)) {

      // Save the view root.
      setAttribute(BRIDGE_REQ_SCOPE_ATTR_FACES_VIEW_ROOT, facesContext.getViewRoot());

      // If the PortletMode hasn't changed, then preserve the "javax.faces.ViewState" request
      // parameter value.
      if (!isPortletModeChanged()) {

        if (portletResponse instanceof ActionResponse) {
          String viewState =
              facesContext
                  .getExternalContext()
                  .getRequestParameterMap()
                  .get(ResponseStateManager.VIEW_STATE_PARAM);

          if (viewState != null) {

            // NOTE: Although it is possible to save this as a render parameter, can't use that
            // approach
            // because portlet containers like Pluto will add the "javax.faces.ViewState" parameter
            // to any
            // ResourceURLs that are created during the RENDER_PHASE of the portlet lifecycle.
            setAttribute(ResponseStateManager.VIEW_STATE_PARAM, viewState);
          }
        }
      }

      // If specified in the WEB-INF/portlet.xml descriptor, then preserve the action parameters.
      if (bridgeContext.isPreserveActionParams()) {
        Map<String, String> actionRequestParameterMap =
            new HashMap<String, String>(externalContext.getRequestParameterMap());
        actionRequestParameterMap.remove(ResponseStateManager.VIEW_STATE_PARAM);
        actionRequestParameterMap.remove(JAVAX_FACES_ENCODED_URL_PARAM);
        setAttribute(BRIDGE_REQ_SCOPE_ATTR_ACTION_PARAMS, actionRequestParameterMap);
      }

      // Save the list of faces messages.
      List<FacesMessageWrapper> facesMessageWrappers = new ArrayList<FacesMessageWrapper>();
      Iterator<String> clientIds = facesContext.getClientIdsWithMessages();

      while (clientIds.hasNext()) {
        String clientId = clientIds.next();
        Iterator<FacesMessage> facesMessages = facesContext.getMessages(clientId);

        while (facesMessages.hasNext()) {
          FacesMessage facesMessage = facesMessages.next();
          FacesMessageWrapper facesMessageWrapper = new FacesMessageWrapper(clientId, facesMessage);
          facesMessageWrappers.add(facesMessageWrapper);
        }
      }

      if (facesMessageWrappers.size() > 0) {
        setAttribute(BRIDGE_REQ_SCOPE_ATTR_FACES_MESSAGES, facesMessageWrappers);
      } else {
        logger.trace("Not saving any faces messages");
      }

      // NOTE: PROPOSED-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-203
      // Build up a list
      // of attributes found in the FacesContext attribute map and save them. It has to be copied in
      // this manner
      // because the Faces implementation likely calls the clear() method during the call to its
      // FacesContextImpl.release() method.
      saveJSF2FacesContextAttributes(facesContext);
    }

    if ((beganInPhase == Bridge.PortletPhase.ACTION_PHASE)
        || (beganInPhase == Bridge.PortletPhase.EVENT_PHASE)
        || (beganInPhase == Bridge.PortletPhase.RESOURCE_PHASE)) {

      boolean saveNonExcludedAttributes = true;

      // If a redirect occurred, then indicate that the non-excluded request attributes are not to
      // be preserved.
      if (isRedirectOccurred()) {

        // TCK TestPage062: eventScopeNotRestoredRedirectTest
        logger.trace("Due to redirect, not saving any non-excluded request attributes");
        saveNonExcludedAttributes = false;
      }

      // Otherwise, if the portlet mode has changed, then indicate that the non-exluded request
      // attributes are
      // not to be preserved.
      else if (isPortletModeChanged()) {
        logger.trace("Due to PortletMode change, not saving any non-excluded request attributes");
        saveNonExcludedAttributes = false;
      }

      // If appropriate, save the non-excluded request attributes. This would include, for example,
      // managed-bean
      // instances that may have been created during the ACTION_PHASE that need to survive to the
      // RENDER_PHASE.
      Map<String, Object> currentRequestAttributes = externalContext.getRequestMap();

      if (currentRequestAttributes != null) {
        List<RequestAttribute> savedRequestAttributes = new ArrayList<RequestAttribute>();
        List<String> nonExcludedAttributeNames = new ArrayList<String>();
        Iterator<Map.Entry<String, Object>> itr = currentRequestAttributes.entrySet().iterator();

        if (itr != null) {

          while (itr.hasNext()) {
            Map.Entry<String, Object> mapEntry = itr.next();
            String attributeName = mapEntry.getKey();
            Object attributeValue = mapEntry.getValue();

            if (isExcludedRequestAttributeByConfig(attributeName, attributeValue)
                || isExcludedRequestAttributeByAnnotation(attributeValue)
                || isExcludedRequestAttributeByNamespace(attributeName)
                || isExcludedRequestAttributeByInstance(attributeName, attributeValue)
                || isExcludedRequestAttributeByPreExisting(attributeName)) {

              logger.trace("NOT saving EXCLUDED attribute name=[{0}]", attributeName);
            } else {

              if (saveNonExcludedAttributes) {
                logger.trace(
                    "SAVING non-excluded request attribute name=[{0}] value=[{1}]",
                    attributeName, attributeValue);
                savedRequestAttributes.add(new RequestAttribute(attributeName, attributeValue));
              }

              nonExcludedAttributeNames.add(attributeName);
            }
          }

          if (savedRequestAttributes.size() > 0) {
            setAttribute(BRIDGE_REQ_SCOPE_ATTR_REQUEST_ATTRIBUTES, savedRequestAttributes);
          } else {
            logger.trace("Not saving any non-excluded request attributes");
          }

          setAttribute(BRIDGE_REQ_SCOPE_NON_EXCLUDED_ATTR_NAMES, nonExcludedAttributeNames);
        }
      } else {
        logger.trace(
            "Not saving any non-excluded request attributes because there are no request attributes!");
      }
    }

    // If running in the ACTION_PHASE or EVENT_PHASE, then the Flash scope must be saved as well so
    // that it can be
    // restored.
    Bridge.PortletPhase portletRequestPhase = bridgeContext.getPortletRequestPhase();

    if ((portletRequestPhase == Bridge.PortletPhase.ACTION_PHASE)
        || (portletRequestPhase == Bridge.PortletPhase.EVENT_PHASE)) {

      // PROPOSED-FOR-JSR344-API: http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1070
      // PROPOSED-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-201
      saveFlashState(facesContext);
    }

    // If running in the ACTION_PHASE or EVENT_PHASE, then the incongruity context must be saved as
    // well so that it
    // can be restored.
    if ((portletRequestPhase == Bridge.PortletPhase.ACTION_PHASE)
        || (portletRequestPhase == Bridge.PortletPhase.EVENT_PHASE)) {

      IncongruityContext incongruityContext = bridgeContext.getIncongruityContext();
      Map<String, Object> incongruityAttributeMap = incongruityContext.getAttributes();
      int mapSize = incongruityAttributeMap.size();
      List<IncongruityAttribute> savedIncongruityAttributes =
          new ArrayList<IncongruityAttribute>(mapSize);
      Iterator<Map.Entry<String, Object>> itr = incongruityAttributeMap.entrySet().iterator();

      while (itr.hasNext()) {
        Map.Entry<String, Object> mapEntry = itr.next();
        String name = mapEntry.getKey();
        Object value = mapEntry.getValue();
        logger.trace("Saving IncongruityContext attribute name=[{0}] value=[{1}]", name, value);
        savedIncongruityAttributes.add(new IncongruityAttribute(name, value));
      }

      setAttribute(
          BRIDGE_REQ_SCOPE_ATTR_INCONGRUITY_CONTEXT_ATTRIBUTES, savedIncongruityAttributes);
    }
  }
  private boolean isNoscriptRequest(ExternalContext externalContext) {
    String noscript = externalContext.getRequestParameterMap().get(NOSCRIPT_PARAMETER);

    return (noscript != null && "true".equals(noscript));
  }
  @Override
  public String getWindowId(FacesContext facesContext) {
    ExternalContext externalContext = facesContext.getExternalContext();
    Map<String, Object> requestMap = externalContext.getRequestMap();

    // try to lookup from cache
    String windowId = (String) requestMap.get(WINDOW_ID_REQUEST_MAP_KEY);
    if (windowId != null) {
      return windowId;
    }

    ClientWindowRenderMode clientWindowRenderMode =
        clientWindowConfig.getClientWindowRenderMode(facesContext);
    if (ClientWindowRenderMode.NONE.equals(clientWindowRenderMode)) {
      // if this request should not get any window detection then we are done
      windowId = DEFAULT_WINDOW_ID;
    } else if (ClientWindowRenderMode.DELEGATED.equals(clientWindowRenderMode)) {
      windowId = ClientWindowAdapter.getWindowIdFromJsf(facesContext);
    } else if (ClientWindowRenderMode.LAZY.equals(clientWindowRenderMode)) {
      windowId = ClientWindowHelper.getInitialRedirectWindowId(facesContext);

      if (StringUtils.isEmpty(windowId)) {
        windowId = externalContext.getRequestParameterMap().get(DELTASPIKE_WINDOW_ID_URL_PARAM);
      }

      if (StringUtils.isEmpty(windowId)) {
        if (this.jsfModuleConfig.isInitialRedirectEnabled()) {
          ClientWindowHelper.handleInitialRedirect(facesContext, generateNewWindowId());
          facesContext.responseComplete();
          windowId = null;
        } else {
          windowId = generateNewWindowId();
        }
      }
    } else if (ClientWindowRenderMode.CLIENTWINDOW.equals(clientWindowRenderMode)) {
      if (facesContext.isPostback()) {
        windowId = getPostBackWindowId(facesContext);
      } else if (isNoscriptRequest(externalContext)) {
        // the client has JavaScript disabled
        clientWindowConfig.setJavaScriptEnabled(false);

        windowId = DEFAULT_WINDOW_ID;
      } else {
        windowId = getVerifiedWindowIdFromCookie(externalContext);

        boolean newWindowIdRequested = false;
        if (AUTOMATED_ENTRY_POINT_PARAMETER_KEY.equals(windowId)) {
          // this is a marker for generating a new windowId
          windowId = generateNewWindowId();
          newWindowIdRequested = true;
        }

        if (windowId == null || newWindowIdRequested) {
          // GET request without windowId - send windowhandlerfilter.html to get the windowId
          sendWindowHandlerHtml(externalContext, windowId);
          facesContext.responseComplete();
        }
      }
    }

    // we have a valid windowId - set it and continue with the request
    if (windowId != null) {
      requestMap.put(WINDOW_ID_REQUEST_MAP_KEY, windowId);
    }

    return windowId;
  }