当前位置: 首页 > news >正文

网站制作图书邢台做wap网站找谁

网站制作图书,邢台做wap网站找谁,旅游电子商务平台有哪些,aso优化技术这篇文章的目的是总结一些JSF开发人员可以在日常工作中使用的便捷方法。 实用程序类是将所有方法放在一起的好地方。 我会称此类为FacesAccessor。 第一种方法可能是最常用的方法。 它以给定名称返回托管bean。 必须按faces-config.xml或注释注册该bean。 注入是好的#xff0… 这篇文章的目的是总结一些JSF开发人员可以在日常工作中使用的便捷方法。 实用程序类是将所有方法放在一起的好地方。 我会称此类为FacesAccessor。 第一种方法可能是最常用的方法。 它以给定名称返回托管bean。 必须按faces-config.xml或注释注册该bean。 注入是好的但是有时如果很少调用bean则不必将bean相互注入。 public static Object getManagedBean(final String beanName) {FacesContext fc FacesContext.getCurrentInstance();Object bean;try {ELContext elContext fc.getELContext();bean elContext.getELResolver().getValue(elContext, null, beanName);} catch (RuntimeException e) {throw new FacesException(e.getMessage(), e);}if (bean null) {throw new FacesException(Managed bean with name beanName was not found. Check your faces-config.xml or ManagedBean annotation.);}return bean; } 使用 ManagedBean public class PersonBean {... }PersonBean personBean (PersonBean)FacesAccessor.getManagedBean(personBean);// do something with personBean 第二种方法对JSF组件开发人员以及所有想要评估给定值表达式{…}并将结果设置为给定值的人都非常有用。 public static void setValue2ValueExpression(final Object value, final String expression) {FacesContext facesContext FacesContext.getCurrentInstance();ELContext elContext facesContext.getELContext();ValueExpression targetExpression facesContext.getApplication().getExpressionFactory().createValueExpression(elContext, expression, Object.class);targetExpression.setValue(elContext, value); } 使用 我个人将这种方法用于“注销功能”。 用户注销后他/她将看到一个特殊的“注销页面”。 “注销页面”使用来自sesion作用域bean的用户设置例如主题语言等。 但是由于会话无效因此该会话作用域bean不再存在。 该怎么办 这是我的注销方法中的代码片段。 UserSettings userSettings (UserSettings) FacesAccessor.getManagedBean(userSettings);// invalidate session ExternalContext ec FacesContext.getCurrentInstance().getExternalContext(); HttpSession session (HttpSession) ec.getSession(false); session.invalidate();// create new session ((HttpServletRequest) ec.getRequest()).getSession(true);// restore last used user settings because login / logout pages reference userSettings FacesAccessor.setValue2ValueExpression(userSettings, #{userSettings});// redirect to the specified logout page ec.redirect(ec.getRequestContextPath() /views/logout.jsf); 第三种方法将变量映射到给定的值表达式{…}。 它使用javax.el.VariableMapper将表达式分配给指定的变量以便对该变量的任何引用都将被EL评估中的表达式替换。 public static void mapVariable2ValueExpression(final String variable, final String expression) {FacesContext facesContext FacesContext.getCurrentInstance();ELContext elContext facesContext.getELContext();ValueExpression targetExpression facesContext.getApplication().getExpressionFactory().createValueExpression(elContext, expression, Object.class);elContext.getVariableMapper().setVariable(variable, targetExpression); } 使用 假设“ PersonBean”是一个具有“ name”属性的托管Bean“ PersonsBean”是一个包含“ PersonBean”的许多实例作为数组集合或映射的Bean。 以下代码允许将“ personBean”用作对具有“ name” Oleg的特定bean的引用。 FacesAccessor.mapVariable2ValueExpression(personBean, #{personsBean.person[Oleg]}); 在facelets页面中这样说一下personDetail.xhtml我们可以编写 html xmlnshttp://www.w3.org/1999/xhtmlxmlns:uihttp://java.sun.com/jsf/faceletsxmlns:hhttp://java.sun.com/jsf/html ui:composition...h:inputText value#{personBean.name}/... /ui:composition /html 注意参考“ personBean”是在Java中设置的。 还可以通过uiinclude / uiparam以声明的方式在facelet中使用此映射。 html xmlnshttp://www.w3.org/1999/xhtmlxmlns:uihttp://java.sun.com/jsf/facelets ui:composition...ui:include srcpersonDetail.xhtmlui:param namepersonBean value#{personsBean.person[Oleg]}//ui:include... /ui:composition /html 接下来的两个方法用于以编程方式创建MethodExpression / MethodExpressionActionListener。 如果您通过“ binding”属性使用组件绑定或在Java中创建一些模型类则它们非常方便。 public static MethodExpression createMethodExpression(String valueExpression,Class? expectedReturnType,Class?[] expectedParamTypes) {MethodExpression methodExpression null;try {FacesContext fc FacesContext.getCurrentInstance();ExpressionFactory factory fc.getApplication().getExpressionFactory();methodExpression factory.createMethodExpression(fc.getELContext(), valueExpression, expectedReturnType, expectedParamTypes);} catch (Exception e) {throw new FacesException(Method expression valueExpression could not be created.);}return methodExpression; }public static MethodExpressionActionListener createMethodActionListener(String valueExpression,Class? expectedReturnType,Class?[] expectedParamTypes) {MethodExpressionActionListener actionListener null;try {actionListener new MethodExpressionActionListener(createMethodExpression(valueExpression, expectedReturnType, expectedParamTypes));} catch (Exception e) {throw new FacesException(Method expression for ActionListener valueExpression could not be created.);}return actionListener; } 使用 在我的一个项目中我以编程方式创建了带有菜单项的PrimeFaces MenuModel。 MenuItem mi new MenuItem(); mi.setAjax(true); mi.setValue(...); mi.setProcess(...); mi.setUpdate(...); mi.setActionExpression(FacesAccessor.createMethodExpression(#{navigationContext.setBreadcrumbSelection}, String.class, new Class[] {}));UIParameter param new UIParameter(); param.setId(...); param.setName(...); param.setValue(...); mi.getChildren().add(param); 您想在这里分享什么好方法吗 欢迎使用提示/技巧。 参考 5种有用的方法JSF开发人员应该从我们的JCG合作伙伴 Oleg Varaksin的“软件开发思想”博客中了解到。 翻译自: https://www.javacodegeeks.com/2012/04/5-useful-methods-jsf-developers-should.html
http://www.zqtcl.cn/news/810173/

相关文章:

  • 用织梦做的网站是模板的吗外贸展示型模板网站
  • 网站seo的关键词排名怎么做的定制和订制
  • 自适应网站做多大尺寸的四川建设厅电话网站
  • 易语言可以做网站了吗电商平台排名100强
  • 网站代码开发方式影视公司网页设计
  • 如何选择网站定制公司响水专业做网站
  • 海门建网站公司凡客模板wordpress
  • 网站关键字排名php开源cms
  • 手机商城手机网站建设多少钱明水县网站建设
  • 北京网站优化外包做板材外贸一般用哪个网站
  • 北京建设网站有哪些公司药店网站模板
  • 网站欢迎页面怎么做个人简历免费模板下载
  • 宁波外贸网站建设竣工验收报告查询网
  • 内衣网站建设详细方案如何制作企业网站的版式
  • 网站建设是否需要源代码php如何制作网站
  • 自响应式网站是什么意思现货交易平台合法的有几家
  • 网站如何做视频链接地址一个虚拟主机空间挂两个网站
  • seo外贸网站建设常州本地网站
  • 可以做机械设计接单的网站pc网站怎么做自适应
  • 网站建设义乌电子商务做网站实训体会
  • 哪些网站做国际贸易比较好徐州泉山建设局网站
  • 平果县免费网站哪家好新媒体营销
  • 网站制作的页面比例企业为什么建立企业网站
  • 网站开发技术的发展专业的seo网站优化公司
  • 十大ppt模板免费下载网站惠州网络营销
  • 网站建设自优化网站首页
  • 网络营销推广方式包括哪几种湘潭网站seo磐石网络
  • 英文WordPress站点切换为中文优化神马网站关键词排名价格
  • 宁波网站建设免费咨询网站建设服务费怎么做会计分录
  • 工作期间员工花钱做的网站wordpress文章内容乱码