xp:selectItem value property throws Conversion Error - xpages

Within xp:RadioGroup there is xp:selectItem which requires itemLabel.
Data-Properties of xp:selectItem is either itemValue or value:
itemValue - is the value returned to the server
value - specifies the contest of the selection item (Can be literal string or expression)
Loading values in both value & itemValue throws an error e.g.
<xp:radioGroup id="radioGroup"
layout="lineDirection"
dojoType="dijit/form/RadioButton"
styleClass="zmdi">
<xp:selectItem itemLabel='ssh'
itemValue="serverValue"
value="SelectionContentsValue">
</xp:selectItem>
</xp:radioGroup>
The error thrown is:
Exception
Conversion Error setting value ''{0}'' for ''{1}''.
java.lang.IllegalArgumentException: Conversion Error setting value ''{0}'' for ''{1}''.
com.sun.faces.util.Util.getSelectItems(Util.java:489)
com.sun.faces.renderkit.html_basic.SelectManyCheckboxListRenderer.encodeEnd(SelectManyCheckboxListRenderer.java:130)
com.ibm.xsp.renderkit.html_basic.RadioRenderer.encodeEnd(RadioRenderer.java:48)
com.ibm.xsp.renderkit.ReadOnlyAdapterRenderer.encodeEnd(ReadOnlyAdapterRenderer.java:180)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:1005)
com.ibm.xsp.component.UISelectOneEx.encodeEnd(UISelectOneEx.java:331)
com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:858)
Removing the [ value="SelectionContentsValue" ] attribute from the xp:selectItem renders the radioGroup without issue.
ideas? thx

The value property of the is intended to be evaluated to something that is a UISelectItem.
Here, you are assigning it to a String "SelectionContentsValue".
During rendering, the Renderer asks the radioGroup "Please give me your all your selectItems".
It does this by iterating through it's children, and checking if each child is a UISelectItem.
For each UISelectItem that it finds, it evaluates the value property.
If value evaluates to null, it will then check for itemLabel, itemValue etc. and create the selectItem using these properties.
else if value evaluates to a UISelectItem, it will use this UISelectItem
else If value evaluates to something that is not a UISelectItem, it throws an IllegalArgumentException
Your situation is throwing the IllegalArgumentException because you have assigned a String to the 'value' property instead of a UISelectItem
So you should either use the itemLabel, itemValue properties and manually set those options that way. Or instead you can use the value property to compute the selectItem to one that has been prepared in some other place, or is dynamically loaded e.g. a managedBean or scoped variable.
I hope this helps let me know if any questions

Thank you Cameron, you comment sparked an idea to go track down, which I found here:
IBM Domino Designer> IBM Domino Designer 9.0.0> IBM Domino Designer User Guide> Designing XPages applications> Adding controls> Control reference selectItems - Selection Items
» Checkboxes can each checked "true", no mutual exclusivity with checkboxes.
Checkboxes are kinda like Hippies, "It's all cool man".
» Radio buttons are much more finicky:
» Radios require itemLabel with itemValue aliase optional, for each selection option:
» The 'value' data-property is for checkboxes. Value contains pipe-delimited selection values, in an array/vector of checkbox choices.
<xp:checkBoxGroup id="checkBoxGroup1" value="#{document1.fruit}">
<xp:selectItems>
<xp:this.value>
<![CDATA[${javascript:["Apples|apples|Garden of Eden|false","Oranges|oranges"]}]]>
</xp:this.value>
</xp:selectItems>
</xp:checkBoxGroup>

Related

Dynamically set itemValue of selectOneMenu in BootsFaces not working

I am Developing such application in which there is Hibernate Many to One Relationship between Employee and Designation. While Inserting New Employee, I am Creating Dynamic Options(which comes from Designation Table present in Database) of Select Menu for Designation. I can Create options as follow in xhtml:
<b:selectOneMenu value = "#{loginBean.designationVo}">
<f:selectItems value = "#{loginController.designationListByInsert()}" var = "field" itemLabel = "#{field.designation}" itemValue = "#{field.designationId}"/>
</b:selectOneMenu>
In Above Code, designationListByInsert() method will return List of Designation, Now I want to set DesignationName as itemLabel so user can see only Name of Designation along with it I want DesignationId as itemValue, but I can't set itemValue as shown in above code. It takes index value of List as itemValue. If I set DesignationId as itemLabel the it shows correct value but at same time If I Assign it to itemValue then it doesn't work. I can't understand what's wrong in my code. Please Someone help me to make it correct.
Try this it will surely work.
Replace
itemValue = "#{field.designationId}"
by
itemValue = "#{field}"

Xpages: Cannot compute property "defaultValue" in custom control

I have a custom control which contains a comboBox. One property of the CC is default value, which I want the developer to be able to pick in the Xpage.
Static values pass into the CC fine, but if I try to default the value, it fails. I would like to default the default property to the current user, but it cannot.
This is the custom control on an the Xpage. I can return a name statically and it works, but if I compute the name it doesn't work.
<xc:cc_commonfieldselect2fromcache
datasource="#{javascript:return Ticket}"
cacheitem="employees"
fieldname="tckReqs"
fieldlabel="Requester">
<xc:this.defaultvalue>
<![CDATA[#{javascript:var usrNme:String = ("[CN]",session.getEffectiveUserName());
return usrNme;
//return "Bryan S Schmiedeler";}]]>
</xc:this.defaultvalue>
</xc:cc_commonfieldselect2fromcache>
Here is part of the custom control: I am trying to pass in the compositeData.defaultValue that was set above. If I hard code it it works, otherwise it doesn't.
<xp:comboBox
id="${javascript:compositeData.fieldName}"
value="#{compositeData.dataSource[compositeData.fieldName]}"
defaultValue="${javascript:compositeData.defaultValue}">
<xp:selectItems
value="${javascript:'#{CacheBean.'+compositeData.cacheItem+'}'}">
</xp:selectItems>
</xp:comboBox>
Here is how I have set the property in the custom control:
Your code used the defaultValue (inside your cc) before it was stored into your cc´s compositeData.
${} => computed a single time on pageload (and before all dynamically computed)
#{} => dynamically computed
You have 2 options
set your cc defaultValue to dynamically computed (#)
provide the defaultValue also on pageload ($)
In your code you compute the default value at "load time":
defaultValue="${javascript:compositeData.defaultValue}"
while you need to compute it at runtime:
defaultValue="#{javascript:compositeData.defaultValue}"
that should do the trick

How to get Trinidad tr:inputText to echo its changed value instantly?

I have the following Trinidad tr:inputText field in my xhtml file that is bound to "value1" in my managed bean class; the inputText field is of type:
org.apache.myfaces.trinidad.component.core.input.CoreInputText
<tr:inputText value="#{myBean.value1}" autoSubmit="true" immediate="true" valueChangeListener="#{myBean.textChangeListener}" styleClass="stylePageTextSmallColored">
</tr:inputText>
<tr:commandButton id="btnCommit" inlineStyle="width:20" immediate="true" text="Commit" action="#{myBean.doCommit()}" styleClass="styleButton">
</tr:commandButton>
public void textChangeListener(ValueChangeEvent e) {
log.debug(">> textChangeListener: value=["+(String)e.getNewValue()+"]");
}
public String doCommit() throws Throwable {
log.debug("In doCommit: value1="+value1);
value1 = "("+value1+")";
// I update my database with the modified value1 string here; the database has the correct
// updated value1 string (with the parentheses).
// How do I get the modified value1 (above) to echo back to the screen instantly
// inside the doCommit() method with its changes?
}
When I type into this field and change its value then press the "commit" button, I can see its value properly obtained from the screen in the doCommit() method and the textChangeListener() method indicates that it has been called. I would like to make some changes to the "value1" variable and echo its value back instantly to the screen without doing another screen submit; can this be done as part of the doCommit() method or through some other mechanism/tag in the xhtml file?
Please note that this is using Trinidad and the input text class is listed above.
Update...
Thank you for the reference Jasper; I want the SAME inputText field to update itself after the setter method is called and the input text is changed (by the setter method). Thanks to the reference page that you pointed to; I tried the following and it works by using the partialTriggers attribute:
<tr:inputText id="myValue" value="#{myBean.value1}" autoSubmit="true" immediate="true" partialTriggers="myValue" valueChangeListener="#{myBean.textChangeListener}" styleClass="stylePageTextSmallColored"> </tr:inputText>
You can do so using Trinidad's Partial Page Rendering.
In short: you need to add an id attribute to your input, and have and tr:outputText component with a partialTriggers attribute where you refer to the input component.
Minimal implementation in your case would be:
<tr:inputText id="value1Input"
value="#{myBean.value1}"
autoSubmit="true"
immediate="true"/>
<tr:outputText value="value1: #{myBean.value1}"
partialTriggers="value1Input"/>

Domino 9 has a new boolean converter for checkbox group controls - anyone get this working?

I added the new boolean converter to a checkbox and bound this to a number field on the Domino form. When I view the XPage I get an error: Exception
java.lang.String incompatible with java.lang.Boolean.
My source is
<xp:checkBoxGroup
id="checkBoxGroup1"
value="#{document1.Good}"
defaultValue="true">
<xp:this.converter>
<xp:convertBoolean></xp:convertBoolean>
</xp:this.converter>
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var arr = ["true", "false"];
return arr;}]]></xp:this.value>
</xp:selectItems>
</xp:checkBoxGroup>
Just wondering how this new feature in ND9 works???
Howard I posted a tip on this here: http://xpagetips.blogspot.com/2013/01/before-ibm-connect-5-days-5-tips-tip-1.html.
I think you're right. It is only there to make it easier work with boolean values but does not enable actually storing that data type in a Notes document.
Perhaps there is object storage coming in our future??

checkbox value. getting strange value when checked/unchecked

i have a checkbox in jsf as follow. this jsf page is in the portal page.
when i check the checkbox i get value as "on" and when i uncheck it i get the value as null. Why is it like that. the code is as below:
the checkbox is in formitem. isFullTimeStudent is of type Boolean
> <hx:formItem styleClass="formItem"
> id="fullTimeStudentFormItem"
> showHelp="none"
> label=" #{giamsBundle['lbl.full.time.student']}">
> <h:selectBooleanCheckbox id="fullTimeStudentChkBox"
> value="#{pc_AssigneeDependents.dependent.isFullTimeStudent}"></h:selectBooleanCheckbox>
> </hx:formItem>
The value on is the default HTTP request parameter value for a checked checkbox. You're apparently grabbing it raw from the request parameter map instead of accessing it by the property as bound by the input element's value attribute.
Don't use the request parameter map, just access it in the AssigneeDependents managed bean by dependent.getIsFullTimeStudent() which in turn should be a boolean or Boolean.

Resources