JSF2: how achieve site-wide viewParam handling policy using a template

后端 未结 2 1840
走了就别回头了
走了就别回头了 2021-01-14 20:04

The following seems to be ignore inside XHTML facelet templates:


    
         


        
2条回答
  •  执笔经年
    2021-01-14 20:31

    Answering my own question so can share solution with code markup (I wish one could put code markup in comments instead of needing an answer, or if one can please advise how):

    /** Unlike {@link Tracker}, only tracks within a single request.
     * 
     * This is useful for the idFrom request parameter tracking in combination
     * with an idFrom @ManagedProperty.
     * 
     * This can't be done in session scope.
     *
     * @author darrenkelly
     */
    @ManagedBean
    @RequestScoped
    public class RequestTracker extends All_ {
    
        /** Creates a new instance of RequestTracker */
        public RequestTracker() {
        }
    
        @EJB private ElementQuery elementQuery;    
    
        @ManagedProperty("#{param.idFrom}")
        private Long idFrom;    
        /**
         * The id of the element page one came from to reach a tracked overview page.
         * 
         * @return 
         */
        public Long getIdFrom() {
            return idFrom;
        }    
    
        public void setIdFrom(Long idFrom) {
            if (idFrom != null) {
                this.idFrom = idFrom;
                elementFrom = elementQuery.find(idFrom);
                if (elementFrom == null) {
                    String $error = "No element with identifier idFrom(" + idFrom + ") found as referring element";
                    JsfUtil.addErrorMessage($error);
                }
            }
        }
    
        private Element elementFrom;
    
        /** The Element from whose page one came to a another page.
         */
        public Element getElementFrom() {
            return elementFrom;
        }
    
        public void setElementFrom(Element elementFrom) {
            this.elementFrom = elementFrom;
        }    
    }
    

提交回复
热议问题