On 1/6/06, Simon Kitching <[EMAIL PROTECTED]> wrote:
I also dislike the "forceId" function. It's not a good solution IMHO,
because it merges the concepts of HTML ids and JSF ids, thus losing the
abiility to safely compose pages from JSF fragments.

I have been vaguely thinking about solutions for this, esp. as the AJAX
components seem to currently be heavily dependent on the forceId. The
idea isn't completely thought through, but as the thread is currently on
discussion I'll toss it out there for consideration.

How about creating a new tomahawk component t:jsid:
  <h:form id="theForm">
    <h:inputText id="theInput" value="#{bean.inputValue}"/>
    <t:jsid for="" obj="jsIds" id="myInputComponent"/>
  </h:form>

Where the t:jsid component's rendering simply stores away a reference to
the component in the current request. At page end (just before </html>)
the following is then output:

<script>
  var jsIds = new Object();
  jsIds.myInputComponent = document.getElementById('theForm:theInput');
  // repeat above line for each t:jsId component
</script>

_javascript_ can then access any JSF component which has an associated
t:jsid component like:
  jsIds.myInputComponent = "some-value";

Wouldn't it be better all around to just deal with the fact that JSF components in general will emit client ids unchanged, and design your support functions to deal with them?

Let's say you have a function that does something to your autoComplete component, and you want the renderer to call that method (passing it the component it's now rendering).  I'd code the function like this:

    function doSomething(clientId) {
        var autoComplete = document.getElementById(clientId);
        ... do something to the "autoComplete" object ...
    }

and just have my renderer emit the appropriate call:

    writer.writeText("  doSomething('" + component.getClientId(context) + "');\n", null);

Or, if the function takes an object instead:

    function doSomething(auto) {
        ... do something to the "autoComplete" object ...
    }

then emit the code that does the lookup:

    writer.writeText("  doSomething(document.getElementById('" + component.getClientId(context) + "');\n", null);

This way, you don't need any sort of artificial translation layer, and your _javascript_ will work with JSF components that were not designed with a "forceId" attribute (such as the JSF standard components).

Regards,

Simon

Craig
 

Reply via email to