1

I want to add a label with an id and an inputfield with an id to a panelgroup (layout box), which has its own id. I expect the label and the inputfield to have the following ids: (viewid):(formid):(panelgroupid):(own id) But somehow the panelgroupid (fachlich1) isnt passed on to the children.

<form id="viewns_Z7_6PQJDK4JGD09F0I34QTLQH2015_:j_id_3" …&gt;
    <div id="viewns_Z7_6PQJDK4JGD09F0I34QTLQH2015_:j_id_3:fachlich1">
        <label id="viewns_Z7_6PQJDK4JGD09F0I34QTLQH2015_:j_id_3:label" for="viewns_Z7_6PQJDK4JGD09F0I34QTLQH2015_:j_id_3:value">Bla</label>
        <input id="viewns_Z7_6PQJDK4JGD09F0I34QTLQH2015_:j_id_3:value" type="text" value="Blubb34534" name="viewns_Z7_6PQJDK4JGD09F0I34QTLQH2015_:j_id_3:value">
    </div>
</form>

Any clue what I might be doing wrong? :(

Thanks for your help!


Edit:

i want to create my own component which basically consits of a surrounding div + label + inputtext. i extend from the HtmlPanelGroup and override the encodeBegin method, where i set the layout to block, set the id of the panelgroup,add the components, after which i call super.encodeBegin:

public void encodeBeginn(FacesContext context)
{
    setLayout("block");
    setId(getId());

    HtmlOutputLabel label = new HtmlOutputLabel();
    label.setId("label");
    label.setFor("value");
    label.setValue(getLabel());
    getChildren().add(label);

    HtmlInputText text = new HtmlInputText();
    text.setId("value");
    text.setValue(getValue());
    getChildren().add(text);

    super.encodeBeginn(context)
}
4

3 に答える 3

4

インターフェイスの実装のみNamingContainerが、独自の ID を子の ID の先頭に追加します。javadocによると、次のコンポーネントがあります。

すべての既知の実装クラス:

HtmlDataTableHtmlFormUIDataUIFormUINamingContainer

HtmlPanelGroupに裏打ちされたは、その<h:panelGroup>中にはありません。標準の JSF では、それ<h:dataTable><h:form>実装するだけです。標準の Facelets では、<ui:repeat>それも ( を通じてUINamingContainer) 実装するだけです。

これにより、技術的な問題が発生することはまったくありません。あなたの具体的な問題 (質問で何も言わなかった) がこれによって引き起こされていると思われる場合は、間違った原因を見つけた可能性が高く、具体的な問題の原因を別の方向に探さなければなりません。

于 2012-07-02T13:59:06.453 に答える
0

BalusC の回答に関するコメントで述べたように、カスタム コンポーネントに NamingContainer を実装させることは可能です。私は似たようなことを試しましたが、カスタムコンポーネントは基本的に複合コンポーネントにすぎないため、周囲の HtmlPanelGroup は内部構成コンポーネントの NamingContainer になります。

ただし、getFamily を別の名前でオーバーライドしないように注意してください。これを行うと、JSF が標準レンダラー (HtmlPanelGroup に登録されたレンダラー) を見つけられないことがわかるまで、これは私を夢中にさせました。

public class MyComponenten extends HtmlPanelGroup implements NamingContainer {

    public void encodeBeginn(FacesContext context){
        ...fill with components
        super.encodeBeginn(context);
    }
...
于 2012-07-03T13:27:39.963 に答える
0

明示的にidを指定し<h:form> て設定prependId=falseするh:form

于 2012-07-02T13:40:30.567 に答える