English 中文(简体)
JUSF JavaScript API jsf. uft. util. 链路没有像预期的那样工作
原标题:JSF JavaScript API jsf.util.chain not work as expected

在这里我简单的 JavaScript API 应用程序, 用jsf. util. 链法显示 JavaScript API 错误 。

使用 :

  • JRE 1.6
  • Maven 3
  • JSF 2.1.8
  • Tomcat 7
  • Jetty 6 (to run from maven jetty:run)
  • Mozilla Firefox 12.0
  • Firebug 1.9.2

此处的观点是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">

    <h:head>
        <title>Test JSF 2.0 Javascript API</title>
        <script type="text/javascript">
            function returnTrue(){
                debug( return true );
                return true;
            }
            function returnFalse(){
                debug( return false );      
                return false;
            }

            function debug(obj) {               
                if (console) {
                    if(console.debug){
                        //for firebug
                        //http://getfirebug.com/wiki/index.php/Console_API
                        console.debug(obj);
                    }
                }
                else if (console) {
                    if(console.log){
                        //for IE
                        //http://msdn.microsoft.com/en-us/library/dd565625(v=vs.85).aspx
                        console.log(obj);
                    }
                }               
            }

        </script>
    </h:head>
    <h:body>
        <h:form>
            <br />
            <br />
            <h1 align="center">Test jsf.util.chain</h1>
            <br />
            <table align="center">
                <tbody>
                    <tr>
                        <td>Combo A</td>
                        <td><h:selectOneMenu id="comboa" value="#{comboTest1.combo1Value}" onchange="returnTrue()">
                                <f:selectItems value="#{comboTest1.values1}" />
                                <f:ajax listener="#{comboTest1.changeCombo1}" render="combob" />
                            </h:selectOneMenu></td>
                    </tr>
                    <tr>
                        <td><label>Combo B</label></td>
                        <td><h:selectOneMenu id="combob" value="#{comboTest1.combo2Value}" title="Depend of combo 1" onchange="returnFalse()">
                                <f:selectItems value="#{comboTest1.values2}" />
                                <f:ajax listener="#{comboTest1.changeCombo2}" render="@this labela" />
                            </h:selectOneMenu></td>
                    </tr>
                    <tr>
                        <td>Label A</td>
                        <td><h:outputLabel id="labela" value="#{comboTest1.labelValue}" title="Depend of combo 2" /></td>
                    </tr>
                </tbody>
            </table>
            <br />
            <br />
            <br />
        </h:form>
    </h:body>
</f:view>

这里管理着的豆子:

package com.ms.test.jsf.bug;

/**
 * 
 */

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.model.SelectItem;

/**
 * @author soaint
 * 
 */
@ManagedBean(name = "comboTest1")
@ViewScoped
public class ComboTest1 implements Serializable {

    private Map<String, List<String>> combinado = null;

    private Object combo1Value = null;

    private Object combo2Value = null;

    private Object labelValue = null;

    /**
     * 
     */
    private static final long serialVersionUID = -4737479400003511726L;

    public ComboTest1() {

        System.out.println("CREATE ComboTest1");

        combinado = new HashMap<String, List<String>>();
        List<String> list = null;
        for (int i = 0; i < 10; i++) {
            list = new ArrayList<String>();
            for (int k = 0; k < 10; k++) {
                list.add(i + " - " + k);
            }
            combinado.put(i + "", list);
        }
    }

    public void changeCombo1(AjaxBehaviorEvent abe) {
        System.out.println("CHANGE MENU A === " + combo1Value);
    }

    public void changeCombo2(AjaxBehaviorEvent abe) {
        System.out.println("CHANGE MENU B === " + combo2Value);
        labelValue = combo2Value;
    }

    public List<SelectItem> getValues1() {
        List<SelectItem> list = new ArrayList<SelectItem>();

        Set<String> keys = combinado.keySet();
        List<String> listi = new ArrayList<String>(keys);
        Collections.sort(listi);
        for (Object object : listi) {
            list.add(new SelectItem(object, " -- " + object + " -- "));
        }
        list.add(0, new SelectItem(null, " ------- "));

        return list;
    }

    public List<SelectItem> getValues2() {
        List<SelectItem> list = new ArrayList<SelectItem>();

        List<? extends Object> keys = combinado.get(combo1Value);
        if (keys != null) {
            for (Object object : keys) {
                list.add(new SelectItem(object, " -- " + object + " -- "));
            }
        }

        return list;
    }

    public Object getCombo1Value() {
        return combo1Value;
    }

    public void setCombo1Value(Object combo1Value) {
        this.combo1Value = combo1Value;
    }

    public Object getCombo2Value() {
        return combo2Value;
    }

    public void setCombo2Value(Object combo2Value) {
        this.combo2Value = combo2Value;
    }

    public Object getLabelValue() {
        return labelValue;
    }

}

简单而言, 视图有两个表列, 第一个首选的在变化事件中有一个调回 True, 第二个调回 False 。 两者都有ajax 调回管理型贝因的调回( 默认) 。 内部 JSF 加入更改属性的习惯, 而 ajax mojarra 调回 jsf. util 。 链调 :

<select id="j_idt5:comboa" name="j_idt5:comboa" size="1" onchange="jsf.util.chain(this,event, returnTrue() , mojarra.ab(this,event, valueChange ,0, j_idt5:combob ) )">
...
<select id="j_idt5:combob" name="j_idt5:combob" size="1" title="Depend of combo 1" onchange="jsf.util.chain(this,event, returnFalse() , mojarra.ab(this,event, valueChange ,0, @this j_idt5:labela ) )">
...

https://docs.oracle.com/cd/E17802_01/j2ee/javaee/javae/javaserverfaces/2.0/docs/js-api/symbols/jsf.util.html#constructor" rel=“不跟随 noreferrer”>oracle网站 广告:

<static> jsf.util.chain(source, event)

A varrgs 函数引用任意数量的脚本。 如果链条中的任何脚本返回错误, 链条是短路的, 其后的脚本不被引用。 任何脚本数量都可以在事件参数之后指定 。

这不是真的, 第二选择有选择 False 的号召, 但此点燃 ajax 。

<强>原因:

I have my JSF configured in Development mode in web.xml context-param and can debug the jsf.js uncompressed version. On my JSF version used the jsf.util.chain is declared on line 2247. I insert breakpoint on line 2260 on code:

var returnValue = f.call(thisArg, event);

完整方法 :

jsf.util.chain = function(source, event) {

    if (arguments.length < 3) {
        return true;
    }

    // RELEASE_PENDING rogerk - shouldn t this be getElementById instead of null
    var thisArg = (typeof source ===  object ) ? source : null;

    // Call back any scripts that were passed in
    for (var i = 2; i < arguments.length; i++) {

        var f = new Function("event", arguments[i]);
        var returnValue = f.call(thisArg, event);

        if (returnValue === false) {
            return false;
        }
    }
    return true;

};

在第一个方法调用( 返回True 或返回False) 后, < pront@ em > returnValue 总是有 < 坚固 > 未定义 值 。

我测试的全代码 < a href=""https://drive.google.com/file/d/0B_-bJ6IabuUOGhRdEo4VlZrd2M/view" rel="不跟随 noreferrer" >这里

下载、解zip、打开控制台到解zip 路径并运行

mvn clean jetty:run

http://localhost:8080/testBugJSF/ 上开放网络浏览器

My questions are: Did this was a valid implementation and core JavaScript suffered changes that affected the results of this implementation? As to whom to report this to be corrected? What is JSF report path? As I can correct this problem directly in my application?

最佳回答

每种方法必须返回。

<tr>
                    <td>Combo A</td>
                    <td><h:selectOneMenu id="comboa" value="#{comboTest1.combo1Value}" onchange="return returnTrue()">
                            <f:selectItems value="#{comboTest1.values1}" />
                            <f:ajax listener="#{comboTest1.changeCombo1}" render="combob" />
                        </h:selectOneMenu></td>
                </tr>
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...