You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Fe...@t-systems.com on 2008/09/09 15:02:01 UTC

Generation strategy of the j_id prefixes?

Hi,

i'm currently writing JMeter tests for a web frontend generated with
myfaces. I tried to identify the input fields, buttons and drop downs
via their html id attribute. For example the id of one of my input
fields was: j_id36:inputContentText. After redeploying the application
the id changed to j_id42 - and my JMeter script broke.

In the same document the prefix of the id changes, too. So the id of an
input field at the beginning of the document begins with j_id36 and at
the end of the document the id of an button begins with j_id48:. 

How are this id's generated, is it possible to turn them off and is
there any spec which defines / explains the generation of this ids?

Thank you,

Felix Becker 

AW: Generation strategy of the j_id prefixes?

Posted by Fe...@t-systems.com.
Hi Marc,

i'm using fixed id's for the gui elements but i forgot to set ids for the used naming container. That caused ids with a random prefix (generated for the naming container).

Setting an id for every naming container solved my problem - winrunner and jmeter tests are working fine.

Felix

-----Ursprüngliche Nachricht-----
Von: Marc Schneider [mailto:marc.schneider73@gmail.com] 
Gesendet: Dienstag, 9. September 2008 18:56
An: MyFaces Discussion
Betreff: Re: Generation strategy of the j_id prefixes?

Hi,

Why don't you use a fixed id, like :
<h:commandButton id="updateButton" .../> ?

I use it for integration tests with Selenium and it works fine.

Marc.

Simon Lessard a écrit :
> Hi Felix,
> 
> I believe that it's controlled by the JSP 2.1 spec, but doesn't define
> the exact structure of the id. For instance, RI generates something like
> j_id__handler_XYZ. I'm really not an expert of that part of the
> specification so I may be wrong, but at least it gives you a place to
> start looking for an answer.
> 
> 
> Regards,
> 
> ~ Simon
> 
> On Tue, Sep 9, 2008 at 9:02 AM, <Felix.Becker@t-systems.com
> <ma...@t-systems.com>> wrote:
> 
>     Hi,
> 
>     i'm currently writing JMeter tests for a web frontend generated with
>     myfaces. I tried to identify the input fields, buttons and drop downs
>     via their html id attribute. For example the id of one of my input
>     fields was: j_id36:inputContentText. After redeploying the application
>     the id changed to j_id42 - and my JMeter script broke.
> 
>     In the same document the prefix of the id changes, too. So the id of an
>     input field at the beginning of the document begins with j_id36 and at
>     the end of the document the id of an button begins with j_id48:.
> 
>     How are this id's generated, is it possible to turn them off and is
>     there any spec which defines / explains the generation of this ids?
> 
>     Thank you,
> 
>     Felix Becker
> 
> 


Re: Generation strategy of the j_id prefixes?

Posted by Marc Schneider <ma...@gmail.com>.
Hi,

Why don't you use a fixed id, like :
<h:commandButton id="updateButton" .../> ?

I use it for integration tests with Selenium and it works fine.

Marc.

Simon Lessard a écrit :
> Hi Felix,
> 
> I believe that it's controlled by the JSP 2.1 spec, but doesn't define
> the exact structure of the id. For instance, RI generates something like
> j_id__handler_XYZ. I'm really not an expert of that part of the
> specification so I may be wrong, but at least it gives you a place to
> start looking for an answer.
> 
> 
> Regards,
> 
> ~ Simon
> 
> On Tue, Sep 9, 2008 at 9:02 AM, <Felix.Becker@t-systems.com
> <ma...@t-systems.com>> wrote:
> 
>     Hi,
> 
>     i'm currently writing JMeter tests for a web frontend generated with
>     myfaces. I tried to identify the input fields, buttons and drop downs
>     via their html id attribute. For example the id of one of my input
>     fields was: j_id36:inputContentText. After redeploying the application
>     the id changed to j_id42 - and my JMeter script broke.
> 
>     In the same document the prefix of the id changes, too. So the id of an
>     input field at the beginning of the document begins with j_id36 and at
>     the end of the document the id of an button begins with j_id48:.
> 
>     How are this id's generated, is it possible to turn them off and is
>     there any spec which defines / explains the generation of this ids?
> 
>     Thank you,
> 
>     Felix Becker
> 
> 


Re: Generation strategy of the j_id prefixes?

Posted by Simon Lessard <si...@gmail.com>.
Hi Felix,

I believe that it's controlled by the JSP 2.1 spec, but doesn't define the
exact structure of the id. For instance, RI generates something like
j_id__handler_XYZ. I'm really not an expert of that part of the
specification so I may be wrong, but at least it gives you a place to start
looking for an answer.


Regards,

~ Simon

On Tue, Sep 9, 2008 at 9:02 AM, <Fe...@t-systems.com> wrote:

> Hi,
>
> i'm currently writing JMeter tests for a web frontend generated with
> myfaces. I tried to identify the input fields, buttons and drop downs
> via their html id attribute. For example the id of one of my input
> fields was: j_id36:inputContentText. After redeploying the application
> the id changed to j_id42 - and my JMeter script broke.
>
> In the same document the prefix of the id changes, too. So the id of an
> input field at the beginning of the document begins with j_id36 and at
> the end of the document the id of an button begins with j_id48:.
>
> How are this id's generated, is it possible to turn them off and is
> there any spec which defines / explains the generation of this ids?
>
> Thank you,
>
> Felix Becker
>

AW: Generation strategy of the j_id prefixes?

Posted by Fe...@t-systems.com.
Hi Simon,

setting the id for every naming container worked perfect and solved my problem!

Thank you very much!

Felix Becker

-----Ursprüngliche Nachricht-----
Von: Simon Kitching [mailto:skitching@apache.org] 
Gesendet: Dienstag, 9. September 2008 15:26
An: MyFaces Discussion
Betreff: Re: Generation strategy of the j_id prefixes?

Hi Felix,

Felix.Becker@t-systems.com schrieb:
> Hi,
>
> i'm currently writing JMeter tests for a web frontend generated with
> myfaces. I tried to identify the input fields, buttons and drop downs
> via their html id attribute. For example the id of one of my input
> fields was: j_id36:inputContentText. After redeploying the application
> the id changed to j_id42 - and my JMeter script broke.
>
> In the same document the prefix of the id changes, too. So the id of an
> input field at the beginning of the document begins with j_id36 and at
> the end of the document the id of an button begins with j_id48:. 
>
> How are this id's generated, is it possible to turn them off and is
> there any spec which defines / explains the generation of this ids?
>   

When a component has no id assigned explicitly to it by the programmer, 
then the JSF framework assigns it an automatically-generated id, which 
may change. This is standard JSF behaviour, and not myfaces-specific.

A few components are "naming containers" which add their own id as a 
prefix to the ids of their child components, like the absolute filename 
of a file contains the name of the parent directories. Naming container 
components include h:form, h:subview and h:dataTable. This is also 
standard JSF behaviour, and not myfaces-specific.

In your example, there must be a few "naming container" components in 
the page, eg multiple forms or subviews. And the programmers of this app 
have not given fixed ids to these naming container components, so they 
get auto-assigned ids which their child components then inherit as their 
id prefix.

Therefore in situations like yours where you need fixed ids for certain 
elements then the programmers MUST:
(a) provide an explicit "id" attribute on each component which might be 
used in a unit test, and
(b) provide an explicit "id" attribute on each "naming container" component

In a project I worked on a few years ago, I wrote a small piece of code 
that was enabled during development to walk the jsf component tree at 
the end of each render phase, and log errors for components that did not 
have an explicit id. This was done specifically to allow the QA team to 
write Selenium scripts. The check was implemented as a JSF PhaseListener 
if I remember correctly. You might want to suggest that to the 
development team..

Regards,
Simon


Re: Generation strategy of the j_id prefixes?

Posted by Simon Kitching <sk...@apache.org>.
Hi Felix,

Felix.Becker@t-systems.com schrieb:
> Hi,
>
> i'm currently writing JMeter tests for a web frontend generated with
> myfaces. I tried to identify the input fields, buttons and drop downs
> via their html id attribute. For example the id of one of my input
> fields was: j_id36:inputContentText. After redeploying the application
> the id changed to j_id42 - and my JMeter script broke.
>
> In the same document the prefix of the id changes, too. So the id of an
> input field at the beginning of the document begins with j_id36 and at
> the end of the document the id of an button begins with j_id48:. 
>
> How are this id's generated, is it possible to turn them off and is
> there any spec which defines / explains the generation of this ids?
>   

When a component has no id assigned explicitly to it by the programmer, 
then the JSF framework assigns it an automatically-generated id, which 
may change. This is standard JSF behaviour, and not myfaces-specific.

A few components are "naming containers" which add their own id as a 
prefix to the ids of their child components, like the absolute filename 
of a file contains the name of the parent directories. Naming container 
components include h:form, h:subview and h:dataTable. This is also 
standard JSF behaviour, and not myfaces-specific.

In your example, there must be a few "naming container" components in 
the page, eg multiple forms or subviews. And the programmers of this app 
have not given fixed ids to these naming container components, so they 
get auto-assigned ids which their child components then inherit as their 
id prefix.

Therefore in situations like yours where you need fixed ids for certain 
elements then the programmers MUST:
(a) provide an explicit "id" attribute on each component which might be 
used in a unit test, and
(b) provide an explicit "id" attribute on each "naming container" component

In a project I worked on a few years ago, I wrote a small piece of code 
that was enabled during development to walk the jsf component tree at 
the end of each render phase, and log errors for components that did not 
have an explicit id. This was done specifically to allow the QA team to 
write Selenium scripts. The check was implemented as a JSF PhaseListener 
if I remember correctly. You might want to suggest that to the 
development team..

Regards,
Simon


Re: Generation strategy of the j_id prefixes?

Posted by Simon Kitching <sk...@apache.org>.
m4rkuz schrieb:
> Hi Everyone,
>
> I have a little big problem,  I got a CRUD like app, in the main form 
> I have a data table that shows the result of a query and every row has 
> a link to jump to the edit page, everything works fine, until I try to 
> go to the next page /*h:commandLink action="#{backingBean.edit}"  
> */with the selected row so I can edit it, the problems kicks in when I 
> remove a line of code that I have in the getObjectList method
> /* objectList = manager.findAll(); 
> */
> I remove it because I need that the main page doesn't show anything 
> until the search button is clicked, after this modification the links 
> stop working, I cannot get to the nex page, in Debug mode I see I 
> don't even get to the edit() methond in the backing bean, is like the 
> bean is recreated before the action of the h:commandLink kicks and 
> then the table data and the row are null so they don't fire any event :S
>
> The BackingBean scope is Request (it work with session scope but I 
> don't think is necesary to hold on that bean for a whole session )

When you have input fields or commandlinks within a table, then on 
postback the backing bean needs to have the table's datamodel available, 
ie the value attribute of the datatable has to return the same list of 
objects.

Reloading the table from the database does work in some cases (your 
getObjectList method), as long as it always returns the same objects 
that were present when the table was rendered, ie the data in the table 
is *static*.  But in most cases this is not true, ie the number of 
matching "rows" in the database might change. In this case you just 
cannot use request-scoped backing beans with tables that have input 
fields or commandlinks in them.

Your options are to use session scope, or use one of the "conversation 
scope" implementations available, or to not have tables with command or 
input components. Or *if* your manager.findAll method always returns the 
same results, then put it back in.

Regards,
Simon


Re: Generation strategy of the j_id prefixes?

Posted by Matthias Wessendorf <ma...@apache.org>.
Hello Marcus,

I am not sure I understand why you posted your mail to this thread.
I think a new thread is more sufficient... ?

-M

On Tue, Sep 9, 2008 at 7:09 AM, m4rkuz <m4...@gmail.com> wrote:
> Hi Everyone,
>
> I have a little big problem,  I got a CRUD like app, in the main form I have
> a data table that shows the result of a query and every row has a link to
> jump to the edit page, everything works fine, until I try to go to the next
> page h:commandLink action="#{backingBean.edit}"  with the selected row so I
> can edit it, the problems kicks in when I remove a line of code that I have
> in the getObjectList method
>  objectList = manager.findAll();
> I remove it because I need that the main page doesn't show anything until
> the search button is clicked, after this modification the links stop
> working, I cannot get to the nex page, in Debug mode I see I don't even get
> to the edit() methond in the backing bean, is like the bean is recreated
> before the action of the h:commandLink kicks and then the table data and the
> row are null so they don't fire any event :S
>
> The BackingBean scope is Request (it work with session scope but I don't
> think is necesary to hold on that bean for a whole session )
> and I have try with <f:param ,   <f:attribute,
> <f:setPropertyActionListener  all works untill I remove that line....
>
>
> What Can I do??
>
> Code below..
>                                 <t:dataTable id="perfilesTable" width="100%"
> border="0" rows="20"
>                                     cellpadding="5" cellspacing="1"
> value="#{backingBean.objectList}"
>                                     var="selectedRow" rowClasses="row1,
> row2"   headerClass="tableHead">
>                                     <t:column>
>                                            <f:facet name="header">
>                                                   <h:outputText
> value="Perfiles"/>
>                                             </f:facet>
>                                                 <h:commandLink
> action="#{backingBean.edit}" value="#{selectedRow.name}"
> actionListener="#{backingBean.editAction}">
>                                                     <f:attribute
> name="attributeName1" value="#{selectedRow}" />
>                                                 </h:commandLink>
>                                     </t:column>
>                                     <t:column>
>                                         <f:facet name="header">
>                                                 <h:outputText
> value="Active"/>
>                                         </f:facet>
>                                         <h:outputText
> value="#{selectedRow.active}"/>
>                                     </t:column>
>                                 </t:dataTable>
>
>
> Cordialmente,
>
>
> Marcus V. Sánchez D.
> ______________________
> Enterprise Developer.
> Sun Certified Java Programmer (SCJP)
>



-- 
Matthias Wessendorf

blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
twitter: http://twitter.com/mwessendorf

Re: Generation strategy of the j_id prefixes?

Posted by m4rkuz <m4...@gmail.com>.
Hi Everyone,

I have a little big problem,  I got a CRUD like app, in the main form I have
a data table that shows the result of a query and every row has a link to
jump to the edit page, everything works fine, until I try to go to the next
page *h:commandLink action="#{backingBean.edit}"  *with the selected row so
I can edit it, the problems kicks in when I remove a line of code that I
have in the getObjectList method
* objectList = manager.findAll();
*
I remove it because I need that the main page doesn't show anything until
the search button is clicked, after this modification the links stop
working, I cannot get to the nex page, in Debug mode I see I don't even get
to the edit() methond in the backing bean, is like the bean is recreated
before the action of the h:commandLink kicks and then the table data and the
row are null so they don't fire any event :S

The BackingBean scope is Request (it work with session scope but I don't
think is necesary to hold on that bean for a whole session )
and I have try with* <f:param* ,   *<f:attribute*,  *
<f:setPropertyActionListener*  all works untill I remove that line....


*What Can I do??*

Code below..
*                                <t:dataTable id="perfilesTable"
width="100%" border="0" rows="20"
                                    cellpadding="5" cellspacing="1"
value="#{backingBean.objectList}"
                                    var="selectedRow" rowClasses="row1,
row2"   headerClass="tableHead">
                                    <t:column>
                                           <f:facet name="header">
                                                  <h:outputText
value="Perfiles"/>
                                            </f:facet>
                                                <h:commandLink
action="#{backingBean.edit}" value="#{selectedRow.name}"
actionListener="#{backingBean.editAction}">
                                                    <f:attribute
name="attributeName1" value="#{selectedRow}" />
                                                </h:commandLink>
                                    </t:column>
                                    <t:column>
                                        <f:facet name="header">
                                                <h:outputText
value="Active"/>
                                        </f:facet>
                                        <h:outputText
value="#{selectedRow.active}"/>
                                    </t:column>
                                </t:dataTable>
*

Cordialmente,


Marcus V. Sánchez D.
______________________
Enterprise Developer.
Sun Certified Java Programmer (SCJP)