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. import oracle.binding.AttributeBinding;
  16. import oracle.binding.BindingContainer;
  17.  
  18. import oracle.binding.ControlBinding;
  19.  
  20. import oracle.binding.OperationBinding;
  21.  
  22. import oracle.jbo.ApplicationModule;
  23. import oracle.jbo.Key;
  24. import oracle.jbo.Row;
  25. import oracle.jbo.uicli.binding.JUCtrlValueBinding;
  26.  
  27. /**
  28. * A series of convenience functions for dealing with ADF Bindings.
  29. * Note: Updated for JDeveloper 11
  30. *
  31. * @author Duncan Mills
  32. * @author Steve Muench
  33. *
  34. * $Id: ADFUtils.java 2513 2007-09-20 20:39:13Z ralsmith $.
  35. */
  36. public class ADFUtils {
  37.  
  38. public static final ADFLogger LOGGER = ADFLogger.createADFLogger(ADFUtils.class);
  39.  
  40. /**
  41. * Get application module for an application module data control by name.
  42. * @param name application module data control name
  43. * @return ApplicationModule
  44. */
  45. public static ApplicationModule getApplicationModuleForDataControl(String name) {
  46. return (ApplicationModule)JSFUtils.resolveExpression("#{data." + name +
  47. ".dataProvider}");
  48. }
  49.  
  50. /**
  51. * A convenience method for getting the value of a bound attribute in the
  52. * current page context programatically.
  53. * @param attributeName of the bound value in the pageDef
  54. * @return value of the attribute
  55. */
  56. public static Object getBoundAttributeValue(String attributeName) {
  57. return findControlBinding(attributeName).getInputValue();
  58. }
  59.  
  60. /**
  61. * A convenience method for setting the value of a bound attribute in the
  62. * context of the current page.
  63. * @param attributeName of the bound value in the pageDef
  64. * @param value to set
  65. */
  66. public static void setBoundAttributeValue(String attributeName,
  67. Object value) {
  68. findControlBinding(attributeName).setInputValue(value);
  69. }
  70.  
  71. /**
  72. * Returns the evaluated value of a pageDef parameter.
  73. * @param pageDefName reference to the page definition file of the page with the parameter
  74. * @param parameterName name of the pagedef parameter
  75. * @return evaluated value of the parameter as a String
  76. */
  77. public static Object getPageDefParameterValue(String pageDefName,
  78. String parameterName) {
  79. BindingContainer bindings = findBindingContainer(pageDefName);
  80. DCParameter param =
  81. ((DCBindingContainer)bindings).findParameter(parameterName);
  82. return param.getValue();
  83. }
  84.  
  85. /**
  86. * Convenience method to find a DCControlBinding as an AttributeBinding
  87. * to get able to then call getInputValue() or setInputValue() on it.
  88. * @param bindingContainer binding container
  89. * @param attributeName name of the attribute binding.
  90. * @return the control value binding with the name passed in.
  91. *
  92. */
  93. public static AttributeBinding findControlBinding(BindingContainer bindingContainer,
  94. String attributeName) {
  95. if (attributeName != null) {
  96. if (bindingContainer != null) {
  97. ControlBinding ctrlBinding =
  98. bindingContainer.getControlBinding(attributeName);
  99. if (ctrlBinding instanceof AttributeBinding) {
  100. return (AttributeBinding)ctrlBinding;
  101. }
  102. }
  103. }
  104. return null;
  105. }
  106.  
  107. /**
  108. * Convenience method to find a DCControlBinding as a JUCtrlValueBinding
  109. * to get able to then call getInputValue() or setInputValue() on it.
  110. * @param attributeName name of the attribute binding.
  111. * @return the control value binding with the name passed in.
  112. *
  113. */
  114. public static AttributeBinding findControlBinding(String attributeName) {
  115. return findControlBinding(getBindingContainer(), attributeName);
  116. }
  117.  
  118. /**
  119. * Return the current page's binding container.
  120. * @return the current page's binding container
  121. */
  122. public static BindingContainer getBindingContainer() {
  123. return (BindingContainer)JSFUtils.resolveExpression("#{bindings}");
  124. }
  125.  
  126. /**
  127. * Return the Binding Container as a DCBindingContainer.
  128. * @return current binding container as a DCBindingContainer
  129. */
  130. public static DCBindingContainer getDCBindingContainer() {
  131. return (DCBindingContainer)getBindingContainer();
  132. }
  133.  
  134. /**
  135. * Get List of ADF Faces SelectItem for an iterator binding.
  136. *
  137. * Uses the value of the 'valueAttrName' attribute as the key for
  138. * the SelectItem key.
  139. *
  140. * @param iteratorName ADF iterator binding name
  141. * @param valueAttrName name of the value attribute to use
  142. * @param displayAttrName name of the attribute from iterator rows to display
  143. * @return ADF Faces SelectItem for an iterator binding
  144. */
  145. public static List<SelectItem> selectItemsForIterator(String iteratorName,
  146. String valueAttrName,
  147. String displayAttrName) {
  148. return selectItemsForIterator(findIterator(iteratorName),
  149. valueAttrName, displayAttrName);
  150. }
  151.  
  152. /**
  153. * Get List of ADF Faces SelectItem for an iterator binding with description.
  154. *
  155. * Uses the value of the 'valueAttrName' attribute as the key for
  156. * the SelectItem key.
  157. *
  158. * @param iteratorName ADF iterator binding name
  159. * @param valueAttrName name of the value attribute to use
  160. * @param displayAttrName name of the attribute from iterator rows to display
  161. * @param descriptionAttrName name of the attribute to use for description
  162. * @return ADF Faces SelectItem for an iterator binding with description
  163. */
  164. public static List<SelectItem> selectItemsForIterator(String iteratorName,
  165. String valueAttrName,
  166. String displayAttrName,
  167. String descriptionAttrName) {
  168. return selectItemsForIterator(findIterator(iteratorName),
  169. valueAttrName, displayAttrName,
  170. descriptionAttrName);
  171. }
  172.  
  173. /**
  174. * Get List of attribute values for an iterator.
  175. * @param iteratorName ADF iterator binding name
  176. * @param valueAttrName value attribute to use
  177. * @return List of attribute values for an iterator
  178. */
  179. public static List attributeListForIterator(String iteratorName,
  180. String valueAttrName) {
  181. return attributeListForIterator(findIterator(iteratorName),
  182. valueAttrName);
  183. }
  184.  
  185. /**
  186. * Get List of Key objects for rows in an iterator.
  187. * @param iteratorName iterabot binding name
  188. * @return List of Key objects for rows
  189. */
  190. public static List<Key> keyListForIterator(String iteratorName) {
  191. return keyListForIterator(findIterator(iteratorName));
  192. }
  193.  
  194. /**
  195. * Get List of Key objects for rows in an iterator.
  196. * @param iter iterator binding
  197. * @return List of Key objects for rows
  198. */
  199. public static List<Key> keyListForIterator(DCIteratorBinding iter) {
  200. List<Key> attributeList = new ArrayList<Key>();
  201. for (Row r : iter.getAllRowsInRange()) {
  202. attributeList.add(r.getKey());
  203. }
  204. return attributeList;
  205. }
  206.  
  207. /**
  208. * Get List of Key objects for rows in an iterator using key attribute.
  209. * @param iteratorName iterator binding name
  210. * @param keyAttrName name of key attribute to use
  211. * @return List of Key objects for rows
  212. */
  213. public static List<Key> keyAttrListForIterator(String iteratorName,
  214. String keyAttrName) {
  215. return keyAttrListForIterator(findIterator(iteratorName), keyAttrName);
  216. }
  217.  
  218. /**
  219. * Get List of Key objects for rows in an iterator using key attribute.
  220. *
  221. * @param iter iterator binding
  222. * @param keyAttrName name of key attribute to use
  223. * @return List of Key objects for rows
  224. */
  225. public static List<Key> keyAttrListForIterator(DCIteratorBinding iter,
  226. String keyAttrName) {
  227. List<Key> attributeList = new ArrayList<Key>();
  228. for (Row r : iter.getAllRowsInRange()) {
  229. attributeList.add(new Key(new Object[] { r.getAttribute(keyAttrName) }));
  230. }
  231. return attributeList;
  232. }
  233.  
  234. /**
  235. * Get a List of attribute values for an iterator.
  236. *
  237. * @param iter iterator binding
  238. * @param valueAttrName name of value attribute to use
  239. * @return List of attribute values
  240. */
  241. public static List attributeListForIterator(DCIteratorBinding iter,
  242. String valueAttrName) {
  243. List attributeList = new ArrayList();
  244. for (Row r : iter.getAllRowsInRange()) {
  245. attributeList.add(r.getAttribute(valueAttrName));
  246. }
  247. return attributeList;
  248. }
  249.  
  250. /**
  251. * Find an iterator binding in the current binding container by name.
  252. *
  253. * @param name iterator binding name
  254. * @return iterator binding
  255. */
  256. public static DCIteratorBinding findIterator(String name) {
  257. DCIteratorBinding iter =
  258. getDCBindingContainer().findIteratorBinding(name);
  259. if (iter == null) {
  260. throw new RuntimeException("Iterator '" + name + "' not found");
  261. }
  262. return iter;
  263. }
  264.  
  265. /**
  266. * @param bindingContainer
  267. * @param iterator
  268. * @return
  269. */
  270. public static DCIteratorBinding findIterator(String bindingContainer, String iterator) {
  271. DCBindingContainer bindings =
  272. (DCBindingContainer)JSFUtils.resolveExpression("#{" + bindingContainer + "}");
  273. if (bindings == null) {
  274. throw new RuntimeException("Binding container '" +
  275. bindingContainer + "' not found");
  276. }
  277. DCIteratorBinding iter = bindings.findIteratorBinding(iterator);
  278. if (iter == null) {
  279. throw new RuntimeException("Iterator '" + iterator + "' not found");
  280. }
  281. return iter;
  282. }
  283.  
  284. /**
  285. * @param name
  286. * @return
  287. */
  288. public static JUCtrlValueBinding findCtrlBinding(String name){
  289. JUCtrlValueBinding rowBinding =
  290. (JUCtrlValueBinding)getDCBindingContainer().findCtrlBinding(name);
  291. if (rowBinding == null) {
  292. throw new RuntimeException("CtrlBinding " + name + "' not found");
  293. }
  294. return rowBinding;
  295. }
  296.  
  297. /**
  298. * Find an operation binding in the current binding container by name.
  299. *
  300. * @param name operation binding name
  301. * @return operation binding
  302. */
  303. public static OperationBinding findOperation(String name) {
  304. OperationBinding op =
  305. getDCBindingContainer().getOperationBinding(name);
  306. if (op == null) {
  307. throw new RuntimeException("Operation '" + name + "' not found");
  308. }
  309. return op;
  310. }
  311.  
  312. /**
  313. * Find an operation binding in the current binding container by name.
  314. *
  315. * @param bindingContianer binding container name
  316. * @param opName operation binding name
  317. * @return operation binding
  318. */
  319. public static OperationBinding findOperation(String bindingContianer,
  320. String opName) {
  321. DCBindingContainer bindings =
  322. (DCBindingContainer)JSFUtils.resolveExpression("#{" + bindingContianer + "}");
  323. if (bindings == null) {
  324. throw new RuntimeException("Binding container '" +
  325. bindingContianer + "' not found");
  326. }
  327. OperationBinding op =
  328. bindings.getOperationBinding(opName);
  329. if (op == null) {
  330. throw new RuntimeException("Operation '" + opName + "' not found");
  331. }
  332. return op;
  333. }
  334.  
  335. /**
  336. * Get List of ADF Faces SelectItem for an iterator binding with description.
  337. *
  338. * Uses the value of the 'valueAttrName' attribute as the key for
  339. * the SelectItem key.
  340. *
  341. * @param iter ADF iterator binding
  342. * @param valueAttrName name of value attribute to use for key
  343. * @param displayAttrName name of the attribute from iterator rows to display
  344. * @param descriptionAttrName name of the attribute for description
  345. * @return ADF Faces SelectItem for an iterator binding with description
  346. */
  347. public static List<SelectItem> selectItemsForIterator(DCIteratorBinding iter,
  348. String valueAttrName,
  349. String displayAttrName,
  350. String descriptionAttrName) {
  351. List<SelectItem> selectItems = new ArrayList<SelectItem>();
  352. for (Row r : iter.getAllRowsInRange()) {
  353. selectItems.add(new SelectItem(r.getAttribute(valueAttrName),
  354. (String)r.getAttribute(displayAttrName),
  355. (String)r.getAttribute(descriptionAttrName)));
  356. }
  357. return selectItems;
  358. }
  359.  
  360. /**
  361. * Get List of ADF Faces SelectItem for an iterator binding.
  362. *
  363. * Uses the value of the 'valueAttrName' attribute as the key for
  364. * the SelectItem key.
  365. *
  366. * @param iter ADF iterator binding
  367. * @param valueAttrName name of value attribute to use for key
  368. * @param displayAttrName name of the attribute from iterator rows to display
  369. * @return ADF Faces SelectItem for an iterator binding
  370. */
  371. public static List<SelectItem> selectItemsForIterator(DCIteratorBinding iter,
  372. String valueAttrName,
  373. String displayAttrName) {
  374. List<SelectItem> selectItems = new ArrayList<SelectItem>();
  375. for (Row r : iter.getAllRowsInRange()) {
  376. selectItems.add(new SelectItem(r.getAttribute(valueAttrName),
  377. (String)r.getAttribute(displayAttrName)));
  378. }
  379. return selectItems;
  380. }
  381.  
  382. /**
  383. * Get List of ADF Faces SelectItem for an iterator binding.
  384. *
  385. * Uses the rowKey of each row as the SelectItem key.
  386. *
  387. * @param iteratorName ADF iterator binding name
  388. * @param displayAttrName name of the attribute from iterator rows to display
  389. * @return ADF Faces SelectItem for an iterator binding
  390. */
  391. public static List<SelectItem> selectItemsByKeyForIterator(String iteratorName,
  392. String displayAttrName) {
  393. return selectItemsByKeyForIterator(findIterator(iteratorName),
  394. displayAttrName);
  395. }
  396.  
  397. /**
  398. * Get List of ADF Faces SelectItem for an iterator binding with discription.
  399. *
  400. * Uses the rowKey of each row as the SelectItem key.
  401. *
  402. * @param iteratorName ADF iterator binding name
  403. * @param displayAttrName name of the attribute from iterator rows to display
  404. * @param descriptionAttrName name of the attribute for description
  405. * @return ADF Faces SelectItem for an iterator binding with discription
  406. */
  407. public static List<SelectItem> selectItemsByKeyForIterator(String iteratorName,
  408. String displayAttrName,
  409. String descriptionAttrName) {
  410. return selectItemsByKeyForIterator(findIterator(iteratorName),
  411. displayAttrName,
  412. descriptionAttrName);
  413. }
  414.  
  415. /**
  416. * Get List of ADF Faces SelectItem for an iterator binding with discription.
  417. *
  418. * Uses the rowKey of each row as the SelectItem key.
  419. *
  420. * @param iter ADF iterator binding
  421. * @param displayAttrName name of the attribute from iterator rows to display
  422. * @param descriptionAttrName name of the attribute for description
  423. * @return ADF Faces SelectItem for an iterator binding with discription
  424. */
  425. public static List<SelectItem> selectItemsByKeyForIterator(DCIteratorBinding iter,
  426. String displayAttrName,
  427. String descriptionAttrName) {
  428. List<SelectItem> selectItems = new ArrayList<SelectItem>();
  429. for (Row r : iter.getAllRowsInRange()) {
  430. selectItems.add(new SelectItem(r.getKey(),
  431. (String)r.getAttribute(displayAttrName),
  432. (String)r.getAttribute(descriptionAttrName)));
  433. }
  434. return selectItems;
  435. }
  436.  
  437. /**
  438. * Get List of ADF Faces SelectItem for an iterator binding.
  439. *
  440. * Uses the rowKey of each row as the SelectItem key.
  441. *
  442. * @param iter ADF iterator binding
  443. * @param displayAttrName name of the attribute from iterator rows to display
  444. * @return List of ADF Faces SelectItem for an iterator binding
  445. */
  446. public static List<SelectItem> selectItemsByKeyForIterator(DCIteratorBinding iter,
  447. String displayAttrName) {
  448. List<SelectItem> selectItems = new ArrayList<SelectItem>();
  449. for (Row r : iter.getAllRowsInRange()) {
  450. selectItems.add(new SelectItem(r.getKey(),
  451. (String)r.getAttribute(displayAttrName)));
  452. }
  453. return selectItems;
  454. }
  455.  
  456. /**
  457. * Find the BindingContainer for a page definition by name.
  458. *
  459. * Typically used to refer eagerly to page definition parameters. It is
  460. * not best practice to reference or set bindings in binding containers
  461. * that are not the one for the current page.
  462. *
  463. * @param pageDefName name of the page defintion XML file to use
  464. * @return BindingContainer ref for the named definition
  465. */
  466. private static BindingContainer findBindingContainer(String pageDefName) {
  467. BindingContext bctx = getDCBindingContainer().getBindingContext();
  468. BindingContainer foundContainer =
  469. bctx.findBindingContainer(pageDefName);
  470. return foundContainer;
  471. }
  472.  
  473. /**
  474. * @param opList
  475. */
  476. public static void printOperationBindingExceptions(List opList){
  477. if(opList != null && !opList.isEmpty()){
  478. for(Object error:opList){
  479. LOGGER.severe( error.toString() );
  480. }
  481. }
  482. }
  483. }

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. * General useful static utilies for working with JSF.
  26. * NOTE: Updated to use JSF 1.2 ExpressionFactory.
  27. *
  28. * @author Duncan Mills
  29. * @author Steve Muench
  30. *
  31. * $Id: JSFUtils.java 1885 2007-06-26 00:47:41Z ralsmith $
  32. */
  33. public class JSFUtils {
  34.  
  35. private static final String NO_RESOURCE_FOUND = "Missing resource: ";
  36.  
  37. /**
  38. * Method for taking a reference to a JSF binding expression and returning
  39. * the matching object (or creating it).
  40. * @param expression EL expression
  41. * @return Managed object
  42. */
  43. public static Object resolveExpression(String expression) {
  44. FacesContext facesContext = getFacesContext();
  45. Application app = facesContext.getApplication();
  46. ExpressionFactory elFactory = app.getExpressionFactory();
  47. ELContext elContext = facesContext.getELContext();
  48. ValueExpression valueExp =
  49. elFactory.createValueExpression(elContext, expression,
  50. Object.class);
  51. return valueExp.getValue(elContext);
  52. }
  53.  
  54. /**
  55. * @return
  56. */
  57. public static String resolveRemoteUser() {
  58. FacesContext facesContext = getFacesContext();
  59. ExternalContext ectx = facesContext.getExternalContext();
  60. return ectx.getRemoteUser();
  61. }
  62.  
  63. /**
  64. * @return
  65. */
  66. public static String resolveUserPrincipal() {
  67. FacesContext facesContext = getFacesContext();
  68. ExternalContext ectx = facesContext.getExternalContext();
  69. HttpServletRequest request = (HttpServletRequest)ectx.getRequest();
  70. return request.getUserPrincipal().getName();
  71. }
  72.  
  73. /**
  74. * @param expression
  75. * @param returnType
  76. * @param argTypes
  77. * @param argValues
  78. * @return
  79. */
  80. public static Object resolveMethodExpression(String expression,
  81. Class returnType,
  82. Class[] argTypes,
  83. Object[] argValues) {
  84. FacesContext facesContext = getFacesContext();
  85. Application app = facesContext.getApplication();
  86. ExpressionFactory elFactory = app.getExpressionFactory();
  87. ELContext elContext = facesContext.getELContext();
  88. MethodExpression methodExpression =
  89. elFactory.createMethodExpression(elContext, expression, returnType,
  90. argTypes);
  91. return methodExpression.invoke(elContext, argValues);
  92. }
  93.  
  94. /**
  95. * Method for taking a reference to a JSF binding expression and returning
  96. * the matching Boolean.
  97. * @param expression EL expression
  98. * @return Managed object
  99. */
  100. public static Boolean resolveExpressionAsBoolean(String expression) {
  101. return (Boolean)resolveExpression(expression);
  102. }
  103.  
  104. /**
  105. * Method for taking a reference to a JSF binding expression and returning
  106. * the matching String (or creating it).
  107. * @param expression EL expression
  108. * @return Managed object
  109. */
  110. public static String resolveExpressionAsString(String expression) {
  111. return (String)resolveExpression(expression);
  112. }
  113.  
  114. /**
  115. * Convenience method for resolving a reference to a managed bean by name
  116. * rather than by expression.
  117. * @param beanName name of managed bean
  118. * @return Managed object
  119. */
  120. public static Object getManagedBeanValue(String beanName) {
  121. StringBuffer buff = new StringBuffer("#{");
  122. buff.append(beanName);
  123. buff.append("}");
  124. return resolveExpression(buff.toString());
  125. }
  126.  
  127. /**
  128. * Method for setting a new object into a JSF managed bean
  129. * Note: will fail silently if the supplied object does
  130. * not match the type of the managed bean.
  131. * @param expression EL expression
  132. * @param newValue new value to set
  133. */
  134. public static void setExpressionValue(String expression, Object newValue) {
  135. FacesContext facesContext = getFacesContext();
  136. Application app = facesContext.getApplication();
  137. ExpressionFactory elFactory = app.getExpressionFactory();
  138. ELContext elContext = facesContext.getELContext();
  139. ValueExpression valueExp =
  140. elFactory.createValueExpression(elContext, expression,
  141. Object.class);
  142.  
  143. //Check that the input newValue can be cast to the property type
  144. //expected by the managed bean.
  145. //If the managed Bean expects a primitive we rely on Auto-Unboxing
  146. Class bindClass = valueExp.getType(elContext);
  147. if (bindClass.isPrimitive() || bindClass.isInstance(newValue)) {
  148. valueExp.setValue(elContext, newValue);
  149. }
  150. }
  151.  
  152. /**
  153. * Convenience method for setting the value of a managed bean by name
  154. * rather than by expression.
  155. * @param beanName name of managed bean
  156. * @param newValue new value to set
  157. */
  158. public static void setManagedBeanValue(String beanName, Object newValue) {
  159. StringBuffer buff = new StringBuffer("#{");
  160. buff.append(beanName);
  161. buff.append("}");
  162. setExpressionValue(buff.toString(), newValue);
  163. }
  164.  
  165. /**
  166. * Convenience method for setting Session variables.
  167. * @param key object key
  168. * @param object value to store
  169. */
  170. public static
  171.  
  172. void storeOnSession(String key, Object object) {
  173. FacesContext ctx = getFacesContext();
  174. Map sessionState = ctx.getExternalContext().getSessionMap();
  175. sessionState.put(key, object);
  176. }
  177.  
  178. /**
  179. * Convenience method for getting Session variables.
  180. * @param key object key
  181. * @return session object for key
  182. */
  183. public static Object getFromSession(String key) {
  184. FacesContext ctx = getFacesContext();
  185. Map sessionState = ctx.getExternalContext().getSessionMap();
  186. return sessionState.get(key);
  187. }
  188.  
  189. /**
  190. * @param key
  191. * @return
  192. */
  193. public static String getFromHeader(String key) {
  194. FacesContext ctx = getFacesContext();
  195. ExternalContext ectx = ctx.getExternalContext();
  196. return ectx.getRequestHeaderMap().get(key);
  197. }
  198.  
  199. /**
  200. * Convenience method for getting Request variables.
  201. * @param key object key
  202. * @return session object for key
  203. */
  204. public static Object getFromRequest(String key) {
  205. FacesContext ctx = getFacesContext();
  206. Map sessionState = ctx.getExternalContext().getRequestMap();
  207. return sessionState.get(key);
  208. }
  209.  
  210. /**
  211. * Pulls a String resource from the property bundle that
  212. * is defined under the application &lt;message-bundle&gt; element in
  213. * the faces config. Respects Locale
  214. * @param key string message key
  215. * @return Resource value or placeholder error String
  216. */
  217. public static String getStringFromBundle(String key) {
  218. ResourceBundle bundle = getBundle();
  219. return getStringSafely(bundle, key, null);
  220. }
  221.  
  222. /**
  223. * Convenience method to construct a <code>FacesMesssage</code>
  224. * from a defined error key and severity
  225. * This assumes that the error keys follow the convention of
  226. * using <b>_detail</b> for the detailed part of the
  227. * message, otherwise the main message is returned for the
  228. * detail as well.
  229. * @param key for the error message in the resource bundle
  230. * @param severity severity of message
  231. * @return Faces Message object
  232. */
  233. public static FacesMessage getMessageFromBundle(String key,
  234. FacesMessage.Severity severity) {
  235. ResourceBundle bundle = getBundle();
  236. String summary = getStringSafely(bundle, key, null);
  237. String detail = getStringSafely(bundle, key + "_detail", summary);
  238. FacesMessage message = new FacesMessage(summary, detail);
  239. message.setSeverity(severity);
  240. return message;
  241. }
  242.  
  243. /**
  244. * Add JSF info message.
  245. * @param msg info message string
  246. */
  247. public static void addFacesInformationMessage(String msg) {
  248. FacesContext ctx = getFacesContext();
  249. FacesMessage fm =
  250. new FacesMessage(FacesMessage.SEVERITY_INFO, msg, "");
  251. ctx.addMessage(getRootViewComponentId(), fm);
  252. }
  253.  
  254. /**
  255. * Add JSF error message.
  256. * @param msg error message string
  257. */
  258. public static void addFacesErrorMessage(String msg) {
  259. FacesContext ctx = getFacesContext();
  260. FacesMessage fm =
  261. new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, "");
  262. ctx.addMessage(getRootViewComponentId(), fm);
  263. }
  264.  
  265. /**
  266. * Add JSF error message for a specific attribute.
  267. * @param attrName name of attribute
  268. * @param msg error message string
  269. */
  270. public static void addFacesErrorMessage(String attrName, String msg) {
  271. FacesContext ctx = getFacesContext();
  272. FacesMessage fm =
  273. new FacesMessage(FacesMessage.SEVERITY_ERROR, attrName, msg);
  274. ctx.addMessage(getRootViewComponentId(), fm);
  275. }
  276.  
  277. // Informational getters
  278.  
  279. /**
  280. * Get view id of the view root.
  281. * @return view id of the view root
  282. */
  283. public static String getRootViewId() {
  284. return getFacesContext().getViewRoot().getViewId();
  285. }
  286.  
  287. /**
  288. * Get component id of the view root.
  289. * @return component id of the view root
  290. */
  291. public static String getRootViewComponentId() {
  292. return getFacesContext().getViewRoot().getId();
  293. }
  294.  
  295. /**
  296. * Get FacesContext.
  297. * @return FacesContext
  298. */
  299. public static FacesContext getFacesContext() {
  300. return FacesContext.getCurrentInstance();
  301. }
  302. /*
  303. * Internal method to pull out the correct local
  304. * message bundle
  305. */
  306.  
  307. private static ResourceBundle getBundle() {
  308. FacesContext ctx = getFacesContext();
  309. UIViewRoot uiRoot = ctx.getViewRoot();
  310. Locale locale = uiRoot.getLocale();
  311. ClassLoader ldr = Thread.currentThread().getContextClassLoader();
  312. return ResourceBundle.getBundle(ctx.getApplication().getMessageBundle(),
  313. locale, ldr);
  314. }
  315.  
  316. /**
  317. * Get an HTTP Request attribute.
  318. * @param name attribute name
  319. * @return attribute value
  320. */
  321. public static Object getRequestAttribute(String name) {
  322. return getFacesContext().getExternalContext().getRequestMap().get(name);
  323. }
  324.  
  325. /**
  326. * Set an HTTP Request attribute.
  327. * @param name attribute name
  328. * @param value attribute value
  329. */
  330. public static void setRequestAttribute(String name, Object value) {
  331. getFacesContext().getExternalContext().getRequestMap().put(name,
  332. value);
  333. }
  334.  
  335. /*
  336. * Internal method to proxy for resource keys that don't exist
  337. */
  338.  
  339. private static String getStringSafely(ResourceBundle bundle, String key,
  340. String defaultValue) {
  341. String resource = null;
  342. try {
  343. resource = bundle.getString(key);
  344. } catch (MissingResourceException mrex) {
  345. if (defaultValue != null) {
  346. resource = defaultValue;
  347. } else {
  348. resource = NO_RESOURCE_FOUND + key;
  349. }
  350. }
  351. return resource;
  352. }
  353.  
  354. /**
  355. * Locate an UIComponent in view root with its component id. Use a recursive way to achieve this.
  356. * @param id UIComponent id
  357. * @return UIComponent object
  358. */
  359. public static UIComponent findComponentInRoot(String id) {
  360. UIComponent component = null;
  361. FacesContext facesContext = FacesContext.getCurrentInstance();
  362. if (facesContext != null) {
  363. UIComponent root = facesContext.getViewRoot();
  364. component = findComponent(root, id);
  365. }
  366. return component;
  367. }
  368.  
  369. /**
  370. * Locate an UIComponent from its root component.
  371. * Taken from http://www.jroller.com/page/mert?entry=how_to_find_a_uicomponent
  372. * @param base root Component (parent)
  373. * @param id UIComponent id
  374. * @return UIComponent object
  375. */
  376. public static UIComponent findComponent(UIComponent base, String id) {
  377. if (id.equals(base.getId()))
  378. return base;
  379.  
  380. UIComponent children = null;
  381. UIComponent result = null;
  382. Iterator childrens = base.getFacetsAndChildren();
  383. while (childrens.hasNext() && (result == null)) {
  384. children = (UIComponent)childrens.next();
  385. if (id.equals(children.getId())) {
  386. result = children;
  387. break;
  388. }
  389. result = findComponent(children, id);
  390. if (result != null) {
  391. break;
  392. }
  393. }
  394. return result;
  395. }
  396.  
  397. /**
  398. * Method to create a redirect URL. The assumption is that the JSF servlet mapping is
  399. * "faces", which is the default
  400. *
  401. * @param view the JSP or JSPX page to redirect to
  402. * @return a URL to redirect to
  403. */
  404. public static String getPageURL(String view) {
  405. FacesContext facesContext = getFacesContext();
  406. ExternalContext externalContext = facesContext.getExternalContext();
  407. String url =
  408. ((HttpServletRequest)externalContext.getRequest()).getRequestURL().toString();
  409. StringBuffer newUrlBuffer = new StringBuffer();
  410. newUrlBuffer.append(url.substring(0, url.lastIndexOf("faces/")));
  411. newUrlBuffer.append("faces");
  412. String targetPageUrl = view.startsWith("/") ? view : "/" + view;
  413. newUrlBuffer.append(targetPageUrl);
  414. return newUrlBuffer.toString();
  415. }
  416.  
  417. public static boolean isPostBack(){
  418. return JSFUtils.resolveExpressionAsBoolean("#{adfFacesContext.postback}");
  419. }
  420.  
  421. }

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"/>

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

adf笔记的更多相关文章

  1. adf 笔记

    1>jsf在bean中如何获取url参数,注意bean的范围,如果存在分页,范围不能设置为request,否则第二次加载的时候参数会为空. 最小设置为view,在当前页面中一直有效. 方法一:F ...

  2. Android学习笔记(二)——探究一个活动

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 活动(Activity)是最容易吸引到用户的地方了,它是一种可以包含用户界面的组件,主要用于和用户进行交互.一 ...

  3. ArcGIS API for Silverlight学习笔记

    ArcGIS API for Silverlight学习笔记(一):为什么要用Silverlight API(转) 你用上3G手机了吗?你可能会说,我就是喜欢用nokia1100,ABCDEFG跟我都 ...

  4. 23 DesignPatterns学习笔记:C++语言实现 --- 1.1 Factory

    23 DesignPatterns学习笔记:C++语言实现 --- 1.1 Factory 2016-07-18 13:03:43 模式理解

  5. 《时间序列分析——基于R》王燕,读书笔记

    笔记: 一.检验: 1.平稳性检验: 图检验方法:     时序图检验:该序列有明显的趋势性或周期性,则不是平稳序列     自相关图检验:(acf函数)平稳序列具有短期相关性,即随着延迟期数k的增加 ...

  6. git-简单流程(学习笔记)

    这是阅读廖雪峰的官方网站的笔记,用于自己以后回看 1.进入项目文件夹 初始化一个Git仓库,使用git init命令. 添加文件到Git仓库,分两步: 第一步,使用命令git add <file ...

  7. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  8. SQL Server技术内幕笔记合集

    SQL Server技术内幕笔记合集 发这一篇文章主要是方便大家找到我的笔记入口,方便大家o(∩_∩)o Microsoft SQL Server 6.5 技术内幕 笔记http://www.cnbl ...

  9. PHP-自定义模板-学习笔记

    1.  开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2.  整体架构图 ...

随机推荐

  1. 1.Python3关于文件的操作

    1.写了一个简单的Demo,就是向txt文本写入内容,最初代码如下: file = open("D:/Users/nancy/python.txt","wb") ...

  2. 使用Octave分析GNU Radio的数据

    Octave 是 GNU Radio 的最流行的分析工具,因此 GNU Radio 软件包也包含它自身的一组脚本用于读取和语法分析输出.本文介绍如何使用 Octave 分析 GNU Radio 产生的 ...

  3. JVM内存管理之GC算法精解(复制算法与标记/整理算法)

    本次LZ和各位分享GC最后两种算法,复制算法以及标记/整理算法.上一章在讲解标记/清除算法时已经提到过,这两种算法都是在此基础上演化而来的,究竟这两种算法优化了之前标记/清除算法的哪些问题呢? 复制算 ...

  4. 如何安装nginx第三方模块

    nginx文件非常小但是性能非常的高效,这方面完胜apache,nginx文件小的一个原因之一是nginx自带的功能相对较少,好在nginx允许第三方模块,第三方模块使得nginx越发的强大. 在安装 ...

  5. 关于INTEL FPGA设计工具DSP Builder

    一段时间以来,MathWorks一直主张使用Matlab和Simulink开发工具进行基于模型的设计,因为好的设计技术使您能够在更短的时间内开发更高质量的复杂软件.基于模块的设计采用了数学和可视化的方 ...

  6. NAT功能测试

    一.测试目标和功能: 1.内网设备可以访问外网的IP: 2.外网PC可以登录内网设备的telnet. 二.设备硬件结构 1.3135相当于交换机: 2.eth0.netra和业务网口通过内部端口连接3 ...

  7. Android多线程断点下载的代码流程解析

    Step 1:创建一个用来记录线程下载信息的表 创建数据库表,于是乎我们创建一个数据库的管理器类,继承SQLiteOpenHelper类 重写onCreate()与onUpgrade()方法 DBOp ...

  8. Oracle查询结果中的日期格式显示到毫秒数,如何去掉多余的数

    @Temporal(TemporalType.TIMESTAMP) @Column(name="createTime",nullable=false) private Date c ...

  9. Angular2快速入门-5.使用http(新闻数据来自http请求)

    Angular2官网通过http请求模拟API 来请求hero 数据,感觉有点繁琐,很让人理解不了,我们不采用它的办法,直接展示怎么使用http请求来获取我们的数据 ,直截了当. 第一.准备工作,创建 ...

  10. 函数~匿名方法~lambda的逐渐过渡思想

    前提:基于委托实现 (1)使用函数名称 delegate void Printer(string s);//(1)申明委托 static void Main(string[] args) { //(3 ...