I am trying to set the src property of sap.ui.core.Icon based upon data being fetched from the data model. Something like this:
<Icon src="{= ${propertyname} === 'somevalue' ? 'sap-icon://arrow-top' : 'sap-icon://arrow-bottom'}"/>
I have one additional condition in my case which implies that:
Set icon1 (say 'sap-icon://arrow-top') when property value is 'UP'
Set icon2 (say 'sap-icon://arrow-bottom') when property value is 'DOWN'
Set icon3 (say 'sap-icon://arrow-left') for all other cases
Is it possible to achieve this without the use of formatter function?
Simply nest another ternary operator inside your expression.
<Icon src="{= ${propertyname} === 'UP' ? 'sap-icon://arrow-top' : ${propertyname} === 'DOWN' ? 'sap-icon://arrow-bottom' : 'sap-icon://arrow-left'}"/>
Related
Is there a contracted syntax that allows the execution of a certain function only if the left value is true?
Example :
ready() ? drawGraph();
I do not want this:
ready() ? drawGraph() : ELSEFUNCTION;
Thanks
How can I generate something like this in my rule using PackageDescr ?
$var: Number (doubleValue > 100 ) from myPredefinedFunction()
I tried the following :
PatternDescr pt = new PatternDescr("Number","$var");
RelationalExprDescr ex = new RelationalExprDescr(">", false, null, new ExprConstraintDescr("myPredefinedFunction()"), new ExprConstraintDescr("100"));
pt.addConstraint(ex);
but this is what I get :
$var : Number( myPredefinedFunction() > 100 )
You're trying to set the myPredefinedFuntion() as a constraint. Constraints are the part of the drools declaration between the parentheses, eg. MyObject( foo == "bar" ) ... the foo == "bar" is a constraint.
Instead you need to set the source using the setSource method. This is the 'from' part of the declaration. This method takes a instance of a PatternSourceDescr subclass -- likely a FromDescr for this particular scenario.
(Alternatively, you might need setResource instead of setSource. The problem with using internal-only APIs is that they're not documented and subject to change without notice. I strongly suggest not going down this route.)
I am trying to dynamically render class based off actionTypeCreate. This is a method that simply returns a boolean value based off the prop actionType that is passed. I am triggering this method on the mounted hook and confirmed it is returning properly.
Now I am trying to return the class value of 'col-md-4' if actionTypeCreate. If not actionTypeCreate I want to return the class 'col-md-6'.
This is what I have but it is not working:
:class="{toggleActionType : 'col-md-4' ? 'col-md-6'}"
I tried to reference this existing question, but I did not get it.
You can do it as follows:
:class="{'col-md-4' : toggleActionType , 'col-md-6' : !toggleActionType }"
According to the Vue documentation itself you can do it in two ways. First, you can use Array Syntax and this is broadly used to apply a list of classes.
Array Syntax
:class="[toggleActionType ? 'col-md-4' : 'col-md-6']"
Or you can do it as normal by Object Syntax but it does not accept ternary operations, so you have to do it this way:
Object Syntax
:class="{'col-md-4' : toggleActionType , 'col-md-6' : !toggleActionType}"
Try this:
:class="[toggleActionType : 'col-md-4' ? 'col-md-6']"
I found a much upvoted answer to a question with the following code:
var condition = true;
return (
<Button {...condition ? {bsStyle: 'success'} : {}} />
);
Why is the ... required? If I omit it, babel complains to me that:
repl: Unexpected token, expected ...
It looks like the spread syntax, but condition is a boolean. I'm having trouble finding docs that explain what is going on.
If you check out MDN: Spread operator:
The spread syntax allows an expression to be expanded in places where
multiple arguments (for function calls) or multiple elements (for
array literals) or multiple variables (for destructuring assignment)
are expected.
If you see, the spread operator inside the jsx syntax to evaluate expression, then
<Button {...condition ? {bsStyle: 'success'} : {}} />
Would become something like, (after babel run with react bootstrap example):
_react2.default.createElement(_reactBootstrap.Button, condition ? { bsStyle: 'success' } : {})
It can also be written as:
<Button bsStyle={condition ? 'success' : ''} />
Which, then means you are passing the props bsStyle with empty string.
So in order to conditionally pass the props itself, you can leverage the spread operator and evaluate the expression. This helps us to pass multiple props on with conditions:
<Button {...condition ? {bsStyle: 'success', bsSize:"large"} : {}} />
Rather than:
<Button bsStyle={condition ? 'success' : ''} bsSize={condition ? 'large' : ''} />
You are using a boolean to return an object. The spread operator ... usage is for spreading that object, so you can make it more readable for yourself by using parenthesis:
var condition = true;
<Button { ...(condition ? {bsStyle: 'success'} : {}) } />
Which is equivalent to this, if your variable is true:
<Button { ...{bsStyle: 'success'} } />
or this one if your variable is false:
<Button { ...{} } />
I am using rich faces select component.
I want dynamic values when user manually type some thing in the select component.
<rich:select enableManualInput="true" defaultLabel="start typing for select" value="#{supplierSearchBean.userInput}">
<a4j:ajax event="keyup" execute="#this" listener="#{supplierSearchBean.userInputChange}"/>
<f:selectItems value="#{supplierSearchBean.selectOptions}" />
</rich:select>
Java code as follows
public void userInputChange(ActionEvent ae){
Map map = ae.getComponent().getAttributes();
System.out.println(map.toString());
}
public void setUserInput(String userInput) {
System.out.println("userINput = " + userInput);
this.userInput = userInput;
}
Here i found 2 issues
1st: setUserINput always print empty string when user type value
2nd: listener method never get call.
any help ?
The problem is most probably that there is no selected value while the user types, and this component restricts the allowed values to the specified select items. A partial input is thus not valid and cannot be bound to your bean.
I think you could get the expected behavior if you use a rich:autocomplete instead. However, if you want to restrict the allowed values, maybe you can keep your rich:select and listen for the selectitem event.
Override getItems function in richfaces-utils.js file in richfaces-core-impl-4.0.0.Final.jar under richfaces-core-impl-4.0.0.Final\META-INF\resources folder.
Change the condition of pushing items to be
if(p != -1)
instead of
if(p == 0)
This should fix the issue.