zoukankan      html  css  js  c++  java
  • adf笔记

    1>jsf页面js调试,手动添加debugger调试

    方案:在页面中添加debugger,然后打开“开发者工具”(必须打开),直接运行页面自动跳转到debugger处。

    2>jdeveloper使用svn版本控制,修改后版本控制异常

    方案:使用jdeveloper集成的svn版本进行控制,经常出现版本控制异常,比如修改了几个问题,查看版本变动的时候

    发现以前添加的文件都没有版本了,方法重新启动jdeveloper

    3>jdeveloper使用svn版本控制,修改文件后查看挂起的更改,发现没有记录

    方案:打开任意一个jdeveloper中的项目,然后再查看挂起的更改。

    4>jdeveloper开发过程中,调试和运行可能突然中断,然后点击页面运行或调试,进入页面后直接卡死,紧接着weblogic直接终止运行或调试。

    再次运行或是调试,weblgici始终无法启动,

    方案:run>start server instance,先运行weblogci,然后再选择页面点击运行

    5>无法验证事务处理中的所有行

    运行项目报错:

    javax.faces.el.EvaluationException: oracle.jbo.TxnValException: JBO-27023: 无法验证事务处理中的所有行。

    出错原因:提交的字段的值没有通过验证
    比如说:字段的长度过长,类型不匹配
    注意:如果对数据库中的字段做修改,要与eo同步更改。

    6>jdeveloper快捷键

    ctrl+enter:输入sop然后按ctrl+enter,输出 System.out.println()

    ctrl+enter:直接输入ctrl+enter,出来流程控制的智能提示

    ctrl+j:删除本行

    shift+enter:换行

    ctrl+shift+上下方向键:向上或向下移动当前行代码

    ctrl+shift+空格键:上下文智能提示

    shift+alt+f:格式化

    7>通用类ADFUtils和JSFUtils

      1 package view;
      2  
      3 import java.util.ArrayList;
      4 import java.util.List;
      5 
      6 import javax.faces.model.SelectItem;
      7 
      8 import oracle.adf.model.BindingContext;
      9 import oracle.adf.model.binding.DCBindingContainer;
     10 import oracle.adf.model.binding.DCIteratorBinding;
     11 import oracle.adf.model.binding.DCParameter;
     12 
     13 import oracle.adf.share.logging.ADFLogger;
     14 
     15 
     16 
     17 import oracle.binding.AttributeBinding;
     18 import oracle.binding.BindingContainer;
     19 
     20 import oracle.binding.ControlBinding;
     21 
     22 import oracle.binding.OperationBinding;
     23 
     24 
     25 import oracle.jbo.ApplicationModule;
     26 import oracle.jbo.Key;
     27 import oracle.jbo.Row;
     28 import oracle.jbo.uicli.binding.JUCtrlValueBinding;
     29 
     30 
     31 /**
     32  * A series of convenience functions for dealing with ADF Bindings.
     33  * Note: Updated for JDeveloper 11
     34  * 
     35  * @author Duncan Mills
     36  * @author Steve Muench
     37  * 
     38  * $Id: ADFUtils.java 2513 2007-09-20 20:39:13Z ralsmith $.
     39  */
     40 public class ADFUtils {
     41     
     42     public static final ADFLogger LOGGER = ADFLogger.createADFLogger(ADFUtils.class);
     43 
     44     /**
     45      * Get application module for an application module data control by name.
     46      * @param name application module data control name 
     47      * @return ApplicationModule
     48      */
     49     public static ApplicationModule getApplicationModuleForDataControl(String name) {
     50         return (ApplicationModule)JSFUtils.resolveExpression("#{data." + name + 
     51                                                              ".dataProvider}");
     52     }
     53 
     54     /**
     55      * A convenience method for getting the value of a bound attribute in the
     56      * current page context programatically.
     57      * @param attributeName of the bound value in the pageDef
     58      * @return value of the attribute
     59      */
     60     public static Object getBoundAttributeValue(String attributeName) {
     61         return findControlBinding(attributeName).getInputValue();
     62     }
     63 
     64     /**
     65      * A convenience method for setting the value of a bound attribute in the
     66      * context of the current page.
     67      * @param attributeName of the bound value in the pageDef
     68      * @param value to set
     69      */
     70     public static void setBoundAttributeValue(String attributeName, 
     71                                               Object value) {
     72         findControlBinding(attributeName).setInputValue(value);
     73     }
     74 
     75     /**
     76      * Returns the evaluated value of a pageDef parameter.
     77      * @param pageDefName reference to the page definition file of the page with the parameter
     78      * @param parameterName name of the pagedef parameter
     79      * @return evaluated value of the parameter as a String
     80      */
     81     public static Object getPageDefParameterValue(String pageDefName, 
     82                                                   String parameterName) {
     83         BindingContainer bindings = findBindingContainer(pageDefName);
     84         DCParameter param = 
     85             ((DCBindingContainer)bindings).findParameter(parameterName);
     86         return param.getValue();
     87     }
     88 
     89     /**
     90      * Convenience method to find a DCControlBinding as an AttributeBinding
     91      * to get able to then call getInputValue() or setInputValue() on it.
     92      * @param bindingContainer binding container
     93      * @param attributeName name of the attribute binding.
     94      * @return the control value binding with the name passed in.
     95      *
     96      */
     97     public static AttributeBinding findControlBinding(BindingContainer bindingContainer, 
     98                                                       String attributeName) {
     99         if (attributeName != null) {
    100             if (bindingContainer != null) {
    101                 ControlBinding ctrlBinding = 
    102                     bindingContainer.getControlBinding(attributeName);
    103                 if (ctrlBinding instanceof AttributeBinding) {
    104                     return (AttributeBinding)ctrlBinding;
    105                 }
    106             }
    107         }
    108         return null;
    109     }
    110 
    111     /**
    112      * Convenience method to find a DCControlBinding as a JUCtrlValueBinding
    113      * to get able to then call getInputValue() or setInputValue() on it.
    114      * @param attributeName name of the attribute binding.
    115      * @return the control value binding with the name passed in.
    116      *
    117      */
    118     public static AttributeBinding findControlBinding(String attributeName) {
    119         return findControlBinding(getBindingContainer(), attributeName);
    120     }
    121 
    122     /**
    123      * Return the current page's binding container.
    124      * @return the current page's binding container
    125      */
    126     public static BindingContainer getBindingContainer() {
    127         return (BindingContainer)JSFUtils.resolveExpression("#{bindings}");
    128     }
    129  
    130     /**
    131      * Return the Binding Container as a DCBindingContainer.
    132      * @return current binding container as a DCBindingContainer
    133      */
    134     public static DCBindingContainer getDCBindingContainer() {
    135         return (DCBindingContainer)getBindingContainer();
    136     }
    137 
    138     /**
    139      * Get List of ADF Faces SelectItem for an iterator binding.
    140      * 
    141      * Uses the value of the 'valueAttrName' attribute as the key for
    142      * the SelectItem key.
    143      * 
    144      * @param iteratorName ADF iterator binding name
    145      * @param valueAttrName name of the value attribute to use
    146      * @param displayAttrName name of the attribute from iterator rows to display
    147      * @return ADF Faces SelectItem for an iterator binding
    148      */
    149     public static List<SelectItem> selectItemsForIterator(String iteratorName, 
    150                                                           String valueAttrName, 
    151                                                           String displayAttrName) {
    152         return selectItemsForIterator(findIterator(iteratorName), 
    153                                       valueAttrName, displayAttrName);
    154     }
    155 
    156     /**
    157      * Get List of ADF Faces SelectItem for an iterator binding with description.
    158      * 
    159      * Uses the value of the 'valueAttrName' attribute as the key for
    160      * the SelectItem key.
    161      * 
    162      * @param iteratorName ADF iterator binding name
    163      * @param valueAttrName name of the value attribute to use
    164      * @param displayAttrName name of the attribute from iterator rows to display
    165      * @param descriptionAttrName name of the attribute to use for description
    166      * @return ADF Faces SelectItem for an iterator binding with description
    167      */
    168     public static List<SelectItem> selectItemsForIterator(String iteratorName, 
    169                                                           String valueAttrName, 
    170                                                           String displayAttrName, 
    171                                                           String descriptionAttrName) {
    172         return selectItemsForIterator(findIterator(iteratorName), 
    173                                       valueAttrName, displayAttrName, 
    174                                       descriptionAttrName);
    175     }
    176 
    177     /**
    178      * Get List of attribute values for an iterator.
    179      * @param iteratorName ADF iterator binding name
    180      * @param valueAttrName value attribute to use
    181      * @return List of attribute values for an iterator
    182      */
    183     public static List attributeListForIterator(String iteratorName, 
    184                                                 String valueAttrName) {
    185         return attributeListForIterator(findIterator(iteratorName), 
    186                                         valueAttrName);
    187     }
    188 
    189     /**
    190      * Get List of Key objects for rows in an iterator.
    191      * @param iteratorName iterabot binding name
    192      * @return List of Key objects for rows
    193      */
    194     public static List<Key> keyListForIterator(String iteratorName) {
    195         return keyListForIterator(findIterator(iteratorName));
    196     }
    197 
    198     /**
    199      * Get List of Key objects for rows in an iterator.
    200      * @param iter iterator binding
    201      * @return List of Key objects for rows
    202      */
    203     public static List<Key> keyListForIterator(DCIteratorBinding iter) {
    204         List<Key> attributeList = new ArrayList<Key>();
    205         for (Row r : iter.getAllRowsInRange()) {
    206             attributeList.add(r.getKey());
    207         }
    208         return attributeList;
    209     }
    210 
    211     /**
    212      * Get List of Key objects for rows in an iterator using key attribute.
    213      * @param iteratorName iterator binding name
    214      * @param keyAttrName name of key attribute to use
    215      * @return List of Key objects for rows
    216      */
    217     public static List<Key> keyAttrListForIterator(String iteratorName, 
    218                                                    String keyAttrName) {
    219         return keyAttrListForIterator(findIterator(iteratorName), keyAttrName);
    220     }
    221 
    222     /**
    223      * Get List of Key objects for rows in an iterator using key attribute.
    224      * 
    225      * @param iter iterator binding
    226      * @param keyAttrName name of key attribute to use
    227      * @return List of Key objects for rows
    228      */
    229     public static List<Key> keyAttrListForIterator(DCIteratorBinding iter, 
    230                                                    String keyAttrName) {
    231         List<Key> attributeList = new ArrayList<Key>();
    232         for (Row r : iter.getAllRowsInRange()) {
    233             attributeList.add(new Key(new Object[] { r.getAttribute(keyAttrName) }));
    234         }
    235         return attributeList;
    236     }
    237 
    238     /**
    239      * Get a List of attribute values for an iterator.
    240      * 
    241      * @param iter iterator binding
    242      * @param valueAttrName name of value attribute to use
    243      * @return List of attribute values
    244      */
    245     public static List attributeListForIterator(DCIteratorBinding iter, 
    246                                                 String valueAttrName) {
    247         List attributeList = new ArrayList();
    248         for (Row r : iter.getAllRowsInRange()) {
    249             attributeList.add(r.getAttribute(valueAttrName));
    250         }
    251         return attributeList;
    252     }
    253 
    254     /**
    255      * Find an iterator binding in the current binding container by name.
    256      * 
    257      * @param name iterator binding name
    258      * @return iterator binding
    259      */
    260     public static DCIteratorBinding findIterator(String name) {
    261         DCIteratorBinding iter = 
    262             getDCBindingContainer().findIteratorBinding(name);
    263         if (iter == null) {
    264             throw new RuntimeException("Iterator '" + name + "' not found");
    265         }
    266         return iter;
    267     }
    268 
    269     /**
    270      * @param bindingContainer
    271      * @param iterator
    272      * @return
    273      */
    274     public static DCIteratorBinding findIterator(String bindingContainer, String iterator) {
    275         DCBindingContainer bindings = 
    276             (DCBindingContainer)JSFUtils.resolveExpression("#{" + bindingContainer + "}");
    277         if (bindings == null) {
    278             throw new RuntimeException("Binding container '" + 
    279                                        bindingContainer + "' not found");
    280         }
    281         DCIteratorBinding iter = bindings.findIteratorBinding(iterator);
    282         if (iter == null) {
    283             throw new RuntimeException("Iterator '" + iterator + "' not found");
    284         }
    285         return iter;
    286     }
    287 
    288     /**
    289      * @param name
    290      * @return
    291      */
    292     public static JUCtrlValueBinding findCtrlBinding(String name){
    293         JUCtrlValueBinding rowBinding = 
    294             (JUCtrlValueBinding)getDCBindingContainer().findCtrlBinding(name);    
    295         if (rowBinding == null) {
    296             throw new RuntimeException("CtrlBinding " + name + "' not found");
    297         }
    298         return rowBinding;
    299     }
    300 
    301     /**
    302      * Find an operation binding in the current binding container by name.
    303      * 
    304      * @param name operation binding name
    305      * @return operation binding
    306      */
    307     public static OperationBinding findOperation(String name) {
    308         OperationBinding op = 
    309             getDCBindingContainer().getOperationBinding(name);
    310         if (op == null) {
    311             throw new RuntimeException("Operation '" + name + "' not found");
    312         }
    313         return op;
    314     }
    315 
    316     /**
    317      * Find an operation binding in the current binding container by name.
    318      * 
    319      * @param bindingContianer binding container name
    320      * @param opName operation binding name
    321      * @return operation binding
    322      */
    323     public static OperationBinding findOperation(String bindingContianer, 
    324                                                  String opName) {
    325         DCBindingContainer bindings = 
    326             (DCBindingContainer)JSFUtils.resolveExpression("#{" + bindingContianer + "}");
    327         if (bindings == null) {
    328             throw new RuntimeException("Binding container '" + 
    329                                        bindingContianer + "' not found");
    330         }
    331         OperationBinding op = 
    332             bindings.getOperationBinding(opName);
    333         if (op == null) {
    334             throw new RuntimeException("Operation '" + opName + "' not found");
    335         }
    336         return op;
    337     }
    338 
    339     /**
    340      * Get List of ADF Faces SelectItem for an iterator binding with description.
    341      * 
    342      * Uses the value of the 'valueAttrName' attribute as the key for
    343      * the SelectItem key.
    344      * 
    345      * @param iter ADF iterator binding
    346      * @param valueAttrName name of value attribute to use for key
    347      * @param displayAttrName name of the attribute from iterator rows to display
    348      * @param descriptionAttrName name of the attribute for description
    349      * @return ADF Faces SelectItem for an iterator binding with description
    350      */
    351     public static List<SelectItem> selectItemsForIterator(DCIteratorBinding iter, 
    352                                                           String valueAttrName, 
    353                                                           String displayAttrName, 
    354                                                           String descriptionAttrName) {
    355         List<SelectItem> selectItems = new ArrayList<SelectItem>();
    356         for (Row r : iter.getAllRowsInRange()) {
    357             selectItems.add(new SelectItem(r.getAttribute(valueAttrName), 
    358                                            (String)r.getAttribute(displayAttrName), 
    359                                            (String)r.getAttribute(descriptionAttrName)));
    360         }
    361         return selectItems;
    362     }
    363 
    364     /**
    365      * Get List of ADF Faces SelectItem for an iterator binding.
    366      * 
    367      * Uses the value of the 'valueAttrName' attribute as the key for
    368      * the SelectItem key.
    369      * 
    370      * @param iter ADF iterator binding
    371      * @param valueAttrName name of value attribute to use for key
    372      * @param displayAttrName name of the attribute from iterator rows to display
    373      * @return ADF Faces SelectItem for an iterator binding
    374      */
    375     public static List<SelectItem> selectItemsForIterator(DCIteratorBinding iter, 
    376                                                           String valueAttrName, 
    377                                                           String displayAttrName) {
    378         List<SelectItem> selectItems = new ArrayList<SelectItem>();
    379         for (Row r : iter.getAllRowsInRange()) {
    380             selectItems.add(new SelectItem(r.getAttribute(valueAttrName), 
    381                                            (String)r.getAttribute(displayAttrName)));
    382         }
    383         return selectItems;
    384     }
    385 
    386     /**
    387      * Get List of ADF Faces SelectItem for an iterator binding.
    388      * 
    389      * Uses the rowKey of each row as the SelectItem key.
    390      * 
    391      * @param iteratorName ADF iterator binding name
    392      * @param displayAttrName name of the attribute from iterator rows to display
    393      * @return ADF Faces SelectItem for an iterator binding
    394      */
    395     public static List<SelectItem> selectItemsByKeyForIterator(String iteratorName, 
    396                                                                String displayAttrName) {
    397         return selectItemsByKeyForIterator(findIterator(iteratorName), 
    398                                            displayAttrName);
    399     }
    400 
    401     /**
    402      * Get List of ADF Faces SelectItem for an iterator binding with discription.
    403      * 
    404      * Uses the rowKey of each row as the SelectItem key.
    405      * 
    406      * @param iteratorName ADF iterator binding name
    407      * @param displayAttrName name of the attribute from iterator rows to display
    408      * @param descriptionAttrName name of the attribute for description
    409      * @return ADF Faces SelectItem for an iterator binding with discription
    410      */
    411     public static List<SelectItem> selectItemsByKeyForIterator(String iteratorName, 
    412                                                                String displayAttrName, 
    413                                                                String descriptionAttrName) {
    414         return selectItemsByKeyForIterator(findIterator(iteratorName), 
    415                                            displayAttrName, 
    416                                            descriptionAttrName);
    417     }
    418 
    419     /**
    420      * Get List of ADF Faces SelectItem for an iterator binding with discription.
    421      * 
    422      * Uses the rowKey of each row as the SelectItem key.
    423      * 
    424      * @param iter ADF iterator binding
    425      * @param displayAttrName name of the attribute from iterator rows to display
    426      * @param descriptionAttrName name of the attribute for description
    427      * @return ADF Faces SelectItem for an iterator binding with discription
    428      */
    429     public static List<SelectItem> selectItemsByKeyForIterator(DCIteratorBinding iter, 
    430                                                                String displayAttrName, 
    431                                                                String descriptionAttrName) {
    432         List<SelectItem> selectItems = new ArrayList<SelectItem>();
    433         for (Row r : iter.getAllRowsInRange()) {
    434             selectItems.add(new SelectItem(r.getKey(), 
    435                                            (String)r.getAttribute(displayAttrName), 
    436                                            (String)r.getAttribute(descriptionAttrName)));
    437         }
    438         return selectItems;
    439     }
    440 
    441     /**
    442      * Get List of ADF Faces SelectItem for an iterator binding.
    443      * 
    444      * Uses the rowKey of each row as the SelectItem key.
    445      * 
    446      * @param iter ADF iterator binding
    447      * @param displayAttrName name of the attribute from iterator rows to display
    448      * @return List of ADF Faces SelectItem for an iterator binding
    449      */
    450     public static List<SelectItem> selectItemsByKeyForIterator(DCIteratorBinding iter, 
    451                                                                String displayAttrName) {
    452         List<SelectItem> selectItems = new ArrayList<SelectItem>();
    453         for (Row r : iter.getAllRowsInRange()) {
    454             selectItems.add(new SelectItem(r.getKey(), 
    455                                            (String)r.getAttribute(displayAttrName)));
    456         }
    457         return selectItems;
    458     }
    459 
    460     /**
    461      * Find the BindingContainer for a page definition by name.
    462      *
    463      * Typically used to refer eagerly to page definition parameters. It is
    464      * not best practice to reference or set bindings in binding containers
    465      * that are not the one for the current page.
    466      *
    467      * @param pageDefName name of the page defintion XML file to use
    468      * @return BindingContainer ref for the named definition
    469      */
    470     private static BindingContainer findBindingContainer(String pageDefName) {
    471         BindingContext bctx = getDCBindingContainer().getBindingContext();
    472         BindingContainer foundContainer = 
    473             bctx.findBindingContainer(pageDefName);
    474         return foundContainer;
    475     }
    476 
    477     /**
    478      * @param opList
    479      */
    480     public static void printOperationBindingExceptions(List opList){
    481         if(opList != null && !opList.isEmpty()){
    482             for(Object error:opList){
    483                 LOGGER.severe( error.toString() );
    484             }
    485         }
    486     }
    487 }
    ADFUtils
      1 package view;
      2 
      3 import java.util.Iterator;
      4 import java.util.Locale;
      5 import java.util.Map;
      6 import java.util.MissingResourceException;
      7 import java.util.ResourceBundle;
      8 
      9 import javax.el.ELContext;
     10 import javax.el.ExpressionFactory;
     11 
     12 import javax.el.MethodExpression;
     13 import javax.el.ValueExpression;
     14 
     15 import javax.faces.application.Application;
     16 import javax.faces.application.FacesMessage;
     17 import javax.faces.component.UIComponent;
     18 import javax.faces.component.UIViewRoot;
     19 import javax.faces.context.ExternalContext;
     20 import javax.faces.context.FacesContext;
     21 
     22 import javax.servlet.http.HttpServletRequest;
     23 
     24  
     25 /**
     26  * General useful static utilies for working with JSF.
     27  * NOTE: Updated to use JSF 1.2 ExpressionFactory.
     28  *
     29  * @author Duncan Mills
     30  * @author Steve Muench
     31  *
     32  * $Id: JSFUtils.java 1885 2007-06-26 00:47:41Z ralsmith $
     33  */
     34 public class JSFUtils {
     35  
     36     private static final String NO_RESOURCE_FOUND = "Missing resource: ";
     37 
     38     /**
     39      * Method for taking a reference to a JSF binding expression and returning
     40      * the matching object (or creating it).
     41      * @param expression EL expression
     42      * @return Managed object
     43      */
     44     public static Object resolveExpression(String expression) {
     45         FacesContext facesContext = getFacesContext();
     46         Application app = facesContext.getApplication();
     47         ExpressionFactory elFactory = app.getExpressionFactory();
     48         ELContext elContext = facesContext.getELContext();
     49         ValueExpression valueExp = 
     50             elFactory.createValueExpression(elContext, expression, 
     51                                             Object.class);
     52         return valueExp.getValue(elContext);
     53     }
     54 
     55     /**
     56      * @return
     57      */
     58     public static String resolveRemoteUser() {
     59         FacesContext facesContext = getFacesContext();
     60         ExternalContext ectx = facesContext.getExternalContext();
     61         return ectx.getRemoteUser();
     62     }
     63 
     64     /**
     65      * @return
     66      */
     67     public static String resolveUserPrincipal() {
     68         FacesContext facesContext = getFacesContext();
     69         ExternalContext ectx = facesContext.getExternalContext();
     70         HttpServletRequest request = (HttpServletRequest)ectx.getRequest();
     71         return request.getUserPrincipal().getName();
     72     }
     73 
     74     /**
     75      * @param expression
     76      * @param returnType
     77      * @param argTypes
     78      * @param argValues
     79      * @return
     80      */
     81     public static Object resolveMethodExpression(String expression, 
     82                                                  Class returnType, 
     83                                                  Class[] argTypes, 
     84                                                  Object[] argValues) {
     85         FacesContext facesContext = getFacesContext();
     86         Application app = facesContext.getApplication();
     87         ExpressionFactory elFactory = app.getExpressionFactory();
     88         ELContext elContext = facesContext.getELContext();
     89         MethodExpression methodExpression = 
     90             elFactory.createMethodExpression(elContext, expression, returnType, 
     91                                              argTypes);
     92         return methodExpression.invoke(elContext, argValues);
     93     }
     94 
     95     /**
     96      * Method for taking a reference to a JSF binding expression and returning
     97      * the matching Boolean.
     98      * @param expression EL expression
     99      * @return Managed object
    100      */
    101     public static Boolean resolveExpressionAsBoolean(String expression) {
    102         return (Boolean)resolveExpression(expression);
    103     }
    104 
    105     /**
    106      * Method for taking a reference to a JSF binding expression and returning
    107      * the matching String (or creating it).
    108      * @param expression EL expression
    109      * @return Managed object
    110      */
    111     public static String resolveExpressionAsString(String expression) {
    112         return (String)resolveExpression(expression);
    113     }
    114 
    115     /**
    116      * Convenience method for resolving a reference to a managed bean by name
    117      * rather than by expression.
    118      * @param beanName name of managed bean
    119      * @return Managed object
    120      */
    121     public static Object getManagedBeanValue(String beanName) {
    122         StringBuffer buff = new StringBuffer("#{");
    123         buff.append(beanName);
    124         buff.append("}");
    125         return resolveExpression(buff.toString());
    126     }
    127 
    128     /**
    129      * Method for setting a new object into a JSF managed bean
    130      * Note: will fail silently if the supplied object does
    131      * not match the type of the managed bean.
    132      * @param expression EL expression
    133      * @param newValue new value to set
    134      */
    135     public static void setExpressionValue(String expression, Object newValue) {
    136         FacesContext facesContext = getFacesContext();
    137         Application app = facesContext.getApplication();
    138         ExpressionFactory elFactory = app.getExpressionFactory();
    139         ELContext elContext = facesContext.getELContext();
    140         ValueExpression valueExp = 
    141             elFactory.createValueExpression(elContext, expression, 
    142                                             Object.class);
    143 
    144         //Check that the input newValue can be cast to the property type
    145         //expected by the managed bean.
    146         //If the managed Bean expects a primitive we rely on Auto-Unboxing
    147         Class bindClass = valueExp.getType(elContext);
    148         if (bindClass.isPrimitive() || bindClass.isInstance(newValue)) {
    149             valueExp.setValue(elContext, newValue);
    150         }
    151     }
    152 
    153     /**
    154      * Convenience method for setting the value of a managed bean by name
    155      * rather than by expression.
    156      * @param beanName name of managed bean
    157      * @param newValue new value to set
    158      */
    159     public static void setManagedBeanValue(String beanName, Object newValue) {
    160         StringBuffer buff = new StringBuffer("#{");
    161         buff.append(beanName);
    162         buff.append("}");
    163         setExpressionValue(buff.toString(), newValue);
    164     }
    165 
    166 
    167     /**
    168      * Convenience method for setting Session variables.
    169      * @param key object key
    170      * @param object value to store
    171      */
    172     public static
    173 
    174     void storeOnSession(String key, Object object) {
    175         FacesContext ctx = getFacesContext();
    176         Map sessionState = ctx.getExternalContext().getSessionMap();
    177         sessionState.put(key, object);
    178     }
    179 
    180     /**
    181      * Convenience method for getting Session variables.
    182      * @param key object key
    183      * @return session object for key
    184      */
    185     public static Object getFromSession(String key) {
    186         FacesContext ctx = getFacesContext();
    187         Map sessionState = ctx.getExternalContext().getSessionMap();
    188         return sessionState.get(key);
    189     }
    190 
    191     /**
    192      * @param key
    193      * @return
    194      */
    195     public static String getFromHeader(String key) {
    196         FacesContext ctx = getFacesContext();
    197         ExternalContext ectx = ctx.getExternalContext();
    198         return ectx.getRequestHeaderMap().get(key);
    199     }
    200 
    201     /**
    202      * Convenience method for getting Request variables.
    203      * @param key object key
    204      * @return session object for key
    205      */
    206     public static Object getFromRequest(String key) {
    207         FacesContext ctx = getFacesContext();
    208         Map sessionState = ctx.getExternalContext().getRequestMap();
    209         return sessionState.get(key);
    210     }
    211 
    212     /**
    213      * Pulls a String resource from the property bundle that
    214      * is defined under the application &lt;message-bundle&gt; element in
    215      * the faces config. Respects Locale
    216      * @param key string message key
    217      * @return Resource value or placeholder error String
    218      */
    219     public static String getStringFromBundle(String key) {
    220         ResourceBundle bundle = getBundle();
    221         return getStringSafely(bundle, key, null);
    222     }
    223 
    224 
    225     /**
    226      * Convenience method to construct a <code>FacesMesssage</code>
    227      * from a defined error key and severity
    228      * This assumes that the error keys follow the convention of
    229      * using <b>_detail</b> for the detailed part of the
    230      * message, otherwise the main message is returned for the
    231      * detail as well.
    232      * @param key for the error message in the resource bundle
    233      * @param severity severity of message
    234      * @return Faces Message object
    235      */
    236     public static FacesMessage getMessageFromBundle(String key, 
    237                                                     FacesMessage.Severity severity) {
    238         ResourceBundle bundle = getBundle();
    239         String summary = getStringSafely(bundle, key, null);
    240         String detail = getStringSafely(bundle, key + "_detail", summary);
    241         FacesMessage message = new FacesMessage(summary, detail);
    242         message.setSeverity(severity);
    243         return message;
    244     }
    245 
    246     /**
    247      * Add JSF info message.
    248      * @param msg info message string
    249      */
    250     public static void addFacesInformationMessage(String msg) {
    251         FacesContext ctx = getFacesContext();
    252         FacesMessage fm = 
    253             new FacesMessage(FacesMessage.SEVERITY_INFO, msg, "");
    254         ctx.addMessage(getRootViewComponentId(), fm);
    255     }
    256 
    257     /**
    258      * Add JSF error message.
    259      * @param msg error message string
    260      */
    261     public static void addFacesErrorMessage(String msg) {
    262         FacesContext ctx = getFacesContext();
    263         FacesMessage fm = 
    264             new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, "");
    265         ctx.addMessage(getRootViewComponentId(), fm);
    266     }
    267 
    268     /**
    269      * Add JSF error message for a specific attribute.
    270      * @param attrName name of attribute
    271      * @param msg error message string
    272      */
    273     public static void addFacesErrorMessage(String attrName, String msg) {
    274         FacesContext ctx = getFacesContext();
    275         FacesMessage fm = 
    276             new FacesMessage(FacesMessage.SEVERITY_ERROR, attrName, msg);
    277         ctx.addMessage(getRootViewComponentId(), fm);
    278     }
    279 
    280     // Informational getters
    281 
    282     /**
    283      * Get view id of the view root.
    284      * @return view id of the view root
    285      */
    286     public static String getRootViewId() {
    287         return getFacesContext().getViewRoot().getViewId();
    288     }
    289 
    290     /**
    291      * Get component id of the view root.
    292      * @return component id of the view root
    293      */
    294     public static String getRootViewComponentId() {
    295         return getFacesContext().getViewRoot().getId();
    296     }
    297 
    298     /**
    299      * Get FacesContext.
    300      * @return FacesContext
    301      */
    302     public static FacesContext getFacesContext() {
    303         return FacesContext.getCurrentInstance();
    304     }
    305     /*
    306    * Internal method to pull out the correct local
    307    * message bundle
    308    */
    309 
    310     private static ResourceBundle getBundle() {
    311         FacesContext ctx = getFacesContext();
    312         UIViewRoot uiRoot = ctx.getViewRoot();
    313         Locale locale = uiRoot.getLocale();
    314         ClassLoader ldr = Thread.currentThread().getContextClassLoader();
    315         return ResourceBundle.getBundle(ctx.getApplication().getMessageBundle(), 
    316                                         locale, ldr);
    317     }
    318 
    319     /**
    320      * Get an HTTP Request attribute.
    321      * @param name attribute name
    322      * @return attribute value
    323      */
    324     public static Object getRequestAttribute(String name) {
    325         return getFacesContext().getExternalContext().getRequestMap().get(name);
    326     }
    327 
    328     /**
    329      * Set an HTTP Request attribute.
    330      * @param name attribute name
    331      * @param value attribute value
    332      */
    333     public static void setRequestAttribute(String name, Object value) {
    334         getFacesContext().getExternalContext().getRequestMap().put(name, 
    335                                                                    value);
    336     }
    337 
    338     /*
    339    * Internal method to proxy for resource keys that don't exist
    340    */
    341 
    342     private static String getStringSafely(ResourceBundle bundle, String key, 
    343                                           String defaultValue) {
    344         String resource = null;
    345         try {
    346             resource = bundle.getString(key);
    347         } catch (MissingResourceException mrex) {
    348             if (defaultValue != null) {
    349                 resource = defaultValue;
    350             } else {
    351                 resource = NO_RESOURCE_FOUND + key;
    352             }
    353         }
    354         return resource;
    355     }
    356 
    357     /**
    358      * Locate an UIComponent in view root with its component id. Use a recursive way to achieve this.
    359      * @param id UIComponent id
    360      * @return UIComponent object
    361      */
    362     public static UIComponent findComponentInRoot(String id) {
    363         UIComponent component = null;
    364         FacesContext facesContext = FacesContext.getCurrentInstance();
    365         if (facesContext != null) {
    366             UIComponent root = facesContext.getViewRoot();
    367             component = findComponent(root, id);
    368         }
    369         return component;
    370     }
    371 
    372     /**
    373      * Locate an UIComponent from its root component.
    374      * Taken from http://www.jroller.com/page/mert?entry=how_to_find_a_uicomponent
    375      * @param base root Component (parent)
    376      * @param id UIComponent id
    377      * @return UIComponent object
    378      */
    379     public static UIComponent findComponent(UIComponent base, String id) {
    380         if (id.equals(base.getId()))
    381             return base;
    382 
    383         UIComponent children = null;
    384         UIComponent result = null;
    385         Iterator childrens = base.getFacetsAndChildren();
    386         while (childrens.hasNext() && (result == null)) {
    387             children = (UIComponent)childrens.next();
    388             if (id.equals(children.getId())) {
    389                 result = children;
    390                 break;
    391             }
    392             result = findComponent(children, id);
    393             if (result != null) {
    394                 break;
    395             }
    396         }
    397         return result;
    398     }
    399 
    400     /**
    401      * Method to create a redirect URL. The assumption is that the JSF servlet mapping is
    402      * "faces", which is the default
    403      * 
    404      * @param view the JSP or JSPX page to redirect to
    405      * @return a URL to redirect to
    406      */
    407     public static String getPageURL(String view) {
    408         FacesContext facesContext = getFacesContext();
    409         ExternalContext externalContext = facesContext.getExternalContext();
    410         String url = 
    411             ((HttpServletRequest)externalContext.getRequest()).getRequestURL().toString();        
    412         StringBuffer newUrlBuffer = new StringBuffer();
    413         newUrlBuffer.append(url.substring(0, url.lastIndexOf("faces/")));
    414         newUrlBuffer.append("faces");
    415         String targetPageUrl = view.startsWith("/") ? view : "/" + view;
    416         newUrlBuffer.append(targetPageUrl);
    417         return newUrlBuffer.toString();
    418     }
    419     
    420     public static boolean isPostBack(){
    421         return JSFUtils.resolveExpressionAsBoolean("#{adfFacesContext.postback}");
    422         }
    423 
    424 }
    JSFUtils

    8>在jsf页面绑定的Managed Bean中引用am

    在bean中获取am,在对应的jsf页面中必须有注册,否则返回空

    ADFUtils.getApplicationModuleForDataControl("AppModuleAMDataControl");

    9>jsf页面跳转,十一adf的link标签,设置destination属性

    <af:link text="link 1" destination="" id="l1"/>

    程序员的基础教程:菜鸟程序员

  • 相关阅读:
    class和struct
    类内初始值(c++11)
    默认初始化、值初始化
    聚合类
    对象
    排序算法的比较
    快速排序
    堆排序
    ubunu设置java命令为全局的命令-添加到全局环境变量
    Mina笔记
  • 原文地址:https://www.cnblogs.com/guohu/p/4843554.html
Copyright © 2011-2022 走看看