EzDevInfo.com

jsf interview questions

Top jsf frequently asked interview questions

JSTL in JSF2 Facelets... makes sense?

I would like to output a bit of Facelets code conditionally.

For that purpose, the JSTL tags seem to work fine:

<c:if test="${lpc.verbose}">
    ...
</c:if>

However, I'm not sure if this is a best practice? Is there another way to achieve my goal?


Source: (StackOverflow)

ViewParam vs @ManagedProperty(value = "#{param.id}")

What is the difference between defining View Params like this:

<f:metadata>
  <f:viewParam name="id" value="#{someBean.id}"/>
</f:metadata>

And defining the property in the ManagedBean like this:

@ManagedProperty(value = "#{param.id}")
private Integer id;

Source: (StackOverflow)

Advertisements

Java EE 6 vs. Spring 3 stack [closed]

I'm starting a new project now. I have to choose technologies. I need something light, so no EJB or Seam. On the other hand I need JPA (Hibernate or alternative) and JSF with IceFaces.

Do you think that such a stack on Spring 3 deployed on Tomcat is a good choice? Or a Java EE 6 web application could be better? I'm afraid that Java EE 6 is a new technology, not well documented yet. Tomcat seems to be easier to maintain than Glassfish 3.

What's your opinion? Do you have any experiences?


Source: (StackOverflow)

How to include another XHTML in XHTML using JSF 2.0 Facelets?

What is the most correct way to include another XHTML page in an XHTML page? I have been trying different ways, none of them are working.


Source: (StackOverflow)

Performing user authentication in Java EE / JSF using j_security_check

I'm wondering what the current approach is regarding user authentication for a web application making use of JSF 2.0 (and if any components do exist) and Java EE 6 core mechanisms (login/check permissions/logouts) with user information hold in a JPA entity. The Oracle Java EE tutorial is a bit sparse on this (only handles servlets).

This is without making use of a whole other framework, like Spring-Security (acegi), or Seam, but trying to stick hopefully with the new Java EE 6 platform (web profile) if possible.


Source: (StackOverflow)

JSF vs Facelets vs JSP [duplicate]

This question already has an answer here:

I can't seem to get a clear answer as to the concrete difference between Java Server Faces vs. so-called facelets. Can anyone give me a clear-as-day answer?!?

Also, I understand that either JSF or JSP can be used to create dynamic web pages, but two seemingly-conflicting details are confusing me. I've heard both of the following:

  1. That JSF is a replacement for JSP; and

  2. JSF and JSP form different parts of the View in Java's web-tier MVC paradigm

So which is it? Logic dictates it almost certainly can't be both!


Source: (StackOverflow)

Why JSF saves the state of UI components on server?

  1. Until what point in time does JSF save the state of UI components on the server side & when exactly is the UI component's state information removed from the server memory? As a logged-in user on the application navigates though pages, will the state of components keep on accumulating on the server?

  2. I don't understand what is the benefit of keeping UI components state on server !? Isn't directly passing the validated/converted data to managed beans enough? Can I or should I try to avoid it?

  3. Doesn't that consume too much memory on the server side, if there are thousands of concurrent user sessions? I have an application where users can post blogs on certain topics. This blogs are quite large in size. When there will be post back or request for viewing the blogs, will this big page data be saved as a part of the state of components? This would eat up too much memory. Isn't this a concern ?


Update 1:

Now, it is no longer necessary to save state while using JSF. A high performance Stateless JSF implementation is available for use. See this blog & this question for relevant details & discussion. Also, there is an open issue to include in JSF specs, an option to provide stateless mode for JSF. (P.S. Consider voting for the issues this & this if this is a useful feature for you.)


Update 2 (24-02-2013):

A great news that Mojarra 2.1.19 is out with stateless mode!

See here:

http://weblogs.java.net/blog/mriem/archive/2013/02/08/jsf-going-stateless?force=255

http://java.net/jira/browse/JAVASERVERFACES-2731

http://balusc.blogspot.de/2013/02/stateless-jsf.html


Source: (StackOverflow)

How can I pass selected row to commandLink inside dataTable?

I'm using Primefaces in a JSF 2 application. I have a <p:dataTable>, and instead of selecting rows, I want the user to be able to directly execute various actions on individual rows. For that, I have several <p:commandLink>s in the last column.

My problem: how can I pass a row ID to the action started by the command link so that I know which row to act on? I tried using an <f:attribute>:

<p:dataTable value="#{bean.items}" var="item">
    ...
    <p:column>
        <p:commandLink actionListener="#{bean.insert}" value="insert">
            <f:attribute name="id" value="#{item.id}" />
        </p:commandLink>
    </p:column>
</p:dataTable>

But it always yields 0 - apparently the row variable f is not available when the attribute is rendered (it works when I use a fixed value).

Anyone has an alternative solution?


Source: (StackOverflow)

Setting property 'source' to 'org.eclipse.jst.jee.server:JSFTut' did not find a matching property

I am getting following error, when I run the demo JSF application on the console

[SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:JSFTut' did not find a matching property.

Source: (StackOverflow)

Get JSF managed bean by name in any Servlet related class

I'm trying to write a custom servlet (for AJAX/JSON) in which I would like to reference my @ManagedBeans by name. I'm hoping to map:

http://host/app/myBean/myProperty

to:

@ManagedBean(name="myBean")
public class MyBean {
    public String getMyProperty();
}

Is it possible to load a bean by name from a regular servlet? Is there a JSF servlet or helper I could use for it?

I seem to be spoilt by Spring in which all this is too obvious.


Source: (StackOverflow)

What is the need of JSF. When UI can be achieved from css html javascript jQuery?

I was reading about JSF that its a UI framework and provides some UI components. But how is it better or different from number of components that can are available from extjs or jQuery or combination of css and html and js. Why should someone learn JSF.


Source: (StackOverflow)

commandLink/commandButton/ajax backing bean action/listener method not invoked

I found a problem when using the <h:commandLink> or <h:commandButton> in an include page: the action and actionListener associated with the UICommand component are simply not being invoked. What are the possible causes and solutions for this?


Source: (StackOverflow)

How to choose the right bean scope?

I noticed that there are different bean scopes like:

@RequestScoped
@ViewScoped
@FlowScoped
@SessionScoped
@ApplicationScoped

What is the purpose of each? How do I choose a proper scope for my bean?


Source: (StackOverflow)

What can , and be used for?

Can anyone clarify how we can use in general, or a in real world example, this snippet?

<f:metadata>
    <f:viewParam id="id" value="#{bean.id}" />
    <f:viewAction action="#{bean.init}" />
</f:metadata>

Source: (StackOverflow)

javax.faces.application.ViewExpiredException: View could not be restored

I have written simple application with container-managed security. The problem is when I log in and open another page on which I logout, then I come back to first page and I click on any link etc or refresh page I get this exception. I guess it's normal (or maybe not:)) because I logged out and session is destroyed. What should I do to redirect user to for example index.xhtml or login.xhtml and save him from seeing that error page/message?

In other words how can I automatically redirect other pages to index/login page after I log out?

Here it is:

javax.faces.application.ViewExpiredException: viewId:/index.xhtml - View /index.xhtml could not be restored.
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:212)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
    at filter.HttpHttpsFilter.doFilter(HttpHttpsFilter.java:66)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
    at java.lang.Thread.run(Thread.java:619)

Source: (StackOverflow)