Questions of Test: JSF Interview questions 2

1

Given property files  
1) messages.properties   
2) messages_de.properties 
 
in WEB-INF/classes folder, and with following definition in faces-config.xml file: 
 
<application> 
<locale-config> 
  <default-locale>en</default-locale> 
  <supported-locale>de</supported-locale> 
</locale-config> 
</application> 
 
 
given a jsp file: 
 
<f:view> 
     <f:loadBundle basename="messages" var="msgs"/> 
    <h:form id="helloForm"> 
     Key1:<h:outputText value="#{msgs.key1}" /> 
     </h:form> 
   </f:view> 
 
What change will you do in 'jsp' file to load the 'messages_de.properties' file as message bundle?

2

Give following:
 
a messageBean:
public MessageBean{
  String message;
  public MessageBean(){
   message = "This is Sample Message from bean";
  }
 
  public String getMessage(){ return message;}
  public void setMessage(String message){ this.message = message; }
}
 
bean definition in faces-config.xml:
 
<managed-bean>
    <managed-bean-name>msg</managed-bean-name>
    <managed-bean-class>MessageBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
   </managed-bean>
</faces-config>
 
and properties file messages.properties in WEB-INF/classes folder with following text:
message = message from message bundle and
 
and a test.jsp page:
<f:view>
    <f:loadBundle basename="messages" var="msg"/>
    <h:form>
      <h:outputText value="#{msg.messgae}" />
     </h:form>
   </f:view>
what will be the result when run test.jsf?

3

Given samplebean property table:
 
class SampleBean{
  HashMap<String,String> table;
  public HashMap<String,String> getTable() { return table;}
}
 
bean definition:
 
<managed-bean>
    <managed-bean-name>sampleBean</managed-bean-name>
    <managed-bean-class>SampleBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
  
    <managed-property>
    <property-name>table</property-name>
    <property-class>java.util.Map</property-class>
    <map-entries>
  <map-entry>
   <key>1</key>
   <value>First Value</value>
  </map-entry>
  <map-entry>
   <key>two</key>
   <value>Second Value</value>
  </map-entry>
</map-entries>
     </managed-property>
  </managed-bean>
 
which is the right way to access HashMap's data?

4

Given request scoped bean:
 
public class RequestBean {
      
   
      private String name;
      private String address;
 
      RequestBean(){
           name = null;
           address = null;
         }
 
         public String getName(){
               return name;
         }
}
 
Test.jsp:
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<f:view>
<h:outputText value="Welcome  #{requestBean.name}  #{requestBean.address}"></h:outputText>
</f:view>
 
Which of the following is true when we access url http://localhot/testApp/Test.faces?

5

About javax.faces.STATE_SAVING_METHOD Context parameter which of the following statements are true

6

Which of the following code are correct to access session scoped attribute cisId?

7

Which of the following statements displays 5 as result when run in a jsf page

8

Given a Java.util.List of Strings shoppingItems in a bean shoppingCart 
Which is the right way to display the List items in tabular data in JSF

9

<h:outputFormat value="Thanks. You have purchased {0} items. You will get discount for {1} items.">  
  <f:param value="10"/>  
</h:outputFormat>  
 
What is the output of the above code?

10

Given personBean containing day property of type java.util.Date which is not null , given personBean configured as reques scoped  managed bean,  
what would be the result of the following when run in a jsp page 
 
<h:outputText value="#{personBean.day}">  
<f:convertDateTime type="date" dateStyle="dd/mm/yyyy" />  
</h:outputText>