Page Jump components: actionlink, directlink, externallink, genericlink, and servicelink)

Source: Internet
Author: User
Tags actionlink servicelink
New article: 4-Oracle accumulation | old article: 0-Accumulation

1-actionlink component

It is understood for the moment that, instead of turning to the next page, only a listener method is activated.

When the page responds, a link is created. If the link is triggered, the actionlink component gets a listener (by calling the actiontriggered () method ()).
2-DirectlinkComponents

Bytes -------------------------------------------------------------------------------------------------------------------

1-directlink creates a <A/> tag, which contains contextual data provided to the component listening method. It is used when actionlink is unavailable.

2-The parameters parameter specifies an array of objects encoded on the URL. When a link is triggered, these objects are decoded. This means that "object" can be passed as a parameter.

The following three methods can be used to obtain parameters for a listener:

1-istenermethod (Parameters): Provides parameters in the listener method.

2-istenermethod (irequestcycle cycle,Parameters)

3-listenermethod (ireuqestcycle cycle), using irequestcycle. getserviceparameters ()

When the 3-stateful parameter is true, when the link is activated, it checks whether there is a valid httpsession. If the link cannot be obtained, a stalelinkexception is thrown.
I don't know if you think it is special: Tapestry can pass objects between pages through URLs, or save an object completely to the browser of the client. In my previous project, the URL passed is even more than one thousand characters long.
Recall that in JSP, parameters between pages are transmitted in the string type unless you put them in the session. But tapestry can pass objects. Why?
In fact, the reason is very simple, as you saw earlier errors: cocould not find an adaptor for class com. Ramon. Test. myobj. That is to say, tapestry is still a parameter of the string type, and the parameter stored on the client browser is still a string. As a framework, tapestry converts the objects you need to pass, that is, an object is converted to a unique string on the server through an "adapter, put it on the client browser. When the string is returned to the server segment from the client, tapestry restores it to the original object and retains the object state.
Why does directlink not mention serialization ?", Serialization aims to save the object state during data transmission. Serialization is a very huge learning. Of course, it can also be simply interpreted as a specification of data transmission. As a specification, it may be ignored sometimes.
For this adaptor of tapestry, in tapestry4.0, You Can refactor the officially provided adaptor according to your own logic. I remember that we didn't officially provide adaptors for T4 before tapestry4.0-beta5. At that time, in the official e-mail list of tapestry, people realized their own adaptors.

Persit = "client" whether to use it with caution, although it is easy to use
I personally think it is inappropriate for large objects. The xxxxlink parameter in this page will all have a State: pagename = XXXXXXXX (very long ). The problem I encountered was that the link with those parameters cannot be opened because of the get method's restriction on the URL length.
It may be avoided in other ways. But I think it is best to have a small object, such as transmitting an ID.

In fact, you have to worry about it. You can take a closer look at the source code running on the page. If xxxlink is used, it is transmitted in post mode. The following is a URL that I used directlink IN THE T3 era.
It is a link of our [Chengdu Jianxin] www.cdcin.com actually running project. Use Word for statistics: 741. Of course, this is not our longest link.
Http://www.cdcin.com/Work_safety_constructionFinishForm.html? SP = OH4sIAAAAAAAAAFvzloG1uIhBKTk_Vy85JTe5WC8_US8pX885P6-4pKg0uSQzP88tMy-zOONyjYkuy7Y_B5kYGCqKGLTRNSQlFqfqOQEJTJ3f_X1PPloh08DEwOnJwJGRWJzhnJ-S6sPAHZ-YnJxaUOKSWJJawiDgk5VYlqhfWpKZow8SsQYrKCjJLClNSfXLL2EQgijIScxL1w8uKcrMSwcq4YsHOiQ3s8Q5P7cgMa-ykKGOgdmHQQQoinAFqhx7fFpmDtBAKJc5PjOlhEEYyWzPvJLU9NQioOE88QVF-VmpySWOKSlFUPVwMb_E3FSwWEVBAwMDAzAQeUFm6BUX5uiB3C_yyy3D3jRtOiS8-MByIM-BJTOyGhm9I0skmYGSBeUcQP3_HeatYKgoYeA0MjAwNjSwMDQtYVB81jHhZfPepzuanq9Z87R19dPdu56vnfh0-9LnK7qftq552r-jhEEdqqZ31vOJ85517H86Z8OTXcuf7ml42j_x2ZzOlzMnwFSCTDYxNDCxsAC6VRDsHpB_9aD-FXq0YMn3xnYLJgZGTwbWssSc0lSguwUQ6vxKc5NSi9rWTJXlnvKgG-StAgYGxuvAiHk5d9LzfV1Plyx_2TjZ0MDwaf_2EgZZiIsgzn_RtfHp7LVPdnQ-mzPfGCQPABoE4-93AgAA
Although there is no State data in this link, it can at least prove that the URL can be very long.
Then the get method you mentioned is submitted in form. In this case, the State data of persist is stored in the form as a hidden.
Therefore, I don't think there will be any such situation.

Bytes --------------------------------------------------------------------------------------------------------------------

The directlink component involves sessions. There are two differences between the directlink component and the externallink component:

First, directlink involves sessions. directlink has a Boolean stateful parameter to select stateful or stateless. The default value of this parameter is true, that is, stateful.

Externallink does not involve sessions. externallink is only stateless and cannot be selected.

Second, it is very important that directlink and externallink parameters are transmitted differently.

Directlink ----> obtain the parameters in the monitoring method on this page, and set the parameters to the next page.

Externallink ----> implemented on the next pageIexternalpageInterface andActivateexternalpageMethod "receive" parameter.

To implement the paging function, we use the directlink component. In the following example, each page shows only 10 data records, so hql queries only 10 data records from the database. For a page, you need to jump to the "next page" (or "Previous Page") and pass paging parameters (that is, the current page number) to the business logic layer method, and the number of data displayed on each page ).
See the relevant code in the corresponding HTML file:
<Span serving cid = "@ conditional" condition = "ognl: firstdisable">
<Span cid = "first"> homepage </span>
<Span upload cid = "previous"> previous page </span>
</Span>
Page <span upload cid = "@ Insert" value = "ognl: pageno"/>
<Span inclucid = "@ conditional" condition = "ognl: lastdisable">
<Span cid = "Next"> next page </span>
<Span distinct cid = "last"> last page </span>
</Span>
Total <span cid = "@ Insert" value = "ognl: total"/> pages
Declare related components in the page file:

The getter and setter of first previous next maxresult must be defined in the page class containing the link.

<Component id = "first" type = "directlink">
<Binding name = "listener" expression = "listeners. changepage"/>
<Binding name = "Parameters" expression = "New java. Lang. object [] {first, maxresult}"/>
</Component>
<Component id = "previous" type = "directlink">
<Binding name = "listener" expression = "listeners. changepage"/>
<Binding name = "Parameters" expression = "New java. Lang. object [] {previous, maxresult}"/>
<Binding name = "disabled" expression = "previusdisable"/>
</Component>
<Component id = "Next" type = "directlink">
<Binding name = "listener" expression = "listeners. changepage"/>
<Binding name = "Parameters" expression = "New java. Lang. object [] {next, maxresult}"/>
<Binding name = "disabled" expression = "nextdisable"/>
</Component>
<Component id = "last" type = "directlink">
<Binding name = "listener" expression = "listeners. changepage"/>
<Binding name = "Parameters" expression = "New java. Lang. object [] {last, maxresult}"/>
</Component>
The directlink component is represented as an html<A>Element, used to provide a URL. When a user clicks, a specific listening method is triggered on the page.
In the four components that implement paging page Jump, they are declared as the same listener listening method. See the changepage code of the corresponding listening method in the corresponding Java:
Public VoidChangepage (irequestcycle cycle ){
// Tapestry4.0 has deprecated cycle. getlistenerparameters ()
Object[] Parameters = cycle. getserviceparameters ();
// Obtain the current page number
IntegerIg1 = (Integer) Parameters [0];
IntI1 = ig1.intvalue ();
Setpageno (I1 );
// Obtain the maximum number of entries displayed on each page
IntegerIg2 = (Integer) Parameters [1];
IntI2 = ig2.intvalue ();
Setmaxresult (I2 );
}
For directlink, the parameters parameter is assigned the same value as externallink. Here we get an array containing two types of information: the number of pages to be redirected, and the number of data entries displayed on the page to be redirected.
As mentioned above, after the Java file on the page completes the data processing required for the page performance, it should restore all its member variables (page property) to the initial value. Therefore, the "current page number" and "maximum data displayed per page" data are saved on the page. After you click the trigger listener method, the page will provide the "page number" and "Maximum number of displays per page" for the next page ". Then query the new maxresult.
Run the following command:
3-externallink component

Certificate -----------------------------------------------------------------------------------------------------------------------------------------------
Externallink uses the "receive" Method for parameters to point to the link on the application page.
The externallink component does not verify the user session, so the URL generated by the externallink component can be added to the user's favorites for further access.

<a href="#" 
jwcid="@ExternalLink"
page="ViewArticle"
parameters="ognl:{articleId, 'de'}"
disabled="ognl:languageCode=='de'"
>view this article in German</a>

<div jwcid="@Insert" value="ognl:content">content of the article</div>
package com.myexample;

import org.apache.tapestry.IExternalPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.html.BasePage;

public abstract class ViewArticle extends BasePage
implements IExternalPage {

public abstract Integer getArticleId();
public abstract void setArticleId(Integer articleId);
public abstract String getLanguageCode();
public abstract void setLanguageCode(String language);

public void activateExternalPage(Object[] params, IRequestCycle cycle) {
setArticleId((Integer) params[0]);
setLanguageCode((String) params[1]);
}

public String getContent() {
// retrieve the content of the article for the selected language

}

}

Certificate -----------------------------------------------------------------------------------------------------------------------------------------------

The externallink component uses the external service in nine services of the tapestry. This component uses external service to create a link that inherits the iexternalpage interface. The following is an example of its usage.
<A required cid = "@ externallink" page = "successpage" parameters = 'ognl: New java. Lang. object [] {"this is success page! ", Item. ID} 'Disabled =" ognl: item. Isable "> </a>
Page = "successpage" indicates the name of the page to be redirected. The page parameter of the externallink component finds the corresponding page file based on the configuration in the configuration file tapestry. application:
<Page name = "successpage" Specification-Path = "/webinf/successpage. Page"/>
In the successpage. page file:
<Page-specification class = "com. Ce. tapestry. Success">
Find the success. Java file. In the success. Java file, we found that this class inherits the iexternalpage interface:
Public Abstract ClassSuccessImplementsIexternalpage
And implements the activateexternalpage (object [], irequestcycle) method.
For the externallink component, it must inherit the iexternalpage interface and implement the public void activateexternalpage (object [] parameters, irequestcycle cycle) method. The parameter object [] of this method comes from the parameter value of parameters of this component. The default value of the disabled parameter is false. If it is true, it cannot be clicked ".
4-genericlink component

The component genericlink is usually usedJump to a link outside the application scope. Although genericlink can be completed using other components, genericlink is more flexible: it can be set to disabled, and can also contain rolover components like directlink or actionlink.
The usage is as follows:
<A required cid = "@ genericlink" href = "ognl: item. Homepage" Disabled = "false"/>
Href parameter: provides a link address. The preceding example shows that the address is retrieved from item. Homepage.
Disabled: this parameter defaults to false. If it is true, it cannot be clicked ". All link components have the same effect on the disabled parameter.
5-pagelink component

It is equivalent to externallink without parameters.

The pagelink component is very simple. You only need to specify the name of the next page to jump to in the page parameter. Note that pagelink and externallink use different services. This component uses page service to create another URL.
See the example for how to use:
<A challenge cid = "@ pagelink" page = "Infos">
</A>
Jump to the following url: http: // localhost: 8080/Hello/helloworld?Service = page/Upload
6-servicelink component

Create any engine service without parameters. The servicelink component usage is similar to that of actionlink, pagelink, and directlink, but is often used together with specific application services. The service parameter is the name of the engineservice object to be called. (Body)

The above link components must be in the bodyUsed within the scope of components.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.