You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Heath Borders <he...@gmail.com> on 2005/01/03 23:10:48 UTC

design

Here is the JSP and rendering hints I was thinking about for the
<x:script /> tag.

JSP Example:

<h:inputText id="myInputText" value="#{bean.text}" />
<x:script language="javascript" type="text/javascript">
<x:scriptParameter for="myInputText" id="p_myInputText" />
function disableMyInputText()
{
  var input = document.getElementById('p_myInputText');
  input.disabled=true;
}
</x:script>


The language and type attributes would be optional, and default to
"javascript" and "text/javascript" respectively.

The scriptParameter would use the UIComponent.findComponent(String)
method to find a component within the current namingContainer with the
given id.  The <x:script> tag would then search its bodyContent for
any strings matching the <x:scriptParameter> id's and replace them
with the clientId of the UIComponent from the <x:scriptParameter> for
attribute.

This would be a simple way to include javascript (and appropriate code
commenting and <noscript> tags for non-javascript browsers) in JSF
code.

I'd appreciate any input on this design.

-- 
-Heath Borders-Wing
hborders@mail.win.org

Re: design

Posted by Sean Schofield <se...@gmail.com>.
> Surrounding it with dollar signs should make the template code
> editable in an existing javascript IDE, right?

I would suggest Craig's other choice of @@ instead of $.  This would
eliminate any potential confusion about whether the $ is related to an
EL expression.

> As for the dataTable issues, I would say that that would just have to
> be a limitation of the tag.  If you can't assign an id to the
> UIComponent within the same namingcontainer as your <x:script>, then
> you just can't use it.  In this case, you would have to include your
> javascript within a custom component that is not reliant on an id.

I think this answers one of the questions I just asked.  You will only
be able to use this if the javascript is in the same naming container
as your component.  I guess this means that you cannot have your
javascript in a separate page from your component then (ex.
scripts/foo.js) unless you do a static include ...

As for the UIData issue, perhaps this could be solved by approach #2?

sean

Re: design

Posted by Heath Borders <he...@gmail.com>.
Ok, so how about combining the two together:

<x:script language="javascript" type="text/javascript">
<x:scriptParameter for="myInputText" />
function disableMyInputText()
{
 var input = document.getElementById('$myInputText$');
 input.disabled=true;
}
</x:script>

Surrounding it with dollar signs should make the template code
editable in an existing javascript IDE, right?

As for the dataTable issues, I would say that that would just have to
be a limitation of the tag.  If you can't assign an id to the
UIComponent within the same namingcontainer as your <x:script>, then
you just can't use it.  In this case, you would have to include your
javascript within a custom component that is not reliant on an id.


On Mon, 03 Jan 2005 14:35:46 -0800, Travis Reeder
<tr...@ecommstats.com> wrote:
> I like it, but for simplicity's sake if the x:script is going to replace
> matching id strings, then I don't see the need for having the for and
> the id.  Why not just the for like so:
> 
> <x:script language="javascript" type="text/javascript">
> <x:scriptParameter for="myInputText" />
> function disableMyInputText()
> {
>  var input = document.getElementById('myInputText');
>  input.disabled=true;
> }
> </x:script>
> 
> 
> Travis
> 
> Heath Borders wrote:
> 
> >Here is the JSP and rendering hints I was thinking about for the
> ><x:script /> tag.
> >
> >JSP Example:
> >
> ><h:inputText id="myInputText" value="#{bean.text}" />
> ><x:script language="javascript" type="text/javascript">
> ><x:scriptParameter for="myInputText" id="p_myInputText" />
> >function disableMyInputText()
> >{
> >  var input = document.getElementById('p_myInputText');
> >  input.disabled=true;
> >}
> ></x:script>
> >
> >
> >The language and type attributes would be optional, and default to
> >"javascript" and "text/javascript" respectively.
> >
> >The scriptParameter would use the UIComponent.findComponent(String)
> >method to find a component within the current namingContainer with the
> >given id.  The <x:script> tag would then search its bodyContent for
> >any strings matching the <x:scriptParameter> id's and replace them
> >with the clientId of the UIComponent from the <x:scriptParameter> for
> >attribute.
> >
> >This would be a simple way to include javascript (and appropriate code
> >commenting and <noscript> tags for non-javascript browsers) in JSF
> >code.
> >
> >I'd appreciate any input on this design.
> >
> >
> >
> 
> -- 
> Travis Reeder
> Ecommstats Web Analytics
> www.ecommstats.com
> 
> 


-- 
-Heath Borders-Wing
hborders@mail.win.org

Re: design

Posted by Sean Schofield <se...@gmail.com>.
Heath,

Now that I have read your proposal again, it is starting to grow on
me.  I would also agree with the change Travis suggested (one less
thing to worry about.)

Just so I understand you.  Whenever the <x:scriptParameter> tag is
encountered, the tag is going to replace references to the "for"
attribute in the enclosed text and replace it with the JSF determined
id to the component right?

A few questions for you on how this would work.  The first is, how
would the script tag be able to find the component in the tree (in
order to get its generated it)?  Is it assumed that the script would
be "coupled" to the component?

sean

Re: design

Posted by Travis Reeder <tr...@ecommstats.com>.
I like it, but for simplicity's sake if the x:script is going to replace 
matching id strings, then I don't see the need for having the for and 
the id.  Why not just the for like so:

<x:script language="javascript" type="text/javascript">
<x:scriptParameter for="myInputText" />
function disableMyInputText()
{
  var input = document.getElementById('myInputText');
  input.disabled=true;
}
</x:script>



Travis

Heath Borders wrote:

>Here is the JSP and rendering hints I was thinking about for the
><x:script /> tag.
>
>JSP Example:
>
><h:inputText id="myInputText" value="#{bean.text}" />
><x:script language="javascript" type="text/javascript">
><x:scriptParameter for="myInputText" id="p_myInputText" />
>function disableMyInputText()
>{
>  var input = document.getElementById('p_myInputText');
>  input.disabled=true;
>}
></x:script>
>
>
>The language and type attributes would be optional, and default to
>"javascript" and "text/javascript" respectively.
>
>The scriptParameter would use the UIComponent.findComponent(String)
>method to find a component within the current namingContainer with the
>given id.  The <x:script> tag would then search its bodyContent for
>any strings matching the <x:scriptParameter> id's and replace them
>with the clientId of the UIComponent from the <x:scriptParameter> for
>attribute.
>
>This would be a simple way to include javascript (and appropriate code
>commenting and <noscript> tags for non-javascript browsers) in JSF
>code.
>
>I'd appreciate any input on this design.
>
>  
>

-- 
Travis Reeder
Ecommstats Web Analytics
www.ecommstats.com


Re: design

Posted by Craig McClanahan <cr...@gmail.com>.
How would something like this work inside, say, <h:dataTable>?  Or
maybe that's the place you decide to draw a line on what is being
supported?

Also, you might want to consider reducing potential ambiguitties a
little by surrounding the replacement text with "$...$" or "@...@"
(the latter is what Ant uses, for example).

Craig



On Mon, 3 Jan 2005 16:10:48 -0600, Heath Borders
<he...@gmail.com> wrote:
> Here is the JSP and rendering hints I was thinking about for the
> <x:script /> tag.
> 
> JSP Example:
> 
> <h:inputText id="myInputText" value="#{bean.text}" />
> <x:script language="javascript" type="text/javascript">
> <x:scriptParameter for="myInputText" id="p_myInputText" />
> function disableMyInputText()
> {
>   var input = document.getElementById('p_myInputText');
>   input.disabled=true;
> }
> </x:script>
> 
> The language and type attributes would be optional, and default to
> "javascript" and "text/javascript" respectively.
> 
> The scriptParameter would use the UIComponent.findComponent(String)
> method to find a component within the current namingContainer with the
> given id.  The <x:script> tag would then search its bodyContent for
> any strings matching the <x:scriptParameter> id's and replace them
> with the clientId of the UIComponent from the <x:scriptParameter> for
> attribute.
> 
> This would be a simple way to include javascript (and appropriate code
> commenting and <noscript> tags for non-javascript browsers) in JSF
> code.
> 
> I'd appreciate any input on this design.
> 
> --
> -Heath Borders-Wing
> hborders@mail.win.org
>