簡體   English   中英

組件屬性“重新解析”后,無法對AJAX請求

[英]Component attributes doesn't set after “reRender” on AJAX request

目前,我正在研究一些復雜的Web前端,並使用以下方法實現它:

  • JSF 1.2
  • 小面1.1.15
  • RichFaces 3.3.3最終版

我創建了一個自定義JSF組件,該組件可以使用純JavaScript驗證inputText字段。 該組件只有一個屬性:type。 此屬性負責驗證算法,該算法將在用戶按下鍵盤鍵時應用。

在創建初始視圖的restoreView階段,此屬性由JSF(實際上是Facelets)設置。 這意味着我有一個帶有屬性“類型”的設置器和獲取器的組件類。 還有一個“類型”設置器,用xhtml文檔中指定的值進行調用。

如果我在reRender屬性中指定組件對象,則每次在restoreView階段都會重新創建組件對象。 但是,當重新創建它時,我的必需屬性類型未設置。 它只是創建新的組件對象……而已。 可能是我不了解某些內容,這是正常現象,但是在這種情況下如何獲取屬性值?

碼:

簡單測試頁:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:u="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a="http://richfaces.org/a4j"
      xmlns:r="http://richfaces.org/rich"
      xmlns:v="http://nobodyhere.ru/jsf/validation">
    <head>
        <title>Test Page</title>
    </head>
    <body>
        <h:form id="testForm">
            <h:inputText id="textInput" value="test">
                <v:keyValidator type="time"/>
            </h:inputText>
            <a:commandButton value="Make AJAX request" reRender="testForm"/>
        </h:form>
    </body>
</html>

組件類:

public class KeyValidator extends UIComponentBase
{

    public KeyValidator()
    {
        System.out.println("new KeyValidator");
    }

    public KeyValidatorType getValidatorType()
    {
        return type;
    }

    public String getType()
    {
        return getValidatorType().toString();
    }

    public void setType(String type)
    {
        this.type = KeyValidatorType.valueOf(type.toUpperCase());
    }

    @Override
    public String getFamily()
    {
        return KeyValidator.class.getName();
    }

    private KeyValidatorType type;
}

當我按“發出AJAX請求”按鈕時,將重新創建我的組件。 但是屬性“類型”未在組件中設置。

主要的問題在開始renderView在組件渲染階段時encodeBegin把它叫做試圖讓這個屬性,當然,它得到null的,而不是正確的值。

因此,更精確的問題可能是:
如何在renderView階段獲取AJAX請求上組件的屬性值?

任何幫助將不勝感激。

您必須在組件中重寫saveStaterestoreState才能保存和恢復所需的屬性。

祝好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM