XPages and EL concat - xpages

I am trying to implement the example at http://lpar.ath0.com/2014/04/07/repeated-xpages-input-controls-with-number-indexed-field-names/
I've got it working. This is the call to the composite control:
<xc:track_row row="#{rownum}" fieldName="Track#{rownum}" dataSource="#{document1}" />
However, what I'd like is to save fields with the 01, 02 concatenated instead of 1, 2 etc. I've tried
fieldName="Track#{(rownum lt 10)? '0'.concat(rownum):rownum}"
However that generates an EL syntax error on that line. What am I doing wrong?
Thanks,
Dan

You can use multiple EL statements, it is a String only. All EL notations will be replaced during processing of the expressions. You can solve it this way:
fieldName="Track#{(rownum lt 10)? '0':''}#{rownum}"

Related

May I know how to create / generate XML using elementtree

...
para1= ET.SubElement(root,'para')
anchortag=ET.SubElement(para1,'anchor')
anchortag.set()
para1.text= " sometexthere"
I tried with the above code snippet,but couldn't get the expected output.I don't want to create a new para tag that would take the text to newline.
result of above code :
<para> sometexthere<anchor> xyxyy</anchor></para>
Expected code
<para><anchor> xyxyy</anchor> sometexthere </para>
You have to make a couple of changes, and it should work:
First, change
anchortag.set()
to
anchortag.text='xyxy'
and then, given that you want sometexthere to be at the tail end of the element,
change
para1.text= " sometexthere"
to
para1.tail= "sometexthere"

Does 'position()' have to be explicitly included in this Xpath?

This returns all the first 'nd's as expected
select="osm/way/nd[1]"
This returns all the lasts:
select="osm/way/nd[last()]"
This returns both:
select="osm/way/nd[position() = 1 or position() = last()]"
Is there a syntax to remove position() function?
Something like this, but works?
select="osm/way/nd[[1] or [last()]]"
There has been some debate about allowing a new syntax to select a range https://github.com/qt4cg/qtspecs/issues/50#issuecomment-799228627 e.g. osm/way/nd[#1,last()] might work in a future XPath 4 but currently it is all up in the air of a lot of debate and questionable whether a new operator is helpful instead of doing osm/way/nd[position() = (1, last())].

a range instead of equals for a render syntax

i have got a render that looks at a bean and if it is the same as a value above then it will render or not, this is working fine :
rendered="#{formBean.number eq 1}
what i want to do now though, is add if it is in a range, between 1 and 8 for example, is this possible if so what is the syntax as a quick google haven't shown up any results
Thanks
You can use le (less equal) and ge (greater equal) in java EL to achieve this:
rendered="#{formBean.number ge 1 and formBean.number le 8}

How to use && in EL boolean expressions in Facelets?

I am having a little trouble figuring out how to do and's on EL expressions in Facelets.
So basically I have:
<h:outputText id="Prompt"
value="Fobar"
rendered="#{beanA.prompt == true && beanB.currentBase !=null}" />
But I keep getting:
Error Traced[line: 69] The entity name must immediately follow the '&'
in the entity reference.
Facelets is a XML based view technology. The & is a special character in XML representing the start of an entity like & which ends with the ; character. You'd need to either escape it, which is ugly:
rendered="#{beanA.prompt == true && beanB.currentBase != null}"
or to use the and keyword instead, which is preferred as to readability and maintainability:
rendered="#{beanA.prompt == true and beanB.currentBase != null}"
See also:
Java EE 6 tutorial - Operators in EL
Unrelated to the concrete problem, comparing booleans with booleans makes little sense when the expression expects a boolean outcome already. I'd get rid of == true:
rendered="#{beanA.prompt and beanB.currentBase != null}"
In addition to the answer of BalusC, use the following Java RegExp to replace && with and:
Search: (#\{[^\}]*)(&&)([^\}]*\})
Replace: $1and$3
You have run this regular expression replacement multiple times to find all occurences in case you are using >2 literals in your EL expressions. Mind to replace the leading # by $ if your EL expression syntax differs.

Using greater than logical expression in rendered attribute

I have an outputText field for which I write a condition in the rendered attribute. The condition is for comparing the length of the string with some numeric value.
<h:outputText id="emailaddress"
value ="#{subsAlertsHelper.personEmail.substring(0,20)}"
rendered="#{subsAlertsHelper.personEmail.length() >20}" />
If I use == or != in rendered it is working fine. But for greaterthan and lessthan it is not giving the output. What could be the reason for that?
You have to use gt and lt operators.
Check out JavaServer Faces Expression Language Intro from Sun/Oracle. Precisely the Operators section.
rendered only accepts EL expression.
subsAlertsHelper.personEmail.length() is incorrect.
On the personEmail object, add a method getLength() witch returns the length
public int getLength(){ return this. length();}
Modify :
rendered="#{subsAlertsHelper.personEmail.length >20}"

Resources