Welcome to Java4u

A Single Place for all Java Resources

Looking for something?

Subscribe to this blog!

Receive the latest posts by email.

.Just enter your email below if you want to subscribe!

Email

Tuesday, August 31, 2010

Struts FAQs

Pre 1 2 3 4 
Q24.What are the important tags of struts-config.xml ?
 
<struts-config>
  <!-- ========== Form Bean Definitions ============ -->
<form-beans>
<form-bean name="login" type=" LoginForm" />
  </form-beans>
  <!-- ========== Global Forward Definitions ========= -->
  <global-forwards>
  </global-forwards>
  <!-- ========== Action Mapping Definitions ======== -->
  <action-mappings>
    <action
        path="/login"
        type="LoginAction" >
        </action>
  </action-mappings>
<!-- ========== Properties Definitions ============ -->
<message-resources parameter="MessageResources" />
<!-- ========== Validator framework Definitions ============ --> 
<plug-in className="org.apache.struts.validator.ValidatorPlugIn"> 
    <set-property 
           property="pathnames" 
            value="/org/apache/struts/validator/validator-rules.xml, 
        /WEB-INF/validation.xml"/> 
   </plug-in> 
</struts-config>
 
 
Q25. What are the core classes of the Struts Framework?

A: Core classes of Struts Framework are ActionForm, Action, ActionMapping, Action Forward, ActionServlet etc. 


Q26. What is action mappings?

         An action mapping is a configuration file entry that, in general, associates an action name with an action. An action mapping can contain a reference to a form bean that the action can use, and can additionally define a list of local forwards that is visible only to this action.

Q27. Describe validate() and reset() methods ?
 
          validate () and reset() methods defined inActionForm class.

validate() : Used to validate properties after they have been populated; Called before FormBean is handed to Action. Returns a collection of ActionMessage as ActionErrors. Following is the method signature for the validate() method.


public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)

reset(): reset() method is called by Struts Framework with each request that uses the defined ActionForm. The purpose of this method is to reset all of the ActionForm's data members prior to the new request values being set. 


public void reset() {}

   
Q28. Give the Details of XML files used in Validator Framework?

The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean. 

Q29. How you will enable front-end validation based on the xml in validation.xml?

The <html:javascript> tag to allow front-end validation based on the xml in validation.xml. For  example the code: <html:javascript formName="logonForm" dynamicJavascript="true" staticJavascript="true" /> generates the client side java script for the form "logonForm" as defined in the validation.xml file. The <html:javascript> when added in the jsp file generates the client site validation script.

Q30. What is the difference between perform() and execute() methods?

perform() method defined in Struts 1.0. but it is was deprecated in the Struts Version 1.1.  In Struts 1.x, Action.perform() is the method called by the ActionServlet. This is typically where your business logic resides, or at least the flow control to your JavaBeans and EJBs that handle your business logic. As we already mentioned, to support declarative exception handling, the method signature changed in perform. Now execute just throws Exception. Action.perform() is now deprecated; however, the Struts v1.1 ActionServlet is smart enough to know whether or not it should call perform or execute in the Action, depending on which one is available.

Q31. What are the various Struts tag libraries?

Struts is very rich framework and it provides very good and user friendly way to develop web application forms. Struts provide many tag libraries to ease the development of web applications. 
These tag libraries are:

* Bean tag library - Tags for accessing JavaBeans and their properties.


* HTML tag library - Tags to output standard HTML, including forms, text boxes, checkboxes, radio buttons etc..


* Logic tag library - Tags for generating conditional output, iteration capabilities and flow management


* Tiles or Template tag library - For the application using tiles


* Nested tag library - For using the nested beans in the application 


Q32. What are the difference between <bean:message> and <bean:write>?

<bean:message>: This tag is used to output locale-specific text (from the properties files) from a MessageResources bundle.

<bean:write>: This tag is used to output property values from a bean. <bean:write> is a commonly used tag which enables the programmers to easily present the data.
 

Q33. What are difference between ActionErrors and ActionMessage?

      ActionMessage: A class that encapsulates messages. Messages can be either global or they are specific to a particular bean property.

Each individual message is described by an ActionMessage object, which contains a message key (to be looked up in an appropriate message resources database), and up to four placeholder arguments used for parametric substitution in the resulting message.


         ActionErrors: A class that encapsulates the error messages being reported by the validate() method of an ActionForm. Validation errors are either global to the entire ActionForm bean they are associated with, or they are specific to a particular bean property (and, therefore, a particular input field on the corresponding form). 


Q34. What is the use of ForwardAction?

The ForwardAction class is useful when you’re trying to integrate Struts into an existing application that uses Servlets to perform business logic functions. You can use this class to take advantage of the Struts controller and its functionality, without having to rewrite the existing Servlets. Use ForwardAction to forward a request to another resource in your application, such as a Servlet that already does business logic processing or even another JSP page. By using this predefined action, you don’t have to write your own Action class. You just have to set up the struts-config file properly to use ForwardAction.

Q35. What is IncludeAction?

The IncludeAction class is useful when you want to integrate Struts into an application that uses Servlets. Use the IncludeAction class to include another resource in the response to the request being processed. 

Q36. What are the steps need to use DynaActionForm?

Using a DynaActionForm instead of a custom subclass of ActionForm is relatively straightforward. You need to make changes in two places:
In struts-config.xml: change your <form-bean> to be an org.apache.struts.action.Dyna ActionForm instead of some subclass of ActionForm

  • <form-bean name="loginForm"   type="org.apache.struts.action.DynaActionForm" >
        <form-property name="userName" type="java.lang.String"/>
        <form-property name="password" type="java.lang.String" />
    </form-bean> 

  • In your Action subclass that uses your form bean:
    • import org.apache.struts.action.DynaActionForm
    • downcast the ActionForm parameter in execute() to a DynaActionForm
    • access the form fields with get(field) rather than getField()
Q.37 In struts what happens if made any changes in actionservlet?

The ActionServlet plays the role of controller wich is responsible for handling the request and selecting the correct Application Module and storing ApplicationConfig and MessageResource bundle in the request object.

If we modify the ActionServlet the Controller may or may not work what happens that depends on your modification, You have not specify whether you want to create your own custom ActionServlet by extending ActionServlet and overriding the methods in it or what exactly you want to modify.


Pre 1 2 3 4 

0 comments: