⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faq.fml

📁 structs源码
💻 FML
📖 第 1 页 / 共 2 页
字号:
<?xml version="1.0"?>
<!--
    $Id$

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at
   
         http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<!--
// ======================================================================== 78
-->

<faqs title="Taglib FAQ">
        <part id="general">

            <faq id="jstl">
                <question>
                What about JSTL?
                </question>
                <answer>
                <p>
                    There is overlap between Struts Taglib and the 
                    <a href="http://java.sun.com/products/jsp/jstl/">
                        JavaServer Standard Tag Library (JSTL).</a>
                       To make the best use of JSTL, 
                       use the <a href="../struts-el/index.html">
                       Struts EL component</a> instead. 
                   </p>             
                </answer>
             </faq>                


            <faq id="jsf">
                <question>
                What about JSF?
                </question>
                <answer>
                <p>
                    Struts 1 is <strong>not</strong> the best choice if you'd 
                    like to use JavaServer Faces components in your 
                    application. 
                    The Struts Faces component provides some interoperability 
                    with JSF, 
                    but Faces is really only intended as a stop gap for teams 
                    experimenting with JSF.
                </p>
                
                 <p>
                    For better JavaServer Faces support, 
                    consider using Struts 2 or 
                   <a href="http://shale.apache.org/">Apache Shale.</a>
                </p>

                </answer>
             </faq>                

            <faq id="xhtml">
                <question>
                Is Struts Taglib XHTML compliant?
                </question>
                <answer>
                <p>
                    If you use an &lt;html:html xhtml="true&gt; or &lt;html:xhtml/&gt;
                    element on your page, the tags
                    will render as XHTML (since version 1.1).
                 </p>
                </answer>
             </faq>                

            <faq id="wml">
                <question>
                Will the Struts tags support other markup languages such as WML?
                </question>
                <answer>
                <p>
                    The framework itself is markup neutral. The original Struts
                    taglibs are only one example of how
                    presentation layer components can access the framework.
                    The framework objects are exposed
                    through the standard application, session, and request
                    contexts, where any Java component in
                    the application can make use of them.
                </p>

                <p>Markup extensions that use the framework are available for
                    <a href="http://jakarta.apache.org/velocity">Velocity</a>
                    and
                    <a href="http://www.openroad.ca/opencode/">XLST,</a>
                    among others.
                    A new Struts tag library for
                    <a href="#jsf">Java Server Faces</a>
                    is also in development.
                </p>

                <p>For more about using WAP/WML with Struts see the article
                    <a href="http://www.sys-con.com/pbdj/archives2/0904/hamboeck/">
                        WAP up your EAserver.</a>
                </p>
                </answer>
             </faq>                

            <faq id="multiple">
                <question>
                Can I use multiple HTML form elements with the same name?
                </question>
                <answer>
                <p>
                    Yes. Define the element as an array and the framework will
                    autopopulate it like any other.
                </p>
                <pre>
                    <code>
                        private String[] id= {};
                        public String[] getId() { return this.id; }
                        public void setItem(String id[]) {this.id = id;}
                    </code>
                </pre>
                <p>
                    And so forth
                </p>
                </answer>
             </faq>                

            <faq id="multipleSubmits">
                <question>
                Can I have multiple submit buttons on the same form
                </question>
                <answer>
                <p>
                    <strong>Yes</strong>
                    . The issue is that only one action class can be
                    associated with a single form. So the real issue is how do
                    I decode
                    multiple submit types to a single
                    <code>Action</code>
                    class.
                    There is more than one way to achieve this functionality.
                </p>
                <p>
                    One popular approach is to use a 
                    <a href="../api/org/apache/struts/actions/LookupDispatchAction.html">
                        <code>LookupDispatchAction.</code>
                    </a>
                    Basically,
                    <code>LookupDispatchAction</code>
                    is using the keys from
                    <code>ApplicationProperties.resources</code>
                    as keys to a map of actions
                    available to your
                    <code>Action</code>
                    class. It uses
                    <a href="http://java.sun.com/j2se/1.3/docs/guide/reflection/">
                        reflection</a>
                    to
                    decode the request and invoke the proper action. It also
                    takes advantage of
                    the 
                    <a href="../userGuide/struts-html.html#submit">
                        <code>&lt;html:submit&gt;</code>
                    </a>
                    tags and is straight forward to implement.
                </p>
                <p>
                    You can roll your own with JavaScript events and
                    <code>javascript:void
                        (document.forms["myform"].submit)</code>
                    on any html element. This gives you
                    control of how you want your page to look. Again you
                    will have to decode the expected action in the
                    <code>execute</code>
                    method of
                    your action form if you choose this route.
                </p>
                </answer>
             </faq>                

            <faq id="focus">
                <question>
                Why doesn't the focus feature on the &lt;html:form> tag work in every circumstance?
                </question>
                <answer>
                <p>
                    Unfortunately, there is some disagreement between the
                    various browsers, and different versions of the same
                    browser, as to how the focus can be set.
                    The &lt;html:form> tag provides a quick and easy
                    JavaScript that will set the focus on a form
                    for most versions of most browsers.
                    If this feature doesn't work for you, then you should set
                    the focus using your own JavaScript.
                    The focus feature is a convenient "value-add" -- not a
                    core requirement of the tag.
                    If you do come up with a JavaScript that provides the
                    final solution to this project,
                    please post your patch to this
                    <a href="http://issues.apache.org/struts/browse/STR-899">
                        JIRA ticket.</a>
                </p>
                
                <p>
                    Another approach is to use a separate JavaScript that 
                    automatically focusses the first enabled field on the 
                    first form on a page. 
                    See the article 
                    <a href="http://www.codeproject.com/jscript/FocusFirstInput.asp">
                    Set Focus to First Input on Web Page</a>
                    for a working example that you can use in your own 
                    applications. 
                </p>
                </answer>
             </faq>                

            <faq id="checkbox">
                <question>
                Why are my checkboxes not being set from ON to OFF?
                </question>
                <answer>
                <p>
                    A problem with a checkbox is that the browser will only
                    include it in the request
                    when it is checked. If it is not checked, the HTML
                    specification suggests that it
                    not be sent (i.e. omitted from the request). If the value
                    of the checkbox is being
                    persisted, either in a session bean or in the model, a
                    checked box can never
                    unchecked by a HTML form -- because the form can never
                    send a signal to uncheck
                    the box. The application must somehow ascertain that since
                    the element was not
                    sent that the corresponding value is unchecked.
                </p>
                <p>
                    The recommended approach for framework applications is to use
                    the reset method in the
                    ActionForm to set all properties represented by checkboxes
                    to null or false. The
                    checked boxes submitted by the form will then set those
                    properties to true. The
                    omitted properties will remain false. Another solution is
                    to use radio buttons
                    instead, which always submit a value.
                </p>
                <p>
                    It is important to note that the HTML specification
                    recommends this same
                    behavior whenever a control is not "successful". Any blank
                    element in a HTML
                    form is not guaranteed to submitted. It is therefor very
                    important to set the
                    default values for an ActionForm correctly, and to
                    implement the reset method
                    when the ActionForm might kept in session scope.
                </p>                
                </answer>
             </faq>                

            <faq id="javascript.submit">
                <question>
                Can I use JavaScript to submit a form?
                </question>
                <answer>
                <p>
                    You can submit a form with a link as below.
                    BTW, the examples below assume you are in an &lt;html:form&gt;
                    block and 'myForm'
                    is picked up from the struts-config.xml name field of the
                    action.
                </p>
                <source>
                    &lt;a
                    href='javascript:void(document.forms["myForm"].submit()&gt;My
                    Link&lt;/a&gt;
                </source>
                <p>
                    Now the trick in the action is to decode what action you
                    intend to perform.
                    Since you are using JavaScript, you could set a field
                    value and look for it in
                    the request or in the form.
                </p>
                <p>
                    ... html/javascript part ...
                </p>
                <source>
                    &lt;input type='hidden' value='myAction' /&gt;
                    &lt;input type='button' value='Save Meeeee'
                    onclick='document.forms["myForm"].myAction.value="save";
                    document.forms["myForm"].submit();' /&gt;
                    &lt;input type='button' value='Delete Meeeee'
                    onclick='document.forms["myForm"].myAction.value="delete";
                    document.forms["myForm"].submit();' /&gt;
                </source>
                <p>
                    ... the java part ...

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -