0 Replies Latest reply on Feb 21, 2011 7:44 AM by gopi balagala

    exception handling causes facesmessages not displayed

    gopi balagala Newbie
      Hi,

             I have to displayed in exception case faces messages, I tried but its not displayed I am using jboss-seam-2.2.1.CR3, Richfaces 3.3.3.final with JSF1.2 and server jboss-5.1.0.GA, but its not displayed FacesMessages, Same message I have displayed in log.

              Please find the below code:

      Xhtml:
      ------------
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
           xmlns:s="http://jboss.com/products/seam/taglib"
           xmlns:ui="http://java.sun.com/jsf/facelets"
           xmlns:f="http://java.sun.com/jsf/core"
           xmlns:h="http://java.sun.com/jsf/html"
           xmlns:a="http://richfaces.org/a4j"
           xmlns:rich="http://richfaces.org/rich"
           template="../layout/dashboardTemplate.xhtml">

           <ui:define name="bodyHolder">
                <h:form id="ePortfolioUploadForm">
                <h:messages globalOnly="true" styleClass="error-panel" id="errorwaringmsg"/>
                     <h:panelGroup id="headerPanel" layout="block"
                          styleClass="rich-panel-header panel-border">
                          <h:outputText value="#{messages.myPortfolio}" />
                     </h:panelGroup>
                     <h:panelGrid columns="2" width="100%" cellspacing="6" id="taskparts"
                          columnClasses="width-15-per,width-80-per">

                          <rich:extendedDataTable id="idTask" var="tasks"
                               value="#{taskList}"
                               selectionMode="single" height="225px"
                               selection="#{portfolioTask.selection}" selectedClass="selectedrow"
                               headerClass="display-none">
                               <a:support id="selection" event="onselectionchange"
                                    actionListener="#{portfolioTask.selectionListener}"
                                    reRender="espParts,taskTitle,taskTitleFeedback,taskTitleParts">
                               </a:support>
                               <rich:column style="align:center" id="tasks">
                                    <h:outputText value="#{tasks.espTask.taskTitle}" id="textTitle"
                                         styleClass="text-bold" />
                                    <br></br>
                                    <h:outputText id="taskDesc"
                                         value="#{tasks.espTask.taskDescription}" />
                               </rich:column>
                          </rich:extendedDataTable>

                          <h:panelGrid columns="1" width="100%" id="tsktitle">
                               <h:column>
                                    <h:outputText
                                         value="#{messages.Show} #{portfolioTask.displayTaskTitle} #{messages.Instructions}"
                                         id="taskTitle" />
                                    <rich:spacer width="510" />
                                    <h:outputText
                                         value="#{portfolioTask.displayTaskTitle} #{messages.FeedBack}"
                                         id="taskTitleFeedback" />
                               </h:column>
                               <rich:dataTable id="espParts" var="task" width="100%"
                                    value="#{espParts}" cellpadding="0" cellspacing="0"
                                    headerClass="no-image"
                                    columnClasses="width-40-per,width-40-per,width-40-per">
                                    <f:facet name="header">
                                         <rich:columnGroup>
                                              <rich:column styleClass="tasks-table-header" id="tasktitle">
                                                   <h:outputText value="#{portfolioTask.displayTaskTitle} "
                                                        id="taskTitleParts" />
                                                   <h:outputText value="#{messages.parts}" id="partId" />
                                              </rich:column>
                                              <rich:column styleClass="tasks-table-header" id="uploadWork">
                                                   <h:outputText value="#{messages.uploadedWork}" id="fileUpload" />
                                              </rich:column>
                                              <rich:column styleClass="tasks-table-header" id="actions">
                                                   <h:outputText value="#{messages.actions}" id="action" />
                                              </rich:column>
                                         </rich:columnGroup>
                                    </f:facet>
                                    <rich:column id="parts">
                                         <h:outputText value="#{task.espPart.partDescription}"
                                              styleClass="datatable-cell-text" id="partDescription" />
                                    </rich:column>
                                    <rich:column id="artifacts">
                                         <h:outputText value="#{task.espUserArtifact.artifactName}"
                                              styleClass="datatable-cell-text" id="artifactName" />
                                    </rich:column>
                                    <rich:column id="file">
                                         <s:link value="#{messages.upload}" id="uploadmsg"/>
                                         <rich:toolTip id="uploadtooltip" direction="bottom-left">
                                              <h:outputText value="#{messages.UploadFileLabel}"
                                                   id="toolTipText" />
                                         </rich:toolTip>
                                    </rich:column>
                               </rich:dataTable>
                               
                               <rich:messages for="errmessage" styleClass="error-panel"/>
                               <h:outputText id="errmessage"/>
                               
                          </h:panelGrid>
                     </h:panelGrid>

                     <a:commandButton type="submit" styleClass="padding-top-4-px"
                          id="btnSubmit" image="../img/buttons/submit_portfolio.png"
                          ignoreDupResponses="true" reRender="mpSubmitPortfolio"
                          value="#{messages.btnsubmitportfolio}">
                          <a:support reRender="mpSubmitPortfolio" event="onclick"
                               id="btnSubmitted" />
                     </a:commandButton>
                </h:form>

           </ui:define>
      </ui:composition>


      -------------

      Java

      ---------------

      /*
      * Copyright (c) 2011 Pearson Education, Inc. or its affiliate(s).  All rights reserved.(Rev.975).
      * Evaluation Systems, Pearson, P.O. Box 226, Amherst, MA  01004.
      *
      */
      package com.pearson.esp.presentation.portfolio;

      import java.util.Iterator;
      import java.util.List;

      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.annotations.End;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.web.RequestParameter;
      import org.jboss.seam.faces.FacesMessages;
      import org.jboss.seam.log.Log;
      import org.richfaces.model.selection.SimpleSelection;

      import com.pearson.esp.biz.portfolio.PortfolioManager;
      import com.pearson.esp.common.ESPException;
      import com.pearson.esp.common.Logging;
      import com.pearson.esp.domain.EspUserPortfolioTask;
      import com.pearson.esp.domain.EspUserPortfolioTaskPart;

      /**
      *
      * File: PortfolioTask.java Purpose: This portfoliotask is used for getting the
      * all tasks and parts for a protfolioId. Date 07/02/2011
      *
      */
      @Name("portfolioTask")
      @Scope(ScopeType.CONVERSATION)
      @Logging
      public class PortfolioTask {

           @Logger
           Log lg;

           @In(create = true)
           private PortfolioManager portfolioManager;

           @DataModel
           private List<EspUserPortfolioTask> taskList;

           private SimpleSelection selection;
           private String displayTaskTitle;

           @SuppressWarnings("unused")
           @DataModel
           private List<EspUserPortfolioTaskPart> espParts;

           @RequestParameter("portfolioId")
           private Long portfolioId;
           
           @In(create=false)
           private FacesMessages facesMessages;
           

           /**
            * gettaskList() method fetches all tasks for a portfolioId. default first
            * task parts displayed. Contains logic to filter duplicate task for a
            * portfolioId.
            *
            * @throws
            *
            */
           @Factory("taskList")
           @Begin(join = true)
           public void gettaskList() {

                if (portfolioId == null) {
                     portfolioId = 150L;
                }

                try {
                     taskList = portfolioManager.getPortfolioTaskById(portfolioId);
                } catch (ESPException eex) {
                     FacesMessages.instance().add(eex.getMessage());
                     FacesMessages.instance().add("Invalid portfolio Id");
                } catch (Exception ie) {
                     lg.info(ie.getMessage());
                }
                EspUserPortfolioTask portfolioTask = new EspUserPortfolioTask();
                if (taskList != null && !taskList.isEmpty() && taskList.size() > 0) {
                     portfolioTask.setUserPortfolioTaskid(taskList.get(0)
                               .getUserPortfolioTaskid());
                     espParts = portfolioManager.getPartsByTask(portfolioTask);
                     this.displayTaskTitle = taskList.iterator().next().getEspTask()
                               .getTaskTitle();
                     selection = new SimpleSelection();
                     selection.addKey(new Integer(0));
                }
           }

           /**
            * selectionListener() this method is called in change of parts selection of
            * currently selected row of task list.
            *
            */

           public void selectionListener() {
                Iterator<Object> iterator = selection.getKeys();

                if(iterator.hasNext()) {
                     Object key = iterator.next();
                     EspUserPortfolioTask portfolioTask = new EspUserPortfolioTask();
                     portfolioTask.setUserPortfolioTaskid(taskList.get(
                               Integer.parseInt(key.toString())).getUserPortfolioTaskid());
                     espParts = portfolioManager.getPartsByTask(portfolioTask);
                     this.displayTaskTitle = this.taskList
                               .get(Integer.parseInt((key.toString()))).getEspTask()
                               .getTaskTitle();
                }
           }

           /**
            *
            * @return a string for displaying portfolio TaskTitle.
            */
           public String getDisplayTaskTitle() {
                return displayTaskTitle;
           }

           public void setDisplayTaskTitle(String displayTaskTitle) {
                this.displayTaskTitle = displayTaskTitle;
           }

           /**
            * @return selected Items a variable of type SimpleSelection.
            */
           public SimpleSelection getSelection() {
                return selection;
           }

           public void setSelection(SimpleSelection selection) {
                this.selection = selection;
           }

           /**
            * Conversation end page redirection here.
            *
            * @return status of Items a variable of type String.
            */
           @End
           public String submitPortfolio() {

                return "submitted";
           }

      }