Disable JSF Dropdown item with JSF1.2 - myfaces

I need to disable few items in selectItem list based on a backing bean. Below is the code snippet
<h:selectOneMenu required="#{bean.tbiLotNumberRequired}"
label="TBI Lot # " id="tbiLotNumber"
value="#{bean.unitDTO.tbiLotNumber}"
disabled="#{bean.disableLotSpecificFields}">
<f:selectItem itemLabel="-Select-" itemValue =""/>
<f:selectItems value="#{bean.communityLotNumber}"/>
</h:selectOneMenu>
The value of selectItem is backed by MyFaces SelectItem.
Now, the bean I'm setting the "disabled" property of SelectItem thru setDisabled in my backing bean. It does not work.
Alternatively, I tried both below options
<f:selectItems value="#{bean.communityLotNumber}" var="lot"
itemDisabled="${lot.isDisabled}"/>
and
<f:selectItems value="#{bean.communityLotNumber}" var="lot"
itemDisabled="${bean.isDisabledLot(lot)}"/>
with a backing bean to evaluate the SelectItem and return the boolean value to set it true.
But, probably since im using JSF 1.2, the server throws the below error
com.sun.facelets.tag.TagAttributeException: /WEB-INF/flow/xx/xxxxx/xxcreate_a.xhtml #109,122 itemDisabled="#{bean.isDisabledLot(lot)}" Error Parsing: #{bean.isDisabledLot(lot)}
at com.sun.facelets.tag.TagAttribute.getValueExpression(TagAttribute.java:259)
at com.sun.facelets.tag.jsf.ComponentRule$ValueExpressionMetadata.applyMetadata(ComponentRule.java:69)
at com.sun.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:36)
at com.sun.facelets.tag.MetaTagHandler.setAttributes(MetaTagHandler.java:62)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:144)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
We are using
MyFaces1.2,
JSF 1.2 and
RichFaces 3.3
can someone suggest an alternative.

The above must work withe the exception that the var, values and itemDisabled properties' do not have the same backing bean. That is wrong. The variable and the values must correlate.

Related

How to use FormComponentPanel for FileUpload Field in Apache wicket 9.x?

I am trying to create FileUploadPanel that can be used in the form.
But however at runtime I facing some conversion error, I did debug the code it is going to the ConverterLocater.class in the wicket-core jar there it fails on the typecasting.
So when I debug I found filename is passed a in the below method public C convertToObject(String value, Locale locale) and in the conversion it fails because the value is string and it trying to caste to fileUpload.class.
Error:
throw (new ConversionException("Could not convert value: " + value + " to type: " + theType.getName() + ". Could not find compatible converter.")).setSourceValue(value);
Here value is passed as file name and theType is FileUpload.
I referred some examples, there setType is mandatory so I tried to set with String.class
but again next time fileUpload class was failing.
Could not convert value: test.pdf to type: org.apache.wicket.markup.html.form.upload.FileUpload. Could not find compatible converter.
I found the solution
Model name parameter was the issue, after changing this to List it got fixed.
private List<FileUpload> fileUploads = new ArrayList<FileUpload>();
new MultiFileUploadField("fileField",new PropertyModel(this,"fileUploads"),maxFiles)

What globals are available in template expressions?

I'm reading the Vue.js guide, and I've come across the statement.
Template expressions are sandboxed and only have access to a whitelist
of globals such as Math and Date. You should not attempt to access
user defined globals in template expressions.
What are all the globals available in templates?
That is, what is the content of the whitelist, exhaustively?
Vue.js defines the whitelist of globals in the core/instance/proxy.js file:
//...
const allowedGlobals = makeMap(
'Infinity,undefined,NaN,isFinite,isNaN,' +
'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
'require' // for Webpack/Browserify
)
// ...
When Vue compiles the template, the string interpolations are processed, and if you reference a global that is not whitelisted, you will have a warning on Development.
If you are curious about how templates are compiled to render functions, look through the template explorer.
From what I understood from source code globals are declared in a variable and make it available via a proxy between vm instance and template :
const allowedGlobals = makeMap(
'Infinity,undefined,NaN,isFinite,isNaN,' +
'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
'require' // for Webpack/Browserify
)
So gobals available in template are :
Infinity
undefined
NaN
isFinite
isNaN
parseFloat
parseInt
decodeURI
decodeURIComponent
encodeURI
encodeURIComponent
Math
Number
Date
Array
Object
Boolean
String
RegExp
Map
Set
JSON
Intl
require
If you try to put in your template a reference that is not whitelisted or not in your vm instance then you will have this warning :
Property or method "${key}" is not defined on the instance but
referenced during render. Make sure that this property is reactive
either in the data option, or for class-based components, by
initializing the property.

Aurelia Binding errors ( on browser console)

I am using below snippet in html
value.two-way="lstName.IsBlocked ? 'Blocked' : Value2 + ' %'"
on console it shows error as
Uncaught Error: Binding expression
"lstName.IsBlocked?'Blocked':Value2+' %'" cannot be assigned to.
at b.a.assign (aurelia.js?v=1.0009:59)
at a.updateSource (aurelia.js?v=1.0009:61)
at a.call (aurelia.js?v=1.0009:61)
at a.v [as callSubscribers] (aurelia.js?v=1.0009:58)
at a.notify (aurelia.js?v=1.0009:60) `
What can be the reason for this ?
Thanks in advance!
Since you're using a two-way binding, the binding expression needs to be assignable.
As the error says: "lstName.IsBlocked?'Blocked':Value2+' %'" cannot be assigned to.. If your bound property changes from the view, it would have to be able to write back to the expression and update the source value in your view model. You can't really write to an inline if.
Change two-way to to-view and it should work.
EDIT:
Since you need the expression to be writable, you could use a ValueConverter to solve the problem (assuming Value2 is what you want to write to):
export class BlockedValueConverter {
toView(value, isBlocked) {
return isBlocked ? 'Blocked' : value + ' %';
}
fromView(value) {
return value;
}
}
Then in your html (don't forget to require the valueConverter or use globalResources):
value.two-way="Value2 | blocked:lstName.IsBlocked"

Assign a value to an attribute of a Microsoft.TeamFoundation.Build.Common.BuildParameter object using XAML

my BuildParameter is defined in my xaml build as follows:
<Activity this:Process.AdvancedBuildSettings=
"[New Microsoft.TeamFoundation.Build.Common.BuildParameter(
" { ""Attribute1"": """",
""Attribute2"": ""Value2"",
""Attribute3"": ""Value3"" } "
)]">
Now I want to update the value of Attribute1 of my BuildParameter but I can't figure out how to do it.
It doesn't look like I can use an Assign block because these attributes names are not known by the compiler, so I want to use BuildParameter's SetValue method but I'm not sure how to call this VB code in my xaml.
<Assign DisplayName="Update That Attribute">
<Assign.To>
<OutArgument x:TypeArguments="x:String">[AdvancedBuildSettings.Attribute1]</OutArgument><!-- this throws a compiler error because it doesn't know what Attribute1 is -->
</Assign.To>
<Assign.Value>
<InArgument x:TypeArguments="x:String">""NewValue""</InArgument>
</Assign.Value>
</Assign>
Not familiar with XAML, but here is a code snippet that using TFS API in C# to update the parameter name. You can use WorkflowHelpers.DeserializeProcessParameters Method and WorkflowHelpers.SerializeProcessParameters Method to get parameter name, remove it, and add the new parameter name, maybe it can help you something:
string argumentName = "Attribute1";
var process = Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers.DeserializeProcessParameters(BuildDefinition.ProcessParameters);
if (process.ContainsKey(argumentName))
{
process.Remove(argumentName);
process.Add(argumentName, attributeValue);
BuildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(process);
BuildDefinition.Save();
}
I was right, the "Assign" workflow tool was not the tool I wanted. I needed to use the "InvokeMethod" workflow tool in order to invoke the SetValue() method of my BuildParameter object in my XAML build.
MSDN InvokeMethod documentation
More details about the properties of InvokeMethod
So my solution looks like this:
<InvokeMethod DisplayName="Invoke That Method" MethodName="SetValue">
<InvokeMethod.GenericTypeArguments>
<x:Type Type="x:String" />
</InvokeMethod.GenericTypeArguments>
<InvokeMethod.TargetObject>
<InArgument x:TypeArguments="mtbc:BuildParameter">[AdvancedBuildSettings]</InArgument>
</InvokeMethod.TargetObject>
<InArgument x:TypeArguments="x:String">Attribute1</InArgument>
<InArgument x:TypeArguments="x:String">[NewValue]</InArgument>
</InvokeMethod>

Struts - getting NPE when passing parameters to bean property

I have a bean property in my form as follows (rates is a HashMap from FleetRateTypeCO to FleetRate[]):
public FleetRate[] getRatesByType(int typeID) {
return this.rates.get(FleetRateTypeCO.getByID(typeID));
}
Then in my jsp I want to do the following:
<c:when test="${not empty DedicatedFleetContractAdminForm.ratesByType[1]}">
...
</c:when>
But I get a null pointer exception:
java.lang.NullPointerException
at javax.el.BeanELResolver$BeanProperty.read(BeanELResolver.java:259)
at javax.el.BeanELResolver$BeanProperty.access$000(BeanELResolver.java:209)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:60)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
at org.apache.el.parser.AstValue.getValue(AstValue.java:97)
at org.apache.el.parser.AstEmpty.getValue(AstEmpty.java:29)
But what really confuses me is that if I try the following, it works fine:
<logic:iterate property="ratesByType[1]" name="DedicatedFleetContractAdminForm" id="overheadRates">
...
</logic:iterate>
Why would they work differently? Any help is appreciated - thank you in advance.
In one you are using the struts tags, and in the other EL.
Try using the struts tag