myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "forceId" by Jan Dockx
Date Mon, 19 Sep 2005 07:54:54 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by Jan Dockx:
http://wiki.apache.org/myfaces/forceId

New page:
Sometimes, developers want to read HTTP request parameters directly in their code. They would
be the result of a HTTP POST, from a page generated by JSF. The parameter the developer is
interested in would probably be generated by a {{{<h:inputHidden ...}}} or another input
field.

The problem these developers are confronted with is that the actual name in the HTTP POST
of the HTTP request parameter they are interested in, is difficult to control. The rendered
input field has an {{{id}}} and {{{name}}} that is often generated, or at least modified,
by JSF. JSF components use ''naming contexts'' to make them unique in a page. Suppose the
input field with id {{{myRequestParamName}} is used in a form, with id {{{myForm}}}, which
is used inside a panel group with id {{{scope1}}}, which is used inside an {{{t:div}}} with
id {{{scope0}}}, etc.
{{{
  ...
  <t:div id="scope0" ... >
    ...
    <h:panelGroup id="scope1" ... >
      ...
      <h:form id="myForm" ...>
        ...
        <t:inputHidden id="myRequestParamName" forceId="true"  ... />
        ...
      </h:form>
      ...
    </h:panelGroup>
    ...
  </t:div>
  ...
}}}
The actual name of the HTTP request parameter we are interested in is than: {{{scope0:scope1:myForm:myRequestParamName}}}.
The slightest change in the layout of the page changes the actual name.

The extended standard components you find in Tomahawk feature an extra attribute {{{forceId}}}.
If this is set to {{{true}}}, the naming contexts will not be used, but the actual value of
the id you have given will be the id of the component.

So, the code
{{{
  ...
  <t:div id="scope0" ... >
    ...
    <h:panelGroup id="scope1" ... >
      ...
      <h:form id="myForm" ...>
        ...
        <t:inputHidden id="myRequestParamName" forceId="true"  ... />
        ...
      </h:form>
      ...
    </h:panelGroup>
    ...
  </t:div>
  ...
}}}
will result in a HTML hidden input tage in the generated page with id and name {{{myRequestParamName}}}

Obviously, the burden then falls on your shoulders to make sure that the id is unique in the
page, also considering included files or tiles.

Mime
View raw message