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.
Related
How to display of popup when any of the two dropdowns selection changed and input values are modified using JSF. I am using valuechangelistener.
I have added a flag in my Mbean, if any of the input changes, this flag will be true. on change of the value of the dropdown, if this flag is true I need to show popup, but this is not coming
If you're using the<f:ajax/> tag inside of your dropdowns the following code snippet (especially the "onevent" attribute) might be useful:
<f:ajax render="itemsDataTable"
onevent="function(data) { if (data.status === 'success') {
alert('it works') ;} }"/>
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
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>
I am using a p:accordionPanel instead of a p:dataTable. Every time I change a tab, I would like to reset the active tab's entity ID within the controller. IOW, if the tabs in the accordionPanel correspond to entities whose IDs are 1, 2, 3, when I select one, I want the activeEntityID variable in the controller to be reset to the corresponding ID:
<p:accordionPanel value="#{litigController.appealsForCase}" var="appeal">
<p:ajax event="tabChange" listener="#{litigController.setSelectedAppeal}"/>
<p:tab id="#{appeal.appealID}" title="Appellate Court No #{appeal.appelateCourtNo}">
Controller method:
public void setSelectedAppeal(TabChangeEvent event) {
this.activeAppealID = event.getTab().getId();
System.out.println("tab change for appealID " + this.activeAppealID);
}
However, I get an IllegalArgumentException:
java.lang.IllegalArgumentException: Empty id attribute is not allowed
How can I link identity between each tab in my accordionPanel and the controller. I tried modeling my code after this example, but their example is poor because it uses the tab title and not an id.
You can't use EL in id attribute in this way. JSF dosn't allow it. The id attribute should be available during view build time, but your EL is evaluated during view render time. This is too late, so in the moment that the id is checked, it is empty.
Also take a look at this:
Using id="#{...}" causes java.lang.IllegalArgumentException: Empty id attribute is not allowed
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"/>