dataTable は、value 属性に角括弧が含まれている場合、最初の項目のみを出力します。

StackOverflow https://stackoverflow.com/questions/3806906

  •  25-09-2019
  •  | 
  •  

質問

私は持っています h:dataTable 表示する ProfileNotification 以下のように:

        <h:dataTable value="#{myBean.profileNotifications}" var="item"
                     rendered="#{myBean.renderProfileNotification}">
            <h:column>
                <h:form>                        
                    <h:outputText value="#{item.userName} "/>
                    <h:outputText value="commented on your profile. "/>
                    <!-- <h:outputText value="[#{item.createTime}]"/> -->
                </h:form>
            </h:column>                
        </h:dataTable>

私が持っていないときは item.createTime, をクリックすると、 commandLink 設定する renderProfileNotification=true, 、4つの項目が出力されます。ただし、コメントを外した場合 item.createTime, 、それは 1 つの項目のみを出力します、 最初の項目.

編集:問題は、 [] 内部 value. 。BalusC はこれが EL のバグであると疑っているため、小さく、読みやすく、再現可能なコードでバグを再現します。このコードは Glassfish v3.0.1 b22 で実行されます。

index.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>TODO supply a title</title>
</h:head>
<h:body>
    <h:form id="table">
        <h:dataTable   value="#{myBean.temp}" var="item" rendered="#{myBean.display}">
            <h:column>
                <h:outputText value="[#{item}]"/>
            </h:column>
        </h:dataTable>            
    </h:form>
    <h:form>
        <p:commandLink value="Display" actionListener="#{myBean.setDisplay}" update="table"/>
    </h:form>
</h:body>
</html>

myBean.java

@ManagedBean(name="myBean")
@SessionScoped
public class myBean {

List<String> temp = null;

public myBean() {
}

private boolean display = false;

@PostConstruct
public void init(){
    temp = new ArrayList<String>();
    temp.add(0, "Tom");
    temp.add(1, "Peter");
    temp.add(2, "Mike");
    temp.add(3, "Fox");
}

public List<String> getTemp() {
    return temp;
}

public void setTemp(List<String> temp) {
    this.temp = temp;
}

public boolean isDisplay() {
    return display;
}

public void setDisplay() {
    this.display = !this.display;
}
}
役に立ちましたか?

解決

はい、最後です ] それが問題を引き起こしています。使用するとき

<h:outputText value="[#{item}]"/>

ajax リクエストの XML レスポンスは次のとおりです。

<?xml version="1.0" encoding="UTF-8"?><partialResponse><components><component><id>table</id><output><![CDATA[
<form id="table" name="table" method="post" action="/playground/test.jsf" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="table" value="table" />
<table>
<tbody>
<tr>
<td>[Tom]]]><![CDATA[</td>
</tr>
<tr>
<td>[Peter]]]><![CDATA[</td>
</tr>
<tr>
<td>[Mike]]]><![CDATA[</td>
</tr>
<tr>
<td>[Fox]]]><![CDATA[</td>
</tr>
</tbody>
</table>
~com.sun.faces.saveStateFieldMarker~
</form>]]></output></component></components><state><![CDATA[<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="8834103461195979522:5904029216967015556" autocomplete="off" />]]></state><callbackParams><callbackParam>{"validationFailed":false}</callbackParam></callbackParams></partialResponse>

不要な CDATA ブロックに注意してください。

そして使用するときは

<h:outputText value="[#{item})"/>

ajax リクエストの XML レスポンスは次のとおりです。

<?xml version="1.0" encoding="UTF-8"?><partialResponse><components><component><id>table</id><output><![CDATA[
<form id="table" name="table" method="post" action="/playground/test.jsf" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="table" value="table" />
<table>
<tbody>
<tr>
<td>[Tom)</td>
</tr>
<tr>
<td>[Peter)</td>
</tr>
<tr>
<td>[Mike)</td>
</tr>
<tr>
<td>[Fox)</td>
</tr>
</tbody>
</table>
~com.sun.faces.saveStateFieldMarker~
</form>]]></output></component></components><state><![CDATA[<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="502405171373727621:5591448575905434431" autocomplete="off" />]]></state><callbackParams><callbackParam>{"validationFailed":false}</callbackParam></callbackParams></partialResponse>

これは要約すると、次の問題の原因になります。ajax 応答ハンドラーは、CDATA ブロックを閉じたり開始したりする必要はありません。 ] 部分的な応答であり、JS XML 応答パーサーは最初の応答のみを選択して表示します。簡単な回避策は、 ] 値式の外側:

<h:outputText value="[#{item}"/>]

その結果、次の XML 応答が返されます。

<?xml version="1.0" encoding="UTF-8"?><partialResponse><components><component><id>table</id><output><![CDATA[
<form id="table" name="table" method="post" action="/playground/test.jsf" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="table" value="table" />
<table>
<tbody>
<tr>
<td>[Tom]
            </td>
</tr>
<tr>
<td>[Peter]
            </td>
</tr>
<tr>
<td>[Mike]
            </td>
</tr>
<tr>
<td>[Fox]
            </td>
</tr>
</tbody>
</table>
~com.sun.faces.saveStateFieldMarker~
</form>]]></output></component></components><state><![CDATA[<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-1679996061683473780:1967669133311943592" autocomplete="off" />]]></state><callbackParams><callbackParam>{"validationFailed":false}</callbackParam></callbackParams></partialResponse>

Ajax 応答ハンドラーまたは JS XML 応答パーサーのどこに問題の原因があるのか​​はまだわかりませんが、少なくとも原因はわかりました。問題が特定されたら、遅かれ早かれ Mojarra のスタッフに報告するつもりです。


アップデート:OK、さらに詳しく説明しました。これを誤って実行しているのは、PrimeFaces の ajax 応答ハンドラーと JS XML パーサーです。モジャラを使用する場合 h:commandLink の代わりに p:commandLink うまくいきます。

<h:commandLink value="Display" actionListener="#{myBean.setDisplay}">
    <f:ajax render=":table" />
</h:commandLink>

Mojarra の ajax 応答ハンドラーは、毎回の後に不要な CDATA ブロックを出力しません。 ]. 。それが PrimeFaces の根本的な原因である可能性があります。


アップデート:問題は PF 担当者に報告されました: http://code.google.com/p/primefaces/issues/detail?id=1282

他のヒント

何が間違っている

Iフィギュア。見かけ上、[]属性内valueを置くことは悪いです。私が持っていることはこれです:

<h:outputText value="[#{item.createTime}]"/>

私はなるために、[]を取る場合は、

<h:outputText value="#{item.createTime}"/>

そして、すべての作業罰金。特殊文字のもののいずれかである必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top