- A long time ago, I made the following changes for the XDoclet 1.2.2, in order to achieve this goal.
So, here is my changes:

1. from xdoclet-jsf-module-1.2.2.jar/xdoclet/modules/jsf/resources , take the faces_config_xml.xdt , and replace the current
   <XDtFacesNavigation:forAllViews>
              ..........
   </XDtFacesNavigation:forAllViews>

with the following one:

   <XDtFacesNavigation:forAllViews>
   <navigation-rule>
      <XDtFacesNavigation:ifNeedFromViewId>
          <!-- by cwele, from-view-id vise nije obavezno: -->
      <from-view-id><XDtFacesNavigation:fromView/></from-view-id>
      </XDtFacesNavigation:ifNeedFromViewId>

      <XDtFacesNavigation:forAllRules>
      <navigation-case>
         <XDtFacesNavigation:ifHasFromAction>
           <!-- from-action, added by cwele:-->
         <from-action><XDtFacesNavigation:fromAction/></from-action>
         </XDtFacesNavigation:ifHasFromAction>
         <from-outcome><XDtFacesNavigation:outcome/></from-outcome>
         <to-view-id><XDtFacesNavigation:toView/></to-view-id>
         <XDtFacesNavigation:ifNeedRedirect>
           <!-- redirect, added by cwele:-->
         <redirect/>
         </XDtFacesNavigation:ifNeedRedirect>
      </navigation-case>
      </XDtFacesNavigation:forAllRules>
   </navigation-rule>
    </XDtFacesNavigation:forAllViews>

2. take the NavigationTagsHandler.java, and replace with following one:

package xdoclet.modules.jsf;
import java.util.*;
import xdoclet.*;
import xjavadoc.*;

/**         --- TEST PRIMERI
                   --- primer bez from-view-id:---
 * @jsf.navigation
 *                 fromAction="#{reportHandler.yyy}"
                   result="xxx"
                   to="/yyy.jsp"

 * @jsf.navigation from="/prefFont.jsp"
 *                 fromAction="#{reportHandler.firstAction}"
                   result="success"
                   to="/prefLang.jsp"
 *                 redirect="false"

   @jsf.navigation from="/prefFont.jsp"
 *                 fromAction="#{reportHandler.secondAction}"
                   result="success"
                   to="/menuArea.jsp"
 *                 redirect="true"
 *
  @jsf.navigation from="/index.jsp"
 *                 fromAction="#{reportHandler.thirdAction}"
                   result="ok"
                   to="/allReports.jsp"
 *                 redirect="true"

 *
 * @jsf.navigation from="/test.jsp"
                   result="cancel"
                   to="/menuArea.jsp"
 *                 redirect="true"

 */
public class NavigationTagsHandler extends XDocletTagSupport
{
    /**
      samo prost bean sa geterima, koji vracaju vrednosti proslednjene
u konstruktoru
    */
    private class JsfNavigationRule
    {

        public String getFromView()
        {
            return fromView;
        }

        public String getOutcome()
        {
            return outcome;
        }

        public String getToView()
        {
            return toView;
        }

        private String fromView;
        private String outcome;
        private String toView;


        public JsfNavigationRule(String fromView, String outcome,
String toView)
        {
            /* by cwele:
            this.fromView = null;
            this.outcome = null;
            this.toView = null;
            this.fromView = fromView;
            this.outcome = outcome;
            this.toView = toView;
            */
            this(fromView, outcome, toView, null, null);
        }


        /** by cwele: konstruktor koji, pored <from-view_id> prima sve
sto moze da se nadje u
            okviru <navigation-case>...</navigation-case>

        */
        private String fromAction;
        private String redirect;

        public String getFromAction(){
            return fromAction;
        }

        public String getRedirect(){
           return redirect;
        }
        /** by cwele: konstruktor koji, pored <from-view_id> prima sve
sto moze da se nadje u
            okviru <navigation-case>...</navigation-case>

        */
        public JsfNavigationRule(String fromView,
                                 String outcome,
                                 String toView,
                                 String fromAction,
                                 String redirect)
        {
            this.fromView = null;
            this.outcome = null;
            this.toView = null;
            this.fromAction = null; //ajde da sledim njih... mada...
            this.redirect = null;

            this.fromView = fromView;
            this.outcome = outcome;
            this.toView = toView;
            this.fromAction = fromAction;
            this.redirect = redirect;
        }


    }// of JsfNavigationRule class

    public NavigationTagsHandler()
    {
        currentRule = null;
        fromViewId = null;
        rules = new HashMap();
    }

    public void forAllRules(String template)
        throws XDocletException
    {
        Collection viewRules;
        if (generateFromViewId){// treba from-view-id, 'fromViewId' je
postavljeno u forAllViews()
            viewRules = (Collection)rules.get(fromViewId);
        }else{
            viewRules = (Collection)rules.get(currentRulesKey);
        }
        for(Iterator itr = viewRules.iterator(); itr.hasNext();
generate(template))

            /*cwele: treba zbog toView() i outcome() odavde, koji se
pozivaju template-u:
                <navigation-case>

<from-outcome><XDtFacesNavigation:outcome/></from-outcome> ---poziv
outcome()

<to-view-id><XDtFacesNavigation:toView/></to-view-id> --- poziv toView()
                </navigation-case>
            */
            currentRule = (JsfNavigationRule)itr.next();

    }

    public String fromView()
    {
        return fromViewId;
    }

    public String toView()
    {
        return currentRule.getToView();
    }

    public String outcome()
    {
        return currentRule.getOutcome();
    }

    public String fromAction(){
       return currentRule.getFromAction();
    }

    public String redirect(){
       return currentRule.getRedirect();
    }
    /**
     *Donje 3 funkcije trebaju zbog faces_config_xml.xdt
     */
    public void ifHasFromAction(String template) throws XDocletException {
        if (currentRule.getFromAction() != null)
            generate(template);
    }
    public void ifNeedRedirect(String template) throws XDocletException  {
        if ((currentRule.getRedirect() != null) &&
            (currentRule.getRedirect().equals("true")))
            generate(template);
    }
    public void ifNeedFromViewId(String template) throws XDocletException{
       if (generateFromViewId) generate(template);
    }


    /**
      cwele: <XDtFacesNavigation:forAllViews>

    */
    public void forAllViews(String template)
        throws XDocletException
    {
        Collection classes = getXJavaDoc().getSourceClasses();
        Iterator i = classes.iterator();
        do
        {
            if(!i.hasNext())
                break;
            XClass clazz = (XClass)i.next();
            setCurrentClass(clazz);
            if(!DocletSupport.isDocletGenerated(getCurrentClass()) &&
hasRule(getCurrentClass()))
            {
                // cwele: uzima sve @jsf.navigation tagove iz neke klase
                Iterator it =
getCurrentClass().getDoc().getTags("jsf.navigation").iterator();
                while(it.hasNext())
                {
                    XTag tag = (XTag)it.next();
                    String fromView = tag.getAttributeValue("from");
                    String toView = tag.getAttributeValue("to");
                    String result = tag.getAttributeValue("result");
                    // cwele:
                    String fromAction =
tag.getAttributeValue("fromAction");
                    String redirect = tag.getAttributeValue("redirect");

                    // by cwele: JsfNavigationRule rule = new
JsfNavigationRule(fromView, result, toView);
                    JsfNavigationRule rule = new
JsfNavigationRule(fromView, result, toView, fromAction, redirect);

                    /* rules: HashMap koji se pravi u konstruktoru. Za isti
                     from-view-id moze biti vise navigation-case.
                     */
                    if (fromView != null) {
                      // fromView je zadato i != null:
                      Collection r = (Collection)rules.get(fromView);
                      if(r == null)
                          r = new ArrayList();
                      r.add(rule);
                      rules.put(fromView, r);
                    }else{
                      // fromView nije zadato. Svaki takav
_jsf.navigation ce da napravi
                      // po jedan navigation-rule sa JEDNIM
navigation-case unutra, mislim da je to OK
                      // drugim recima, kljucevi za HashMap 'rules'
nece vise biti samo Stringovi, nego
                      // i Integer objekti (a mogao sam odabrati bilo
sta sto nije String),
                      // i po tome cu znati treba li da generisem
<from-view-id> ili ne
                      Integer key = new Integer(myCounter++);
                      ArrayList ruleHolder = new ArrayList();
                      ruleHolder.add(rule);
                      rules.put(key, ruleHolder);
                    }// if-else

                }// kraj obrade za jedan jsf.navigation tag iz source fajla
            }
        } while(true);// kraj za pojedinacan .java source fajl
        for(Iterator it = rules.keySet().iterator(); it.hasNext();
generate(template)){

            // cwele: fromViewId treba postaviti zbog:

            //
<from-view-id><XDtFacesNavigation:fromView/></from-view-id> --- poziv
fromView() odavde
            // originalno, ovo je obavezno, pa ako se ne zada, bude
NullPOinterException (pukne li ovde ?)
            Object currKey = it.next();
            if (currKey instanceof Integer){
                currentRulesKey = (Integer)currKey;// terbace da se u
forAllRules() uzme odgovarajuci JsfNavigationRule
                generateFromViewId = false;
            }else{// user je zadao fromView
                generateFromViewId = true;
                fromViewId = currKey.toString();
            }
            //fromViewId = it.next().toString();
        }// for loop
    }// forAllViews()

    private boolean hasRule(XClass clazz)
    {
        return clazz.getDoc().hasTag("jsf.navigation", false);
    }

    private JsfNavigationRule currentRule;
    private String fromViewId;
    private HashMap rules;

    private boolean generateFromViewId;
    private int myCounter = 0;
    private Integer currentRulesKey;
}

--------------
That is it ;-)

Janga, Sowjanya wrote:

Hi,
I have been trying to use xDoclet to generate redirect attribute for jsf navigation. I understood from XDT-1648 that it has been fixed and that the fix is in a CVS version.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
xdoclet-user mailing list
xdoclet-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xdoclet-user

Reply via email to