How can text in HTML: button, HTML: Submit, HTML: cancel, and other tags of struts be internationalized?

Source: Internet
Author: User
HTML: button, HTML: Submit, HTML: cancel, and other tags in struts. None of these tag attributes are used for internationalization, to put it bluntly, there is no attribute that can fill in the key of message resource for us. This poses a problem for internationalization, because these are buttons, the text on the button cannot be manually written to death using the value attribute in the code.

If there is a problem, we need to check the struts information and his example, and find that the original solution is as follows:

<HTML: Submit property = "Submit" styleclass = "bottonyellow">
<Bean: Message key = "login. submitbtnvalue"/>
</Html: Submit> among these tags, the property attribute is required. This attribute is equivalent to name = ..., therefore, it is necessary to manually add the bean: Message line to the text on the international button. Why does struts achieve internationalization in this way? I checked the struts source code and got some unexpected results.

There are several methods in the tag Library Specification of JSP, which have never been understood before: do_starttag, do_afterbody, and do_endtag. Now we understand that when a tag is touched, do_starttag is triggered, when a Tag ends, the do_endtag is triggered. In the above case, when the content contained between the tags is triggered (that is, the body part ), do_afterbody will be triggered (I believe there are similar methods such as do_startbody). The struts buttontag class is to add code in the do_afterbody method to reset the value attribute to the value specified by our body, to enable the text on the international button. The following is the source code of struts's buttontag. Java:

/**
* Process the start of this tag.
* @ Exception jspexception if a JSP exception has occurred
*/
Public int dostarttag () throws jspexception {

// Do nothing until doendtag () is called
This. Text = NULL;
Return (eval_body_tag );

}

/**
* Save the associated label from the body content (if any ).
* @ Exception jspexception if a JSP exception has occurred
*/
Public int doafterbody () throws jspexception {

If (bodycontent! = NULL ){
String value = bodycontent. getstring (). Trim ();
If (value. Length ()> 0)
TEXT = value;
}
Return (skip_body );

}

/**
* Process the end of this tag.
* <P>
* Support for indexed property since Struts 1.1
* @ Exception jspexception if a JSP exception has occurred
*/
Public int doendtag () throws jspexception {

// Acquire the label value we will be generating
String label = value;
If (Label = NULL) & (text! = NULL ))
Label = text;
If (Label = NULL) | (Label. Trim (). Length () <1 ))
Label = "click ";

// Generate an HTML Element
Stringbuffer Results = new stringbuffer ();
Results. append ("<input type = \" button \"");
If (property! = NULL ){
Results. append ("name = \"");
Results. append (property );
// * @ Since Struts 1.1
If (indexed)
Prepareindex (results, null );
Results. append ("\"");
}
If (accesskey! = NULL ){
Results. append ("accesskey = \"");
Results. append (accesskey );
Results. append ("\"");
}
If (tabindex! = NULL ){
Results. append ("tabindex = \"");
Results. append (tabindex );
Results. append ("\"");
}
Results. append ("value = \"");
Results. append (Label );
Results. append ("\"");
Results. append (prepareeventhandlers ());
Results. append (preparestyles ());
Results. append (getelementclose ());

// Render this element to our writer
Tagutils. getinstance (). Write (pagecontext, results. tostring ());

// Evaluate the remainder of this page
Return (eval_page );

}

 

 

 

 

 

 

 

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.