IntelliJ inspection to find tags without 'id' attribute - jsf

I need to setup an inspection in IntelliJ that will find xhtml/html/jsf page elements without an `id attribute.
<h:outputText value="myOutputValue"
styleClass="someStyle"/>
<h:outputText value="myOtherOutputValue" />
I tried setting up a code inspection in intelliJ under "Structural search". With the following regexp however I can't configure it properly. Any help would be appreciated.
<(?:h:inputText|h:outputText)(?:\s+(?!id\b)[\w\-.:]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[\w\-.:]+))?)*\s*/?>
I know the regexp works because it will find the occurrences in my file when entered into the find box.
One last thing, in the end I'll want to expand (?:h:inputText|h:outputText) to include numerous tags so if using variables in the inspection or something else in intelliJ then that solution would be best. We want to make sure all developers put id attributes on all applicable page elements to aide in testing ease. (JSF tags are hideous)

You can use a Structural Search pattern like the following:
<$name$ $id$>
Remember to set the correct file type. Click Edit Variables... and give $name$ the following constraints:
Text/regexp: h:inputText|h:outputText
Give $id$ the following constraints:
Text/regexp: id
Occurrences count: 0,0
This will find all <h:inputText> and <h:outputText> tags without id attribute.

Related

Matching element id's with JSF dynamic view Id

I'm using JSF 1.2. We want to write some selenium tests (based on xpath) but xpath does not seem to have wildcard matching on element id's.
We cannot turn off prefix ids as we are running as a portlet within IBM Portal Server 6.1 and our application breaks in that environment with the prefix turned off.
Currently we are using xpaths of the form
//*[substring(#id, 54)='id_distributorName']
which will match:
<select size="1" class="firstName" name="viewns_7_8000CB1A0GUIE0IJF799CR10O2_:commonEntryForm:id_distributorName" id="viewns_7_8000CB1A0GUIE0IJF799CR10O2_:commonEntryForm:id_distributorName" >
but it strikes me that assuming JSF will always generate a viewId of the same length is dangerous.
Is there a better way to do this?
We've tried using the name attribute for our input controls but of course JSF ignores the attribute and writes it's own name attribute whose value matches the id presumably for evant handling scripting reasons)
If you're using XPath 2.0, just use ends-with() function:
//*[ends-with(#id, ':id_distributorName')]
If you're using XPath 1.0, use string-length() to calculate the begin of substring():
//*[substring(#id, string-length(#id) - 18) = ':id_distributorName']
Here, 18 is the length of id_distributorName (without the : prefix!).
Ok I've just answered my own question.
I admit I know little about xpaths, that's my excuse!
The answer is to use contains()
i.e.
//*[contains(#id, 'id_distributorName')]
Use:
//*[substring-after(#id, ':commonEntryForm:') = 'id_distributorName']

Inner tags not parsing with Expression Engine 2 custom plugin

I've written a simple plugin that basically loops through a bunch of entries. The plugin is used to only display entries that contain a feature image, amongst some other minor logical conditions. The use of my tag looks something like this:
{exp:myentries:withimages channel="mychannel"}
<!-- This works fine -->
<h1>{title}</h1>
<!-- But nested exp:... tags don't seem to parse? -->
<p>{exp:ce_img:single src="feature_image"}</p>
{/exp:myentries:withimages}
I am calling
return $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $data);
from my custom EE plugin, the data is there, but only the nested {exp:... tags don't want to parse.
I've followed the online User Guide for creating plugins as close as I possibly could, but I need some help getting the other tags to parse? If I simply output {feature_image}, the field renders the src value for the image as expected.
Can anyone possibly shed some light on what I'm doing wrong?
You want to put parse="inward" parameter in your {exp:myentries:withimages tag, otherwise the template will try to parse the exp:ce_img call before {feature_image} is set.
{exp:myentries:withimages parse="inward" channel="mychannel"}
The parse="inward" will tell EE to run this tag first before parsing any other tags within the tag pair.
There are two important typos in your code.
{exp:ce_img:singe src="feature_image"}
Should read:
{exp:ce_img:single src="{feature_image}"}
If those differences are actually present in your template, then that would be it I believe.

How to get the effect of 'user-select: text' in css3?

The validator at http://jigsaw.w3.org/css-validator/ says that the value 'text' for 'user-select' is not valid. For a css rule with this code in it:
user-select: text;
the validator says:
text is not a user-select value : text text
Presumably this is because of this behavior, specified at (the outdated) http://www.w3.org/TR/2000/WD-css3-userint-20000216#user-select:
This property is not inherited, but it does affect children in the
same way that display: none does, it limits it. That is if an element
is user-select: none, it doesn't matter what the user-select value is
of its children, the element's contents or it's childrens contents
cannot be selected.
Also, I only see the attribute value 'text' specified in that out-of-date css3 doc from w3.org:
http://www.w3.org/TR/2000/WD-css3-userint-20000216#user-select
and not in the latest one: http://www.w3.org/TR/css3-ui/
Additionally, searching 'whatwg.org' yields nothing.
Any ideas if 'user-select: text' is valid css3, and if not, what should be used instead?
This would be used, for example, when overriding 'user-select: none' rules applied to containers of text and ancestor containers.
You are getting this wrong. user-select:text doesn't mean it would select text only. It's default value of user-select property. W3C describe it this way:
The element's contents follow a standard text content selection model.
And Also MDN syas something same:
-moz-none The text of the element and sub-elements cannot be selected,
but selection can be enabled on sub-elements using
-moz-user-select:text .
So I don't think this should prevent selecting images or boxes.
As far as I know user-select:text is useful when you have user-select:none for most or all of your elements and you have a textbox or text area that is kind of output and you want it be selectable for copying and pasting.
It seems if you use -webkit- prefix it works for me. I'm sure it works with -moz- prefix too. Test this fiddle in your browser. I don't know why user-select:text is not working on my Chrome 13 Mac?

How to insert a value into a text field under a div using Watir

I used set to insert a value in a text field under a div.
Below is the approach that I've used without success. This is the only way I was able to identify the element. When I tried to identify text field by name was not recognized.
#browser.div(:evaluation, :id => "evaluation_form_attributes").text_field(:id => "evaluation_form_name")
#browser.set('Teacher Evaluation Form')
The following error was displayed:
undefined method `set' for #<Watir::IE:0x4dd9348>
This is the HTML:
div id="evaluation_form_attributes"
Evaluation name:
input id="evaluation_form_name" type="text" size="50" name="evaluation_form[name]" maxlength="30"
Try this:
browser.text_field(:id => "evaluation_form_name").set 'Teacher Evaluation Form'
Is there an iframe involved perhaps? if you know the thing is there, and you are sure of the ID, and watir cannot locate it, then usually it's because that part of the page is inside of a frame.
To work with elements that are inside of a frame, you must specify the frame, then the element
browser.frame(:how, what).element(:how, what).method etc.
see http://wiki.openqa.org/display/WTR/Frames for more info
To set a value for a text field you simply need to find it and set it. The setting part you already know (set), so you need to string together something that finds the text field.
if Zejiko's answer doesn't work because of "unable to locate element" then it's not the setting that's failing, it's finding the text field. Use Firebug (in Firefox) or some kind of DOM toolkit (Tools>Developer Tools or F12 in IE8) to find the text field and see what kind of attributes it has.
Ensure the id is really "evaluation_form_name". This is case sensitive and sensitive to leading/trailing spaces. You could try the following to make your search broader:
#browser.text_field(:id => /evaluation/).set 'Teacher Evaluation Form'
This uses a regular expression to identify the id. You can search by many things, not just :id, and you can use more than one. For example:
#browser.text_field(:id => /eval/, :index => 2)
finds the second text field whose id contains "eval".
What you can use to identify the text field can be found here: https://github.com/watir/watir/wiki/HTML-Elements-Supported-by-Watir

JSF - how to dynamically display values from messages.properties

I have a DataModel which has plan names and some other attributes.
I have different plans - gold , silver etc.
But I dont want to display Gold or Silver as it is. Based on the locale, I want to display it from the messages.properties
Here is my code snippet:
<h:dataTable value="#{newMemberController.membershipModel}"
var="plans" styleClass="gird_header_value">
<h:column><h:outputText value="#{plans.name}" /></h:column>
So instead of plans.name value I want something like #{msgs.#{plans.name}}
but this gives me a compilation error.
Does anyone know what is the correct syntax for this?
You can use the brace notation to access Map values with a dynamic key: #{map[key]}.
Thus, the following example should do:
<h:outputText value="#{msgs[plans.name]}" />

Resources