also problems with myfaces/tomahawk command links in datatab
merlin-hst Jun 12, 2008 2:19 PMHi,
after reading this post http://www.jboss.com/index.html?module=bb&op=viewtopic&t=136815 I've used the current sources from svn to click a myfaces/tomahawk command link in a datatable. What makes me wonder, that jsfunit seems to find the right component but I can't click it. Here's a simple example:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:t="http://myfaces.apache.org/tomahawk"> <t:dataTable ... <t:column> <t:commandLink forceId="true" forceIdIndex="true" id="plantName_1" rendered="true"/></t:column> <t:column> <t:commandLink forceId="true" forceIdIndex="true" id="plantName_2" rendered="false"/></t:column> ... </t:dataTable
The html output looks like:
<a href="#" onclick="return oamSubmitForm('f','plantName_2[0]');" id="plantName_2[0]">1017394342537</a> <a href="#" onclick="return oamSubmitForm('f','plantName_2[1]');" id="plantName_2[1]">1017395465464</a>
My test looks like :
jsfSession = new JSFSession("/faces/presentation/login.xhtml"); client = jsfSession.getJSFClientSession(); server = jsfSession.getJSFServerSession(); ... doLogin(); .. assertEquals("/presentation/plant_selection.xhtml", server.getCurrentViewID()); UIComponent component1 = server.findComponent("plantName_2[0]"); assertNotNull(component1); assertTrue(component1 instanceof HtmlCommandLink); assertTrue(component1.isRendered()); HtmlCommandLink link1 = (HtmlCommandLink)component1; client.click(link1.getId());
This causes the following exception:
org.jboss.jsfunit.jsfsession.ComponentIDNotFoundException: No component ID was found for plantName_2 org.jboss.jsfunit.jsfsession.ClientIDs.findClientID(ClientIDs.java:172) org.jboss.jsfunit.jsfsession.JSFClientSession.getElement(JSFClientSession.java:197) org.jboss.jsfunit.jsfsession.JSFClientSession.click(JSFClientSession.java:153)
But
assertTrue(component1.getId().equals("plantName_2[0]"));returns false, because component1.getId() returns "plantName_2".
If I don't use forceId or change t:commandLink to h:commandLink the html output looks like
<a href="#" onclick="return oamSubmitForm('f','f:plant_selection_data:0:j_id94');" id="f:plant_selection_data:0:j_id94">1017394342537 <a href="#" onclick="return oamSubmitForm('f','f:plant_selection_data:1:j_id94');" id="f:plant_selection_data:1:j_id94">1017395465464
But now I'm having another problem: server.findComponent() returns a value (not null) but getId() returns j_id94 instead of f:plant_selection_data:0:j_id94.
Without "validating the id with assert I'm getting this exception:
org.jboss.jsfunit.jsfsession.DuplicateClientIDException: j_id94 matches more than one JSF component ID. Use a more specific ID suffix. Suffix matches: f:plant_selection_data:0:j_id94 .. org.jboss.jsfunit.jsfsession.ClientIDs.findClientID(ClientIDs.java:174) org.jboss.jsfunit.jsfsession.JSFClientSession.getElement(JSFClientSession.java:197) org.jboss.jsfunit.jsfsession.JSFClientSession.click(JSFClientSession.java:153) com.conergy.sunreader.web.PlantDataJSFTest.testPlantDataChangeExtended(PlantDataJSFTest.java:43)
I'm also using the latest httpunit and htmlunit versions. So what's wrong here ?
Thanks, Lothar