システム開発で思うところ

Javaで主にシステム開発をしながら思うところをツラツラを綴る。主に自分向けのメモ。EE関連の情報が少なく自分自身がそういう情報があったら良いなぁということで他の人の参考になれば幸い

JSFのIDあれこれ

JSFで生成されるidあれこれ - Challenge Java EE !

に加えて pass throughを実際に使ってみた実装サンプル

目的は JSFが生成するidnameについて確認する事。

定義

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:jsf="http://xmlns.jcp.org/jsf"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:pt="http://xmlns.jcp.org/jsf/passthrough">
    <head>
        <title>JSF ID</title>
    </head>
    <body>
        <h1>Id</h1>

        <h:form>
            <div jsf:id="jsfId" pt:id="ptId10" id="divId">
                jsfIdあり、passthroughIdあり、Idあり=passthroughIdが適用
            </div>
        </h:form>

        <h:form>
            <div jsf:id="jsfId" id="divId">
                jsfIdあり、passthroughIdなし、Idあり=divIdが適用
            </div>
        </h:form>

        <h:form>
            <div jsf:id="jsfId">
                jsfIdあり、passthroughIdなし、Idなし=jsfIdが適用(ルートは自動生成)
            </div>
        </h:form>



        <p>input type="text"</p>

        <h:form>
            <input type="text" jsf:id="jsfId" pt:id="ptId10" id="divId" value="jsfIdあり、passthroughIdあり、Idあり=passthroughIdが適用"  style="width:400px" />
        </h:form>

        <h:form>
            <input type="text" jsf:id="jsfId" id="divId" value="jsfIdあり、passthroughIdなし、Idあり=divIdが適用"  style="width:400px" />
        </h:form>

        <h:form>
            <input type="text" jsf:id="jsfId" value="jsfIdあり、passthroughIdなし、Idなし=jsfIdが適用(ルートは自動生成)"  style="width:500px" />
        </h:form>



        <p>h:inputText</p>

        <h:form>
            <h:inputText id="jsfId" pt:id="ptId10" value="jsfIdあり、passthroughIdあり=passthroughIdが適用" style="width:400px"/>
        </h:form>

        <h:form>
            <h:inputText id="jsfId"  value="jsfIdあり、passthroughIdなし=jsfIdが適用(ルートは自動生成)"  style="width:400px" />
        </h:form>



    </body>
</html>

生成後のxhtmlのコード

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>JSF ID</title>
    </head>
    <body>
        <h1>Id</h1>
        <form id="j_idt2" name="j_idt2" method="post" action="/jsf-id/index.xhtml" enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="j_idt2" value="j_idt2" />
            <div id="ptId10">
                jsfIdあり、passthroughIdあり、Idあり=passthroughIdが適用
            </div>
            <input type="hidden" name="javax.faces.ViewState" id="j_id1-javax.faces.ViewState-0" value="-6059247821844920063:3663652348388936230" autocomplete="off" />
        </form>
        <form id="j_idt4" name="j_idt4" method="post" action="/jsf-id/index.xhtml" enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="j_idt4" value="j_idt4" />
            <div id="divId">
                jsfIdあり、passthroughIdなし、Idあり=divIdが適用
            </div>
            <input type="hidden" name="javax.faces.ViewState" id="j_id1-javax.faces.ViewState-1" value="-6059247821844920063:3663652348388936230" autocomplete="off" />
        </form>
        <form id="j_idt6" name="j_idt6" method="post" action="/jsf-id/index.xhtml" enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="j_idt6" value="j_idt6" />
            <div id="j_idt6-jsfId">
                jsfIdあり、passthroughIdなし、Idなし=jsfIdが適用(ルートは自動生成)
            </div>
            <input type="hidden" name="javax.faces.ViewState" id="j_id1-javax.faces.ViewState-2" value="-6059247821844920063:3663652348388936230" autocomplete="off" />
        </form>



        <p>input type="text"</p>
        <form id="j_idt9" name="j_idt9" method="post" action="/jsf-id/index.xhtml" enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="j_idt9" value="j_idt9" />
            <input name="j_idt9-jsfId" style="width:400px" id="ptId10" type="text" value="jsfIdあり、passthroughIdあり、Idあり=passthroughIdが適用" />
            <input type="hidden" name="javax.faces.ViewState" id="j_id1-javax.faces.ViewState-3" value="-6059247821844920063:3663652348388936230" autocomplete="off" />
        </form>
        <form id="j_idt10" name="j_idt10" method="post" action="/jsf-id/index.xhtml" enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="j_idt10" value="j_idt10" />
            <input name="j_idt10-jsfId" style="width:400px" id="divId" type="text" value="jsfIdあり、passthroughIdなし、Idあり=divIdが適用" />
            <input type="hidden" name="javax.faces.ViewState" id="j_id1-javax.faces.ViewState-4" value="-6059247821844920063:3663652348388936230" autocomplete="off" />
        </form>
        <form id="j_idt11" name="j_idt11" method="post" action="/jsf-id/index.xhtml" enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="j_idt11" value="j_idt11" />
            <input id="j_idt11-jsfId" name="j_idt11-jsfId" style="width:500px" type="text" value="jsfIdあり、passthroughIdなし、Idなし=jsfIdが適用(ルートは自動生成)" />
            <input type="hidden" name="javax.faces.ViewState" id="j_id1-javax.faces.ViewState-5" value="-6059247821844920063:3663652348388936230" autocomplete="off" />
        </form>



        <p>h:inputText</p>
        <form id="j_idt13" name="j_idt13" method="post" action="/jsf-id/index.xhtml" enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="j_idt13" value="j_idt13" />
            <input type="text" name="j_idt13-jsfId" value="jsfIdあり、passthroughIdあり=passthroughIdが適用" style="width:400px" id="ptId10" />
            <input type="hidden" name="javax.faces.ViewState" id="j_id1-javax.faces.ViewState-6" value="-6059247821844920063:3663652348388936230" autocomplete="off" />
        </form>
        <form id="j_idt14" name="j_idt14" method="post" action="/jsf-id/index.xhtml" enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="j_idt14" value="j_idt14" />
            <input id="j_idt14-jsfId" type="text" name="j_idt14-jsfId" value="jsfIdあり、passthroughIdなし=jsfIdが適用(ルートは自動生成)" style="width:400px" />
            <input type="hidden" name="javax.faces.ViewState" id="j_id1-javax.faces.ViewState-7" value="-6059247821844920063:3663652348388936230" autocomplete="off" />
        </form>



    </body>
</html>