Search in sources :

Example 66 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class UINavigator method broadcast.

/**
 * @see javax.faces.component.UIInput#broadcast(javax.faces.event.FacesEvent)
 */
public void broadcast(FacesEvent event) throws AbortProcessingException {
    if (event instanceof NavigatorEvent) {
        FacesContext context = FacesContext.getCurrentInstance();
        NavigatorEvent navEvent = (NavigatorEvent) event;
        // node or panel selected?
        switch(navEvent.getMode()) {
            case PANEL_SELECTED:
                {
                    String panelSelected = navEvent.getItem();
                    // a panel was selected, setup the context to make the panel
                    // the focus
                    NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
                    if (nb != null) {
                        try {
                            if (logger.isDebugEnabled())
                                logger.debug("Selecting panel: " + panelSelected);
                            nb.processToolbarLocation(panelSelected, true);
                        } catch (InvalidNodeRefException refErr) {
                            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NOHOME), Application.getCurrentUser(context).getHomeSpaceId()), refErr);
                        } catch (Exception err) {
                            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
                        }
                    }
                    break;
                }
            case NODE_SELECTED:
                {
                    // a node was clicked in the tree
                    boolean nodeExists = true;
                    NodeRef nodeClicked = new NodeRef(navEvent.getItem());
                    // make sure the node exists still before navigating to it
                    UserTransaction tx = null;
                    try {
                        tx = Repository.getUserTransaction(context, true);
                        tx.begin();
                        NodeService nodeSvc = Repository.getServiceRegistry(context).getNodeService();
                        nodeExists = nodeSvc.exists(nodeClicked);
                        tx.commit();
                    } catch (Throwable err) {
                        try {
                            if (tx != null) {
                                tx.rollback();
                            }
                        } catch (Exception tex) {
                        }
                    }
                    if (nodeExists) {
                        // setup the context to make the node the current node
                        BrowseBean bb = (BrowseBean) FacesHelper.getManagedBean(context, BrowseBean.BEAN_NAME);
                        if (bb != null) {
                            if (logger.isDebugEnabled())
                                logger.debug("Selected node: " + nodeClicked);
                            bb.clickSpace(nodeClicked);
                        }
                    } else {
                        String msg = Application.getMessage(context, "navigator_node_deleted");
                        Utils.addErrorMessage(msg);
                    }
                    break;
                }
        }
    } else {
        super.broadcast(event);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NavigationBean(org.alfresco.web.bean.NavigationBean) BrowseBean(org.alfresco.web.bean.BrowseBean) NodeService(org.alfresco.service.cmr.repository.NodeService) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException)

Example 67 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class UISimpleSearch method broadcast.

/**
 * @see javax.faces.component.UICommand#broadcast(javax.faces.event.FacesEvent)
 */
public void broadcast(FacesEvent event) throws AbortProcessingException {
    FacesContext fc = getFacesContext();
    if (event instanceof SearchEvent) {
        // update the component parameters from the search event details
        SearchEvent searchEvent = (SearchEvent) event;
        // construct the Search Context object
        SearchContext context = new SearchContext();
        context.setText(searchEvent.SearchText);
        context.setMode(searchEvent.SearchMode);
        context.setForceAndTerms(Application.getClientConfig(fc).getForceAndTerms());
        context.setSimpleSearchAdditionalAttributes(Application.getClientConfig(fc).getSimpleSearchAdditionalAttributes());
        this.search = context;
        super.broadcast(event);
    } else if (event instanceof AdvancedSearchEvent) {
        // special case to navigate to the advanced search screen
        AdvancedSearchEvent searchEvent = (AdvancedSearchEvent) event;
        fc.getApplication().getNavigationHandler().handleNavigation(fc, null, searchEvent.Outcome);
    // NOTE: we don't call super() here so that our nav outcome is the one that occurs!
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) SearchContext(org.alfresco.web.bean.search.SearchContext)

Example 68 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class UICategoryBrowser method broadcast.

/*
    * (non-Javadoc)
    * 
    * @see org.alfresco.extension.web.ui.repo.component.UINavigator#broadcast(javax.faces.event.FacesEvent)
    */
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
    if (event instanceof CategoryBrowserEvent) {
        FacesContext context = FacesContext.getCurrentInstance();
        CategoryBrowserEvent categoryBrowseEvent = (CategoryBrowserEvent) event;
        NodeRef nodeClicked = new NodeRef(categoryBrowseEvent.getItem());
        boolean subcategories = categoryBrowseEvent.isIncludeSubcategories();
        if (logger.isDebugEnabled())
            logger.debug("Selected category: " + nodeClicked + " subcategories? " + subcategories);
        CategoryBrowserBean categoryBrowserBean = (CategoryBrowserBean) FacesHelper.getManagedBean(context, CategoryBrowserBean.BEAN_NAME);
        categoryBrowserBean.setCurrentCategory(nodeClicked);
        categoryBrowserBean.setIncludeSubcategories(subcategories);
        SearchContext categorySearch = categoryBrowserBean.generateCategorySearchContext();
        NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
        nb.setSearchContext(categorySearch);
        context.getApplication().getNavigationHandler().handleNavigation(context, null, "category-browse");
    } else {
        super.broadcast(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NavigationBean(org.alfresco.web.bean.NavigationBean) SearchContext(org.alfresco.web.bean.search.SearchContext) CategoryBrowserBean(org.alfresco.web.bean.CategoryBrowserBean)

Example 69 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class XMLDateConverter method getLocale.

/**
 * @see javax.faces.convert.DateTimeConverter#getLocale()
 */
@Override
public Locale getLocale() {
    // get the locale set in the client
    FacesContext context = FacesContext.getCurrentInstance();
    Locale locale = context.getViewRoot().getLocale();
    if (locale == null) {
        // else use server locale as the default
        locale = Locale.getDefault();
    }
    return locale;
}
Also used : Locale(java.util.Locale) FacesContext(javax.faces.context.FacesContext)

Example 70 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class UploadInputTag method setProperties.

@SuppressWarnings("unchecked")
protected void setProperties(UIComponent component) {
    super.setProperties(component);
    FacesContext context = getFacesContext();
    if (null != framework) {
        if (isValueReference(framework)) {
            ValueBinding vb = context.getApplication().createValueBinding(framework);
            component.setValueBinding("maxlength", vb);
        } else {
            component.getAttributes().put("framework", framework);
        }
    }
    component.getAttributes().put("immediate", true);
    component.getAttributes().put("style", "display:none;");
}
Also used : FacesContext(javax.faces.context.FacesContext) ValueBinding(javax.faces.el.ValueBinding)

Aggregations

FacesContext (javax.faces.context.FacesContext)361 NodeRef (org.alfresco.service.cmr.repository.NodeRef)61 Node (org.alfresco.web.bean.repository.Node)44 UserTransaction (javax.transaction.UserTransaction)43 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)27 ExternalContext (javax.faces.context.ExternalContext)26 SelectItem (javax.faces.model.SelectItem)26 QName (org.alfresco.service.namespace.QName)25 FacesMessage (javax.faces.application.FacesMessage)24 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Map (java.util.Map)21 ResourceBundle (java.util.ResourceBundle)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)19 MapNode (org.alfresco.web.bean.repository.MapNode)18 UIViewRoot (javax.faces.component.UIViewRoot)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 Serializable (java.io.Serializable)15