Struts bean cannot be found - struts

I'm having a problem with Struts. It's not recognizing a bean, even though it's defined one line above
I have this code
<logic:iterate id="com" name="Handler" property="commandList">
23: <optgroup id="${com.id}" style="display:none;">
24: <logic:iterate id="rem" name="com" property="remotes">
25: <option value="${rem.id}"><bean:write name="rem" property="name"/></option>
26: </logic:iterate>
27: </optgroup>
28: </logic:iterate>
and I get the following error in line 25:
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "rem" in any scope
Which does not make sense, because the bean is defined just above on line 24
Any ideas?
Thanks

As you state, the syntax of your code is correct. My guess is that one of the remotes bean's object is a null value. In that case, according to struts1 reference :
If the collection you are iterating over can contain null values, the
loop will still be performed but no page scope attribute (named by the
id attribute) will be created for that loop iteration. You can use the
<logic:present> and <logic:notPresent> tags to test for this case.
The <bean:write name="rem" property="name"/> tag will be executed, but rem won't exist in any scope. Check for null values in your Array/List/Map/etc remotes, or add a test using the <logic:present> tag.

Related

find element by xpath with contains(node()) AND contains(#attribute)

I'm trying to locate an element by checking innerHTML (property node()) and some attribute (e.g. #class).
Both methods works separately but I can't combine them with "and"
HTML part:
<tr class="tableRow1">
<td nowrap="" class="ct">
<input type="CheckBox" name="RowKey" tabindex="17" value="15635">
<img src="/tm/images/1pixel.gif" style="height:9px;width:9px;border:0" name="RowIndicator">
</td>
<td class="lt" title="ID">XXXXX</td><nobr>0021234567</nobr><td class="rt">1.00</td>
</tr>
So I need to locate this node of class="tableRow1" (from many others) by catching this part:
<nobr>002123456</nobr>.
This two works (but catching several elements):
.find_element_by_xpath('//tr[contains(node(), "0021234567")]')
.find_element_by_xpath('//tr[contains(#class, "Row")]')
This one doesn't:
.find_element_by_xpath('//tr[contains(node(),"0021234567") and contains(#class,"Row")]')
Try this XPath-1.0 expression:
descendant::*[contains(node(), "0021234567")]/ancestor::tr[contains(#class, "Row")][1]
or in a complete instruction
.find_element_by_xpath('descendant::*[contains(node(), "0021234567")]/ancestor::tr[contains(#class, "Row")][1]')
This instruction selects the first tr ancestor - which has a class attribute which contains the value Row - of a (global) node() which contains the value 0021234567.
Your two XPath selectors are selecting different nodes.
The node that contains the string is a descendant of the <tr> node with the class name. That is why when you are putting both conditions for one node it doesn't find any matching node.
Try this:
.find_element_by_xpath('//[contains(node(), "0021234567")]/ancestor::tr[contains(#class), "Row"]')
To locate the <tr> nodes which contains the child <nobr> nodes you can use the following solution:
driver.find_element_by_xpath("//nobr//ancestor::tr[contains(#class, 'Row')]")
Note: It is assumed that the innerText within the <nobr> is a variable else the innerText can be included within the XPath expression as well.
So I need to locate this node of class="tableRow1" (from many
others) by catching this part:
<nobr>002123456</nobr>
The XPath expression should be:
//tr[#class='tableRow1'][.//nobr='002123456']
That is the basic. Then you could adjust that to your situation.
Example 1 (many posible classes tokens):
//tr[contains(concat(' ',#class,' '),' tableRow1 ')][.//nobr='002123456']
Example 2 (posible white space in nobr):
//tr[contains(concat(' ',#class,' '),' tableRow1 ')]
[.//nobr[normalize-space()='002123456']]
Example 3 (class token starts with 'tableRow'):
//tr[contains(concat(' ',#class,' '),' tableRow')]
[.//nobr[normalize-space()='002123456']]

Element '<t t-if="...">' cannot be located in parent view

I am trying to customize a report in Odoo 11. I am modifying an XML file, but I am getting this error:
File "/home/omar/odoo/odoo11/odoo/models.py", line 3094, in write
self._write(old_vals)
File "/home/omar/odoo/odoo11/odoo/models.py", line 3260, in _write
self._validate_fields(vals)
File "/home/omar/odoo/odoo11/odoo/models.py", line 1041, in _validate_fields
raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Error while validating constraint
Element '<t t-if="caseacocher">' cannot be located in parent view
Error context:
View `report_quotation_inherit_demo`
[view_id: 714, xml_id: moduletest.report_quotation_inherit_demo, model: n/a, parent_id: 637]
None" while parsing None:14, near
<data inherit_id="sale.report_saleorder_document">
Go Settings, select User Interface, and then Views. Enter in search field the following view: report_saleorder_document. Is a Qweb Type (report).
So, you are trying to inherit from this view and that t-if="caseacocher" can't be located here in parent view (report_saleorder_document). You are missing an xpath.
Where do you want to locate this in parent view? You will need to open this view and find something else from here that you can use in your module instead of that t-if. It must be exist here in parent view!
I suggest you to use xpath to find an expression and then put this condition.
For example, if div has a class named page, then you could use something like:
<xpath expr="//div[#class='page']" position="inside">
<t t-if="caseacocher">
<!--etc what ever you want put here-->
</t>
</xpath>
This is just an example, but you can then use your t-if inside the xpath.
Good luck.

XPath related questions to locate elements in Webdriver 2 Java

Dear Selenium Webdriver 2 Experts,
I am new to this framework and need your advice on some XPath related questions on the following webpage XHTML snippet:
<dl class="cN-featDetails">
<dt class="propertytype">Property type</dt>
<!-- line 3 --> <dd id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_ddPropertyType" class="propertytype type-house" title="Property type: House">House</dd>
<!-- line 3a --> <!-- or class="propertytype type-townhouse"--->
.......
<div class="main-wrap">
<div class="s-prodDetails">
<a id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_hypMainThumb" class="photo contain" href="/Property/For-Sale/House/LA/St Gabriel/?adid=2009938763">img id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_imgMainThumb" title="44 Crown Street, St Gabriel" src="http://images.abc.com/img/2012814/2778/2009938763_1_PM.JPG?mod=121010-210000" alt="Main photo of 44 Crown Street, St Gabriel - More Details" style="border-width:0px;" /></a>
<div class="description">
<h4><span id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_lblPrice">Offers Over $900,000 </span></h4>
<h5>SOLD BY WAISE YUSOFZAI</h5><p>CHARACTER FAMILY HOME... Filled with warmth and charm, is a very well maintained family home in a quiet level street. Be...</p>
</div>
<a id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_hypMoreDetails" class="button" href="/Property/For-Sale/House/LA/St Gabriel/?adid=2009938763">More Details</a>
<dl id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_dlAgent" class="agent">
<!-- line 19 --> <dt>Advertiser</dt>
<!-- line 20 --> <dd class="contain">
<!-- line 20a --> <!-- or class="" -->
<img id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_imgAgencyLogo" title="Carmen Jones Realty" src="http://images.abc.com/img/Agencys/2778/searchlogo_2778.GIF" style="border-width:0px;" />
</dd>
</dl>
</div>
( a ) How to test whether an element exist or not? e.g. either line 3 or 3a exist but not both. The findElement() method will cause an exception which is what I am trying avoid. Another option is
use findElements() before checking whether its collection list result is empty or not. This approach seems to be a long winded way of doing it. Are there any other simpler way to validate the existence
of an element without the risk of causing an exception? The following statements did not work or cause exception:
WebElement resultsDiv = driver.findElement(By.xpath("/html/body/form/div[3]/div[2]/div[1]/h1/em"));
// If results have been returned, the results are displayed in a drop down.
if (resultsDiv.isDisplayed()) {
break;
}
( b ) Is there a simple way to validate the existence of either of the elements by incorporating boolean operator, and regex, as part of the findElement() or findElements()? This would significantly reduce
the number of finds as well as simplifying the search.
( c ) Is it possible to use XPath syntax when searching Element by TagName. e.g. driver.findElement(By.tagName("/div[#class='report']/result"));
( d ) Is it possible to use regex in XPath search such as driver.findElement(By.xpath("//div[#class='main-wrap']/dl[#class='agent']/dd[#class='' OR #class='contain']")) for line 20 - 20a?
( e ) How to reference the immediate following node? e.g. Assuming the current node is Advertiser on line 19, how to lookup title of which is under , where its class name
can have a value of "contain" or nothing "". There could potentially be multiple tags within on line 18.
I have use XPath on XML document in the past but would like to expand the ability to locate elements within Webdriver 2.
Any assistance would be very greatful.
Thanks a lot,
Jack
considering the answer given by Zarkonnen, i'd add to (a) point
public boolean isElementPresent(By selector)
{
return driver.findElements(selector).size()>0;
}
this method i use for verifying that element is present on the page.
you can also involve isDisplayed() method that can work in pair with isElement is present:
driver.findElement(By locator).isDisplayed()
Returning back to your source:
Suppose we want to verify wheter 'More details' links is present on the page or not.
String cssMoreDetails = "a[id='ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_hypMoreDetails']";
//and you simply call the described above method
isElementPresent(By.cssSelector(cssMoreDetails));
//if you found xPath then it be
isElementPresent(By.xpath("//*..."));
And always try to verify found web elements' locators in firepath
In that way you can get xPath of the elment automatically. See the screen attached.
(a) & (d): You can use the | XPath operator to specify two alternate paths in the same expression.
(c): You can't use XPath in byTagName, but you can use // to look for any descendant of a given node.
(e): You can use XPath axes like parent and following-sibling to select all nodes relative to a given node.
I hope these pointers are helpful. I also recommend the excellent Selenium Locator Rosetta Stone (PDF) as a reference on how to construct XPaths.

Using EL in <jsp:include> tag

i have a jsf 1.2 / rich faces 3.2.2 project (with java 6). i want to display menu bar conditionally depending on type of user logged in. From the question How to conditionally include a file in my template using JSF and Facelets? i tried the following:-
...
<td valign="top" align="left" height="100%">
</f:verbatim>
<jsp:include page="../Menu${authenticateBean.menuSuffix}.jsp" /> <f:verbatim></td>
...
i also tried
<jsp:include page="../Menu#{authenticateBean.menuSuffix}.jsp" />
...
where authenticateBean.menuSuffix is a string that will return "A" or "B" and ultimately, theoretically "MenuA.jsp" or "MenuB.jsp" page should include in my page. but i get following error
javax.servlet.ServletException: File "/pages/includes/LeftPan.jsp" not found
Help. Plz.
Heres how I managed it. Placing as an answer if ne one needs…
<%
AuthenticateBean authBean=
((AuthenticateBean)FacesUtils.getManagedBean(AuthenticateBean.MANAGED_NAME));
String panSuffix = authBean.getPanSuffix();
String impPage = "../includes/Menu"+ panSuffix +".jsp";
%>
.
.
.
<jsp:include page="<%= impPage %>" />
In the getPanSuffix() i have placed business logic that checks the type of user logged on and return a string accordingly. for Type "A" user. MenuA.jsp would display and for type "B" user MenuB.jsp would display. May be a primitive way of doing things but worked for me.
Thanks All.

<html:link> tag

I am new to struts tag libraries. I want to generate an anchor to define a hyperlink destination inside the same document. My code is like this:
<html:link anchor="abc" >
This is to test anchors
</html:link>
...Some other tags here
<html:link linkName = "abc" >
Anchor
</html:link>
The error I am getting is Cannot create rewrite URL: java.net.MalformedURLException: You must specify exactly one of "forward", "href", or "page"
Can anybody tell me how to solve this?
Thanks
as i understand struts and from apache
You must specify exactly one of the action attribute, the forward attribute, the href attribute, the linkName attribute, or the page attribute.
so in your first tag, i would guess that you would need to add an href tag and the anchor is added on to that. then your tag with linkname should work
that is
<html:link href="someurl" anchor="abc" >
This is to test anchors
</html:link>
This worked for me.
Below is the scenario, in which i got the error.
<appl:resource defaultValue="Appl Error" op="GET" category="shunmugaActionMapping" name="specification" property="shunmugaType" id="shunmugaStartMapping" type="string" >
<td class="<xd:valueOf name="rowStyle"/>">
<div class="listRowLink"><html:link page="<%=shunmugaStartMapping%>" paramName="specification" paramProperty="routerId" paramId="detailRouterId">> Details</html:link>
</div>
</td>
This was throwing the following error:
servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E:
Uncaught exception created in one of the service methods of the servlet
/jsp/List.jsp in application Sundaram. Exception created :
com.ibm.websphere.servlet.error.ServletErrorReport:
javax.servlet.jsp.JspException: Cannot create rewrite URL:
java.net.MalformedURLException: You must specify exactly one of
"forward", "href", "page" or "action"
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:695)
All i did is i added the closure at the end:
</appl:resource>
The problem got solved and I am fine now.
Thanks,
Shunmuga