YouTube Icon

Interview Questions.

Top 20 Apache Tapestry Interview Questions - Jul 25, 2022

fluid

Top 20 Apache Tapestry Interview Questions

Q1. What Is Apache Tapestry?

A component-based view framework.

Classes are written as POJOs and byte-code trformed at run time

Configured with annotations and naming conventions rather than XML

Compared to JSPs, enforces a clean separation of HTML markup and Java code.

HTML templates are without delay previewable by web designers

Changed factor instructions are live-reloaded into going for walks utility for faster improvement.

Uses the Post/Redirect/Get navigation sample for form submission.

Q2. Is Apache Tapestry Free/open Source?

Yes. Tapestry is open supply and loose. 

It is certified beneath the Apache Software License, which permits it for use even interior proprietary software program.

Q3. Is Tapestry A Jsp Tag Library?

Tapestry isn't a JSP tag library; Tapestry builds on the servlet API, but doesn’t use JSPs in any manner. It makes use of it own HTML template layout and its own rendering engine. Starting with release three.0, Tapestry includes a easy JSP tag library to permit JSP pages to create hyperlinks to Tapestry pages.

Q4. How Do We Write Components In Apache Tapestry?

Retrieving certain houses : When writting a factor, you often require diverse properties to be provided through the element consumer. At a few factor in the course of rendering, you'll want to apply the fee of this property.

You can do that by means of having access to the Binding. Assume we've a component with one belongings known as ‘values’. Our aspect will use this listing in its preRenderCommponent() method to setup some model, for use elsewhere.

.... If(getValues() == null) 

  IBinding binding = getBindings("values"); if(binding.GetObject() == null) 

      throw new RequestCycleException("The fee for 'values' can not be null", this);

   setValues((List)values.GetObject());

 

The binding itself will make sure that the item fee is the perfect type (assuming of course, it’s been setup proper).

Performing Lazy Instantiation of kingdom primarily based upon thing residences : In a few instances, the output of a component may be based totally upon the kingdom of a few other belongings of the identical element. For instance, imagine a shape where the user can select the kind of product to view. When they choose a product, the form makes a query to the database for merchandise matching this type, and reshows the listing on the equal web page. (the list might be covered out of doors of the shape element itself).

Lets anticipate that the web page item exposes it’s products thru a getProductModel() – which is an instance of IPropertySelectionModel.

We will also assume that the remainder of the web page has the opposite components essential to render correct HTML, the use of the fee furnished by the getProductModel() result.

Here, it's far beneficial to know whilst in the rendering process you could rely upon the price of selectedProduct to be set efficiently, so you can instantiate a ProductModel based at the provided cost, to be used within the shape rendering. The quality location to setup country is within the preRenderComponent() approach. This is referred to as by using Tapestry just before it renders any component, however AFTER it has set factor homes. So, we'd write:

blanketed void preRenderComponent() 

  String selected = getSelectedProduct();

  List products = getMatchingProducts(selectedProduct);

  productModel = new ProductModel(products);

  .. Different initialization code ...

 

Q5. How Do I Make A Link Popup A New Window?

Use the contrib:PopupLink component.

Q6. Why Do We Need

The script framework is an effective me to package deal scripts in components. It provides scripts with the advantages of components. It can now be reused like a issue and now not must worry approximately renaming field names or the wiring among the fields and the scripts. You just declare the aspect and you're top to move. It clearly is some other layer of abstraction that one will should examine but as soon as you have learned it, it's miles very effective. And simply there isn't an awful lot to it.

The script framework is remitted by the reality that form element/area names are mechanically generated with the aid of the framework. And so that you write your script in XML and use variables for these names and allow the framework offer an appropriate names at some stage in runtime. Going further, you could also ask the framework to offer other gadgets that could help in growing your script. For example…

<input-symbol key="select"

    class="org.Apache.Tapestry.Form.PropertySelection"

    required="yes"/>

This defines an input variable “choose” of type “org.Apache.Tapestry.Form.PropertySelection”. All such variables/symbols surpassed in to the script is saved in a symbol map. And now you could use the form select listing call by means of the usage of an ant fashion syntax like $choose.Call. The expression within “$” is an OGNL expression and is evaluated with appreciate to the image map. You may also define your personal symbols/variables the usage of <let…> like…

<let key="formObj">

    record.$pick out.Form.Name

</let>

<let key="selectObj">

    $formObj.$select.Call

</let>

These variables/symbols are saved within the image map additionally. So now in case you need to set the value of the shape pick listing all you do is say $formObj.$selectObj.Value = ‘anything’; this would be equivalent to record.MyForm.MySelect.Cost = ‘whatever’; where myForm is the shape name and mySelect is the select listing name.

<input-symbol...>s are like method parameters and <let...>s are like example variables. Typically you would bypass values to the <input-symbol...>s thru the Script thing like...

<component id="myScript" type="Script">

    <static-binding name="script" value="ScriptSpecificationName.Script"/>

    <binding name="select" expression="components.SomePropertySelection"/>

</component>

The real scripts are defined in one of the two sections of the script specification, <body…> or <initialization…>, depending on while you need the script to execute. If you need the script to execute on load of the web page, you then define it in the <initialization…>, in case you need it to execute on every other occasion, define it inside the <body…> segment of the specification. For instance…

 

<body>

    feature onChangeList(listObj)

    

        alert(listObj.Value);

    

</body>

<initialization>

    $selectObj.Onchange = characteristic(e)

    

        onChangeList($selectObj);

    

</initialization>

As you could see within the rendered page all scripts are aggregated on the top of the web page frame, there are no extra scripts all over the web page. Even event handlers are attached to shape gadgets inside the initialization block.

One greater aspect to do not forget, scripts being components, and additives by means of nature being impartial of its environment, will render the script within the page as soon as for each ocurrance of the element. If you want the frame of the script to be rendered only as soon as no matter how regularly the element is used, simply wrap the frame in a <unique> tag like…

<body>

<unique>

    function onChangeList(listObj)

    

        alert(listObj.Cost);

    

</unique>

</body>

Q7. How Is The Performance Of Tapestry?

My personal testing, documented inside the Sept. 2001 difficulty of the Java Report, concurs with other checking out (documented within the Tapestry discussion forums): Although immediately JSPs have a slight part in demo applications, in actual packages with a database or utility server backend, the performance curves for equal Tapestry and JSP applications are identical. Don’t reflect onconsideration on the performance of Tapestry; think about the overall performance of your Java builders.

Q8. How Do I Integrate A Tapestry Application With J2ee Declarative Security/jaas?

In web.Xml:

upload an additional servlet mapping to your tapestry application to /admin, and upload the following:

<security-constraint>

 <web-resource-collection>

  <url-pattern>/admin/*</url-pattern>

 </web-resource-collection>

 <auth-constraint>

   <role-name>ADMIN</role-name>

 </auth-constraint>

</security-constraint>

In your base magnificence for blanketed pages:

public void validate(IRequestCycle cycle) throws RequestCycleException 

  boolean isAdmin = getRequestCycle().GetRequestContext().GetRequest().IsUserInRole("ADMIN");

  if (!IsAdmin) 

    // not in right function

    throw new PageRedirectException.......

  

You can have some of mappings for the same app-servlet to unique URIs, that way you may depend a bit extra on the declarative security.

Q9. How Does Tapestry Compare To Other Frameworks?

Tapestry may be very an awful lot unlike maximum other frameworks in that it doesn’t use code generation; as a substitute it uses a real aspect item version based on JavaBe properties and sturdy specifications. This gives Tapestry a huge amount of flexibility and enables dynamic runtime inspection of the software with the Tapestry Inspector (a mini-software that may be built into any Tapestry software).

Q10. How Should Do Page Navigation In Apache Tapestry?

Usage web page residences:

Page1.Web page

<page-specification class="Welcome.Action">

        <property name="success" value="Home" />

        <property name="error" value="Error" />

</page-specification>

Page2.Page

<page-specification class="Welcome.Action">

        <property name="success" value="Home2" />

        <property name="error" value="Error2" />

</page-specification>

Welcome.Action.Java

public void submitListener(IRequestCycle cycle)

    if (achievement)

        cycle.Spark off(getSpecification().GetProperty("fulfillment"));

    if (mistakes)

        cycle.Spark off(getSpecification().GetProperty("error"));

 

So on achievement, it is going to be redirected to Home2 and on errors it will be redirected to Error2 page.

Q11. I Have To Restart My Application To Pick Up Changes To Specifications And Templates, How Can I Avoid This?

Start your servlet container with the JVM system parameter org.Apache.Tapestry.Disable-caching set to real, i.E., -Dorg.Apache.Tapestry.Disable-caching=authentic. 

Tapestry will discard cached specifications and templates after every request. You utility will run a chunk slower, but changes to templates and specs will show up right away. This also assessments that you are chronic server-facet nation effectively. 

Q12. Does Tapestry Work With Other Other Application Servers Besides Jboss?

Of direction! JBoss is loose and convienient for the flip-key demonstrations. You can download Tapestry and JBoss and have a real J2EE application jogging in about a minute! The scripts that configure JBoss are sensitive to the precise launch of JBoss, it need to be release three.0.@However, Tapestry packages are a hundred% box agnostic ... Tapestry doesn’t care what servlet box it's miles used with and does not even require an EJB container.

Q13. Can I Use The Same Component Multiple Times In One Template?

No – however you may copy the definition of a thing pretty without difficulty.

<component id="valueInsert" type="Insert" >

   <binding name="value" expression="getValueAt( rowIndex, columnIndex )" />

</component>

<component id="valueInsert1" copy-of="valueInsert"/>

<component id="valueInsert2" copy-of="valueInsert"/>

<component id="valueInsert3" copy-of="valueInsert"/>

<component id="valueInsert4" copy-of="valueInsert"/>

Q14. How To Alter The Url To Point To The Correct Page?

You could need to throw a RedirectException with the new URL; this sends an HTTP redirect to the patron.

Q15. How To Get A File From Client Input To Server End In Apache Tapestry?

Make a way just like the following a a listener, together with from a DirectLink or some thing.

(The Document is just a class that holds the file information you want to send to the person.)

public void downloadAction(IRequestCycle cycle)

    attempt

    

        HttpServletResponse reaction =

        cycle.GetRequestContext().GetResponse();

        byte[] information = new byte[1024];

        FileInputStream in = report.GetFileInputstream();

        reaction.SetHeader("Content-disposition",

          "inline; filename=" +

           file.GetFileName());

        reaction.SetContentType(record.GetMimeType());

        response.SetContentLength(new Long(record.GetSize()).IntValue());

        ServletOutputStream out = response.GetOutputStream();

        while (in.Read(data) > -1)

        

            out.Write(information);

        

        in.Close();

        response.FlushBuffer();

    

    catch (IOException e)

    

        e.PrintStackTrace();

    

Q16. How Do I Stream A File To The User From Tapestry?

Make a method just like the following a a listener, which includes from a DirectLink or some thing.

(The Document is just a magnificence that holds the document information you need to ship to the user.)

public void downloadAction(IRequestCycle cycle)

    strive

    

        HttpServletResponse reaction =

        cycle.GetRequestContext().GetResponse();

 

        byte[] data = new byte[1024];

        FileInputStream in = file.GetFileInputstream();

 

        reaction.SetHeader("Content-disposition",

          "inline; filename=" +

           document.GetFileName());

        response.SetContentType(document.GetMimeType());

        reaction.SetContentLength(new Long(file.GetSize()).IntValue());

        ServletOutputStream out = reaction.GetOutputStream();

        at the same time as (in.Examine(statistics) > -1)

        

            out.Write(information);

        

        in.Near();

        response.FlushBuffer();

    

    catch (IOException e)

    

        e.PrintStackTrace();

    

 

Q17. I Have A Form With A Submit Button. On The Form And The Submit Button Are Two Separate Listeners. Which Is Invoked First?

The button’s listener should get invoked when the shape encounters your button in the course of the rewind. The shape’s submitListener ought to get invoked after the form has completed its rewind, and as a consequence in the end different listeners were invoked. Note - this could mean that the listener for a button may be invoked BEFORE the form has ’submitted’ all its values - it relies upon where your input fields are relative for your button.

Q18. Does Tapestry Use Jsp Tag Libraries?

No. Tapestry does now not use JSP Tag library.

Tapestry builds at the Servlet API, but does now not use JSP anyway.

It makes use of it own HTML template format and its own rendering engine.

Q19. What Does It Cost?

Tapestry is open source and loose. It is certified under the Apache Software License, which lets in it to be used even internal proprietary software.

Q20. Is There A Wysiwyg Editor For Tapestry, Or An Ide Plugin?

Currently, no WYSIWYG editor is to be had for Tapestry; but, the layout of Tapestry lets in current editors to paintings fairly well (Tapestry additions to the HTML markup are virtually invisible to a WYSIWYG editor).Spindle is a Tapestry plugin for the splendid open-source Eclipse IDE. It provides wizards and editors for creating Tapestry applications, pages and components.




CFG