I want to dispatch an action only if the instance 'addressDetails' exists (because the instance is loaded in a subform).
I tried to use the 'if' attribute of xf:action as following but didn't work:
<xf:action ev:event="save" if="instance('addressDetails') != ''">
I got the error "Error evaluating XPath expression instance('addressDetails')".
Is there a way we can check if an instance exists ?
With XPath 2.0, just write:
exists(instance('addressDetails'))
Or you could write:
count(instance('addressDetails')) > 0
Related
is it possible when submitting a form that redirects me with a variable to check if that variable is null? Because when i have if($variable === null) in my code and i dont pass the mentioned variable when loading the page it will result in error that $variable is not defined
you need to define the variable before put it in if condition
not in the if
update:
use this in return : return view('name_page')->with('variable',$variable);
the exception told you that variable doesn't exist on memory so you to check if it exists not in it's value for that you have change your if condition from
if($variable === null) to be if(isset($variable))
Here is the application.properties file:
myVar=${SOME_VAR:#{null}}
result=myVar is #{myVar != null && myVar.length() > 0 ? '' : 'not'} populated
What I am trying to get is if the environment variable SOME_VAR is set (and not blank), the property result should be myVar is populated, otherwise myVar is not populated.
The code I put above doesn't work (the line to set result), and I have also tried different combinations of #{} and ${}, including wrapping myVar, but no success so far.
What is the correct way to do? Thanks.
You wont be able to refer the myVar field directly if your member variable are private. So you should put your condition directly on the property value.
please check below expression as per your requirement.
#Value("myVar is #{ '${SOME_VAR}' != null && '${SOME_VAR}'.trim().length() > 0 ? '' : 'not'} populated")
private String result;
The #{ } is an expression language feature, while ${ } is a simple property placeholder syntax.
I ended up doing
result=myVar is #{'${SOME_VAR:#{null}}' != '#{null}' && '${SOME_VAR:#{null}}'.trim().length() > 0 ? '' : 'not'} populated
I am using an XForms action along with iterate. The iterate selects a set (using XPath) of nodes and repeats the action for it.The problem is I have multiple conditions for selecting the node set.
There should not be a readOnly node.
Should not be part of the ignoreProperties list (this list is in another instance).
Code:
<xf:action ev:event="setValues" iterate="
instance('allProps')/props/prop[
not(readOnly) and
not(instance('ignoreProperties')/ignoredProperties/property[text() = name]
]
">
The first condition not(readOnly) works. But the second condition does not work. I feel there is some problem with the context of the XPath nodes.
How should I replace the second condition to achieve the result ?
The target XML is a simple ignoredProperties document:
<ignoredProperties>
<property>c_name</property>
<property>c_tel_no</property>
</ignoredProperties>
This should work:
<xf:action ev:event="setValues" iterate="
instance('allProps')/props/prop[
not(readOnly) and
not(name = instance('ignoreProperties')/ignoredProperties/property)
]
">
The = operator works against multiple nodes, returning all the ones that match. With not() you can express that you don't want a match.
Explicitly selecting .../property/text() will not be necessary.
There seems to be something wrong with your calls to instance(). If you have:
<xf:instance id="ignoredProperties">
<ignoredProperties>
<property>c_name</property>
<property>c_tel_no</property>
</ignoredProperties>
</xf:instance>
Then instance('ignoredProperties') returns the <ignoredProperties> element. So you should write:
<xf:action ev:event="setValues" iterate="
instance('allProps')/prop[
not(readOnly) and
not(instance('ignoreProperties')/property[text() = name])
]
">
This also assumes your allProps instance has a <props> root element.
Further, the second condition appears wrong, as already shown in another answer. Write instead:
not(name = instance('ignoreProperties')/property)
In XPath 2, you could clarify that your not() are testing on node existence by using empty() instead:
<xf:action ev:event="setValues" iterate="
instance('allProps')/prop[
empty(readOnly) and
not(name = instance('ignoreProperties')/property)
]
">
Need to access 1st and 2nd element of a list in the template.
My Java code:
myMap.put("key", Arrays.asList("val1", "val2");
My FTL Template:
<#list myMap?keys as key>
${myMap[key][0]}, ${myMap[key][1]}
<-- the line above fails with undefined expression on myMap[key][0]. I checked and myMap[key] is a SimpleSequence. Also, tried ${myMap[key]?first} and that failed with the same error. Any ideas?
[0] and [1] are fine for this, but it looks like that either the sequence has 0 elements, or those elements are null. What does ${myMap[key]?size} print? BTW, you can write ${myMap[key][0]!'some default'} if you want to get a value even if the item is non-existant or null.
Your problem is that you put the List into your 'myMap' object with the key: "key" then try and access it with they key: "keys".
This is why you were getting an undefined expression, to correct it:
<#list myMap?key as k>
${myMap[k][0]}, ${myMap[k][1]}
or of course you could change your java code to
myMap.put("keys", Arrays.asList("val1", "val2");
and use the ftl code as is.
I have a message (MsgPortConfig):
<NewTable>
<InternalID>1</InternalID>
<InterfaceId>INT079</InterfaceId>
<PortName>PortArchiveNewStartersDestination</PortName>
<Type>FILE</Type>
<Address>file://c:\test\out\archive\destination\NewStarters%MessageID%.txt</Address>
</NewTable>
When I try to access a value via xpath using the following it always returns null.
VarXPath = "/*[local-name()='NewTable']/*[local-name()='Address']/text()";
VarDynamicPortFilePath = xpath(MsgPortConfig, VarXPath);
I don't know how else I can do this, checking the syntax with an application like XPathBuilder works fine but not in BizTalk. what am I missing? thanks.
Use:
VarXPath = "string(/*[local-name()='NewTable' and namespace-uri()='']/*[local-name()='Address' and namespace-uri()=''])";