jsf

How to create, access and destroy session in JSF managed bean?

一个人想着一个人 提交于 2020-03-20 06:30:39
问题 Currently, I am creating a web application for an online shopping cart and I need to maintain session on each jsf page.. My questions are : How can I create and destroy session in managed bean How can I access value stored in session variable? Like this? FacesContext.getCurrentInstance().getExternalContext().getSessionMap.put("key",object); How can I destroy a session in jsf I also need to destroy the session using session.invalidate() but i am failed !! 回答1: How can I create and destroy

How to create, access and destroy session in JSF managed bean?

孤街醉人 提交于 2020-03-20 06:30:07
问题 Currently, I am creating a web application for an online shopping cart and I need to maintain session on each jsf page.. My questions are : How can I create and destroy session in managed bean How can I access value stored in session variable? Like this? FacesContext.getCurrentInstance().getExternalContext().getSessionMap.put("key",object); How can I destroy a session in jsf I also need to destroy the session using session.invalidate() but i am failed !! 回答1: How can I create and destroy

JSF---->标准转换器(Converter)

亡梦爱人 提交于 2020-03-18 21:58:13
转换器(Converter)协助模型与视图之间的数据转换 标准转换器 Web应用程序与浏览器之间是使用HTTP进行沟通,所有传送的数据基本上都是字符串文字,而Java应用程序本身基本上则是对象,所以对象数据必须经由转换传送给浏览器,而浏览器送来的数据也必须转换为对象才能使用。 JSF定义了一系列标准的转换器(Converter),对于基本数据型态(primitive type)或是其Wrapper类别,JSF会使用javax.faces.Boolean、javax.faces.Byte、 javax.faces.Character、javax.faces.Double、javax.faces.Float、 javax.faces.Integer、javax.faces.Long、javax.faces.Short等自动进行转换,对于 BigDecimal、BigInteger,则会使用javax.faces.BigDecimal、javax.faces.BigInteger自动进行转换。 至于DateTime、Number,我们可以使用 <f:convertDateTime>、<f:convertNumber>标签 进行转换,它们各自提供有一些简单的属性,可以让我们在转换时指定一些转换的格式细节。 来看个简单的例子,首先我们定义一个简单的Bean: UserBean.java

How to get the URL of current page in JSF?

妖精的绣舞 提交于 2020-03-13 07:15:19
问题 Is there any way to get the URL of the page which is loaded? I would like the URL of the page which is loaded, in my controller i will call a method getUrlOfPage() in init() method . I need the URL source to use it as a input for exporting the context in it. How to get the URL of the page? 回答1: It's available by HttpServletRequest#getRequestURL() (with domain) or getRequestURI() (without domain). The HttpServletRequest itself is in turn available by ExternalContext#getRequest(). Thus, so:

SpringEL表达式(一)-入门案例

自闭症网瘾萝莉.ら 提交于 2020-03-10 07:45:17
原文链接: http://www.yiidian.com/spring/spring-el-helloworld.html 在Spring3中就已经支持EL表达式了, Spring Expression Language(SpEL)是类似于OGNL和JSF EL的表达式语言, 能够在运行时构建复杂表达式, 存取对象属性、调用对象方法等, 而且所有的SpEL都支持XML和Annotation两种方式, 使用的格式均为:#{SpEL expression}。 下面的例子,这个例子将展示如何利用SpEL注入String、Bean到属性中。 一、编写Bean类 Customer.java package com.yiidian.domain; import java.io.Serializable; /** * * @author http://www.yiidian.com * */ public class Customer implements Serializable{ private String name; private String telephone; public String getName() { return name; } public void setName(String name) { this.name = name; } public String

JSF---->标准转换器(Converter)

故事扮演 提交于 2020-03-08 08:20:17
转换器(Converter)协助模型与视图之间的数据转换 标准转换器 Web应用程序与浏览器之间是使用HTTP进行沟通,所有传送的数据基本上都是字符串文字,而Java应用程序本身基本上则是对象,所以对象数据必须经由转换传送给浏览器,而浏览器送来的数据也必须转换为对象才能使用。 JSF定义了一系列标准的转换器(Converter),对于基本数据型态(primitive type)或是其Wrapper类别,JSF会使用javax.faces.Boolean、javax.faces.Byte、 javax.faces.Character、javax.faces.Double、javax.faces.Float、 javax.faces.Integer、javax.faces.Long、javax.faces.Short等自动进行转换,对于 BigDecimal、BigInteger,则会使用javax.faces.BigDecimal、javax.faces.BigInteger自动进行转换。 至于DateTime、Number,我们可以使用 <f:convertDateTime>、<f:convertNumber>标签 进行转换,它们各自提供有一些简单的属性,可以让我们在转换时指定一些转换的格式细节。 来看个简单的例子,首先我们定义一个简单的Bean: UserBean.java

未调用commandButton / commandLink / ajax操作/侦听器方法或未设置/更新输入值

你。 提交于 2020-03-07 20:03:00
有时,当使用 <h:commandLink> , <h:commandButton> 或 <f:ajax> ,与标签关联的 action , actionListener 或 listener 方法根本不会被调用。 或者,不使用提交的 UIInput 值更新Bean属性。 有哪些可能的原因和解决方案? #1楼 尽管我的回答并非100%适用,但是大多数搜索引擎都将其作为第一匹配,但我还是决定将其发布: 如果您使用的是 PrimeFaces (或类似的API) p:commandButton 或 p:commandLink ,则可能忘记了将 process="@this" 显式添加到命令组件中。 如《 PrimeFaces用户指南》第3.18节所述, process 和 update 的默认值均为 @form ,这与您可能从纯JSF f:ajax 或RichFaces中获得的默认值完全相反,它们是 execute="@this" 和 render="@none" 分别为 render="@none" 。 只是花了我很长一段时间才能找到答案。 (...而且我认为使用不同于JSF的默认值相当不明智!) #2楼 我自己陷入了这个问题,并找到了导致该问题的另一个原因。 如果在后备bean中没有用于* .xhtml中使用的属性的setter方法,那么就不会调用该操作。 #3楼 介绍 每当

How to use OmniFaces @Eager annotation with PrimeFaces?

泄露秘密 提交于 2020-03-04 07:08:50
问题 PrimeFaces and OmniFaces can be used together in a JSF project. My project is using PrimeFaces 6.1 and works fine. However simply declaring the Maven dependency for OmniFaces <dependency> <groupId>org.omnifaces</groupId> <artifactId>omnifaces</artifactId> <version>2.6.7</version> </dependency> doesn't cause the @Eager annotation an application scoped bean injected with @Named to have any effect. Afaik instructions for CombinedResourceHandler don't solve this problem because it's an injection

How to use OmniFaces @Eager annotation with PrimeFaces?

本小妞迷上赌 提交于 2020-03-04 07:08:19
问题 PrimeFaces and OmniFaces can be used together in a JSF project. My project is using PrimeFaces 6.1 and works fine. However simply declaring the Maven dependency for OmniFaces <dependency> <groupId>org.omnifaces</groupId> <artifactId>omnifaces</artifactId> <version>2.6.7</version> </dependency> doesn't cause the @Eager annotation an application scoped bean injected with @Named to have any effect. Afaik instructions for CombinedResourceHandler don't solve this problem because it's an injection

Validate field and throw exception in JSF, but attach error message to another field?

假装没事ソ 提交于 2020-03-03 05:56:25
问题 I have some fields on my page which I want cross-validated. But I don't want error from this validation to be displayed in <h:message> for this fields. If I add validator to any of the fields, and validator throws exception, error is displayed in <h:message> for this field. On the other hand I HAVE TO throw exception if I want to suppress page from submitting. Just displaying some error message is not enough. So I created some hidden field on the form, and attached validator there. This