jsf-2

Backing bean in composite component is recreated on every request

☆樱花仙子☆ 提交于 2019-12-18 03:45:45
问题 I have two variables "userId" and "name". When I click for example the "SHOW USERID" button it works fine and sets "renderUserId=true" and it shows it with the "render", but then if I click the other "SHOW" button, the Bean is reconstruct and I loose the "renderUserId=true" and it becomes "false" and "renderName=true" so it shows ok, but the USERID is hidden. My question is, how can I avoid loosing the bean values when I render the xhtml? This is a simple simulation of my code. NOTE: if I use

Interceptor in JSF

淺唱寂寞╮ 提交于 2019-12-18 03:39:12
问题 I want to know if there is an interceptor in JSF (like we use in Spring), and how to do we implement it? 回答1: You could implement a PhaseListener for this. You could program them to listen on a specific JSF phase which you specify in the overridden getPhaseId() method. You can intercept on the before and after phase events by beforePhase() and afterPhase() methods. The below example listens on the render response phase: public class RequestInterceptor implements PhaseListener { @Override

How to handle multiple submits before response is rendered?

此生再无相见时 提交于 2019-12-18 03:37:17
问题 It has been reported from testing that it is occasionally possible to press a button more than once if the response is not rendered fast enough, causing several invocations of the back-end code, which we do not want. Application is Java EE 6 Web Profile using JSF 2.0 inside Glassfish 3.1.1. I was wondering how this should be properly dealt with, and have thought of a few scenarios: Submitting should disable all buttons using javascript while response is being rendered. A flag in the Session

How to set JSF2 <welcome-file> with faces servlet mapping?

落花浮王杯 提交于 2019-12-18 03:11:29
问题 I have a simple JSF2 app using Facelets. My web.xml is set as follows:- <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> I want to set the app to default to the welcome page which is /pages/login.xhtml. I can't seem to get the welcome-file setting to pick up this when going to the context root in the browser. My web.xml welcome setting is as follows:- <welcome-file-list> <welcome-file>/pages/login.jsf</welcome-file> </welcome

How to set JSF2 <welcome-file> with faces servlet mapping?

不问归期 提交于 2019-12-18 03:11:05
问题 I have a simple JSF2 app using Facelets. My web.xml is set as follows:- <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> I want to set the app to default to the welcome page which is /pages/login.xhtml. I can't seem to get the welcome-file setting to pick up this when going to the context root in the browser. My web.xml welcome setting is as follows:- <welcome-file-list> <welcome-file>/pages/login.jsf</welcome-file> </welcome

JSF dynamic include using Ajax request [duplicate]

為{幸葍}努か 提交于 2019-12-17 23:34:24
问题 This question already has answers here : How to ajax-refresh dynamic include content by navigation menu? (JSF SPA) (3 answers) Closed 4 years ago . In JSF2, is it possible to change the of value of src of ui:include dynamically using Ajax request (like for example PrimeFaces p:commandButton)? Thank you. <h:form> <h:commandLink value="Display 2" action="#{fTRNav.doNav()}"> <f:setPropertyActionListener target="#{fTRNav.pageName}" value="/disp2.xhtml" /> </h:commandLink> </h:form> <ui:include

Programmatically getting UIComponents of a JSF view in bean's constructor

烈酒焚心 提交于 2019-12-17 22:54:23
问题 Imagine a JSF page with several components such as <h:selectOneMenu> , <h:dataTable> , <h:panelGrid> , etc. Each component has an ID. Is there any method or technique by which I can get the components programmatically when the constructor of the bean is invoked? 回答1: You can get the component tree by FacesContext#getViewRoot() and find a particular component by ID by UIComponentBase#findComponent(): UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); UIComponent component =

how to get beans from view scope

回眸只為那壹抹淺笑 提交于 2019-12-17 22:43:30
问题 I want to ask if i place my managed bean in session scope, then it is stored in session' Like if i have a bean like this @ManagedBean @SessionScoped public class SessionScopedBean implements Serializable { ....... } //end of class SessionScopedBean Then it stored in the session, and during my session i can get it using session.getAttribut("SessionScopedBean"); This will give me the SessionScopedBean Object, and when session will get destroy, i will get null. Now i want to ask if i have my

Primefaces outputLabel for composite component

泪湿孤枕 提交于 2019-12-17 22:42:53
问题 I have an issue with using p:outputLabel when used with composite component. I have composite component with p:inputText field (I removed irrelevant parts from component): <cc:interface> <cc:editableValueHolder name="myInput" targets="myInput"/> <cc:attribute name="required" required="true" type="java.lang.Boolean" default="false"/> </cc:interface> <cc:implementation> <p:inputText id="myInput" required="#{cc.attrs.required}"/> </cc:implementation> Now, I wont to use this component with p

Why aren't multiple Converters allowed on a single value holder?

半腔热情 提交于 2019-12-17 22:00:55
问题 This morning I had reason to try using multiple Converters on an inputText component and realized that this doesn't work. Does anyone who why JSF only allows a single Converter per ValueHolder? It seems that using a series of Converters would be elegant in several situations. 回答1: In JSF, the Converter interface is designed with the following sole purpose: Converter is an interface describing a Java class that can perform Object-to-String and String-to-Object conversions between model data