I am binding all of my components to a java source. One field is a radio button, and if the user selects "Other" as a value, then I must show an field labeled "Other" for the user to fill in.
I cannot use SJSS to get the value of the radio button as it doesn't exist yet. But then how do I found out what the user selected? In the change event should I set a viewScope var and refresh the secondary area and check for the value of the viewScope var?
<xc:cc_CommonFormField
id="cc_CommonFormField14"
label="Savings"
placeholder="">
<xp:this.facets>
<xp:radioGroup
xp:key="field"
id="radioGroup1"
value="#{doc.prjSav}">
<xp:selectItem
itemLabel="Financial"
itemValue="Financial">
</xp:selectItem>
<xp:selectItem
itemLabel="Safety"
itemValue="Safety">
</xp:selectItem>
<xp:eventHandler
event="onchange"
submit="true"
refreshMode="partial" refreshId="refresh1">
</xp:eventHandler>
</xp:radioGroup>
</xp:this.facets>
<div id = "refresh1">
<div id = "innerRefresh"
rendered="#{javascript:what to put here}">
</xc:cc_CommonFormField>
<xc:cc_CommonFormField placeholder="Enter Other Reason...">
<xp:this.facets>
<xp:inputText
id="inputText3"
xp:key="field"
value="#{doc.prjOther}">
</xp:inputText>
</xp:this.facets>
</xc:cc_CommonFormField>
</div>
</div>
Here is the code that is correct:
<xc:cc_CommonFormField
id="cc_CommonFormField14"
label="Savings and/or Revenue From the Project"
placeholder="">
<xp:this.facets>
<xp:radioGroup
xp:key="field"
id="radioGroup1"
value="#{doc.prjSav}">
<xp:selectItem
itemLabel="Financial"
itemValue="Financial">
</xp:selectItem>
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="norefresh">
<xp:this.script><![CDATA[var result=null;
for(var i=0; i<document.forms[0].elements.length; i++){
if(document.forms[0].elements[i].name=="#{id:radioGroup1}" ){
if(document.forms[0].elements[i].checked == true){
result=document.forms[0].elements[i].value;
break; //remove this if for check box groups and collect multiple values above instead
}}}
var sel = x$("#{id:innerRefresh}");
if (result == "Other")
{
x$("#{id:innerRefresh}").removeClass("scoHidden");
x$("#{id:innerRefresh}").addClass("scoVisible");
}
else
{
x$("#{id:innerRefresh}").removeClass("scoVisible")
x$("#{id:innerRefresh}").addClass("scoHidden");
}
XSP.partialRefreshGet("#{id:innerRefresh}")]]></xp:this.script>
</xp:eventHandler></xp:radioGroup>
</xp:this.facets>
</xc:cc_CommonFormField>
<div id="refresh1">
<xp:div id="innerRefresh" styleClass="scoHidden">
<xc:cc_CommonFormField placeholder="Enter Other Reason...">
<xp:this.facets>
<xp:inputText
id="inputText3"
xp:key="field"
value="#{doc.prjOther}">
</xp:inputText>
</xp:this.facets>
</xc:cc_CommonFormField>
There are 2 approaches to solve this:
- server side rendering using SSJS
- client side rendering using JS
When you opt for the former, you have to submit your data (partial including the hidden div) to recompute your rendered property.
Client side: you render the div in any case, but give it a class attribute that maps to CSS display:none.
In your client side JS you add an onChange handler to the radio buttons and change the class to something visible (and back if others are unselected). This saves you from a server round trip.
Only caveat: (best handled in your Java) you need to dismiss an eventually entered value in the field for other if other wasn't selected.
Related
I'm having a problem getting a repeat to refresh when the underlying value is changed using a dialog.
This is the div that contains the repeat:
<xp:div style="display:none;">
<xp:inputText id="linkages" value="#{procureDoc.Linkages}" multipleTrim="true" style="color:cornflowerblue;" multipleSeparator=";">
</xp:inputText>
</xp:div>
<xp:label value="Linkages:" id="linkageLabel" style="font-weight:bold;"></xp:label>
<xp:div id="linkageDiv">
<ul>
<xp:repeat id="linkagesDisplayRepeat" rows="30" var="rowData" indexVar="index" value="#{procureDoc.Linkages}">
<li>
<xp:text escape="true" id="computedField7">
<xp:this.value><![CDATA[#{javascript:rowData;}]]></xp:this.value>
</xp:text>
</li>
</xp:repeat>
</ul>
</xp:div>
Here's the save button from the dialog. It does happen to sit in another custom control, but I don't think that's the problem.
<xp:button value="Save" id="saveButton">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.script><![CDATA[var linkageSelection = document.getElementById("#{id:linkageComboBox}").value;
var linkageUpload = "";
if (linkageSelection == "Use Category") {
linkageUpload = document.getElementById("#{id:linkageCategoryComboBox}").value;
}
else { linkageUpload = linkageSelection;}
var currentLinkages = document.getElementById("#{id:linkages}").value;
if ( currentLinkages == "" ) {
document.getElementById("#{id:linkages}").value = linkageUpload;
} else {
document.getElementById("#{id:linkages}").value = document.getElementById("#{id:linkages}").value + ";" + linkageUpload;
}
XSP.closeDialog('#{id:linkageDialog}');]]></xp:this.script>
</xp:eventHandler>
</xp:button>
I can put a button on the XPage that just refreshes and it will refresh my repeat with the value selected in the dialog, but just using my save button doesn't do it.
I'm sure I'm missing something simple, but I just can't see it.
You could use the onComplete event from your SSJS eventhandler to call a CSJS script like
XSP.partialRefreshGet("#{id:linkagesDisplayRepeat}");
to refresh the repeat control.
There's a second parameter to the client-side closeDialog() method, denoting the ID of the component to partially refresh. That basically adds the onComplete for you.
SSJS corresponding method uses the ID of the component to subsequently refresh as the only parameter (obviously the method is called on the component being closed, which is the first parameter in CSJS).
I ran in some troubles with a combobox. Here is a copy/paste example code to demonstrate my problem.
<xp:this.beforeRenderResponse><![CDATA[#{javascript://
viewScope.value1 = "document.getItemValueString('value1')" + viewScope.document;
viewScope.value2 = "document.getItemValueString('value2')" + viewScope.document;}]]>
</xp:this.beforeRenderResponse>
<xp:button
value="change document"
id="button1">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript: viewScope.document = new Date().getMilliseconds()//}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
<br></br>
<xp:comboBox id="comboBox1" value="#{viewScope.value3}">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:viewScope.value1;}]]></xp:this.value>
</xp:selectItems>
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:viewScope.value2;}]]></xp:this.value>
</xp:selectItems>
<xp:eventHandler
event="onchange" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript://}]]></xp:this.action>
</xp:eventHandler>
</xp:comboBox>
<br></br>
<xp:text escape="true" id="computedField1" value="#{viewScope.value1}"></xp:text>
<br></br>
<xp:text escape="true" id="computedField2" value="#{viewScope.value2}"></xp:text>
<br></br>
<xp:text escape="true" id="computedField3" value="#{viewScope.value3}"> </xp:text>
What did I try to accomplish: I have a combobox with two or more calculated selectItems. They depend on which document is currently selected. To demonstrate a switch of documents I use the button change document in this example. When a new document is selected the beforeRenderResponse event
gets the itemvalues from the document and puts them in a viewscope var. I have to separate the two values so I can't use a Array for them. That's all working so far but: If I select a value e.g. value2(timestamp1) and do a switch document the viewScope.value3 where the combobox is bound to did not update.
It displays the old value2 from the last document until I trigger its onChange event.
How can I force the comboBox to update its viewScope var with its selectItems?
Found a solution wich works at least for my copy/pase example:
<xp:this.beforeRenderResponse><![CDATA[#{javascript://
viewScope.value1 = "document.getItemValueString('value1')" + viewScope.document;
viewScope.value2 = "document.getItemValueString('value2')" + viewScope.document;
var list = new Array();
list.push(value1);
list.push(value2);
if(!#IsMember(viewScope.value3,list)){
viewScope.value3 = list[0];//list.pop();
}}]]>
</xp:this.beforeRenderResponse>
Now the viewScope.value3 gets changed to value1 if the documents is changed.
I am trying to change the display format of a date/time control based on a combo box selection. I thought it would be simple to do.
I am using a js if statement with getComponent instead of datasource.getValue as I thought it would grab the value before it is submitted. I receive an error that the component is null.
Can anyone explain why I am getting null here but in a computedField with getcomponent the value shows?
if (getComponent('comboBox1').getValue()==0)
{'both'}
else
{'date'}
The type of the converter is computed during page load, and during this it is not possible to access a component with getComponent method. Additionally, it is not possible to recompute the type of the converter this way. Event if you use the page load/dynamically trick, the type of the converter will not recomputed.
But you can change the type of the converter in the partial refresh:
<xp:comboBox id="comboBox1">
<xp:selectItem itemLabel="One" itemValue="1"></xp:selectItem>
<xp:selectItem itemLabel="Null" itemValue="0"></xp:selectItem>
<xp:eventHandler event="onchange" submit="true" refreshMode="partial" refreshId="inputText1">
<xp:this.action><![CDATA[#{javascript:
var cmp:com.ibm.xsp.component.xp.XspInputText = getComponent("inputText1");
var converter:com.ibm.xsp.convert.DateTimeConverter = cmp.getConverter();
var value = getComponent("comboBox1").getValue();
if( value == 0) {
converter.setType("both");
}else{
converter.setType("date");
}
}]]>
</xp:this.action>
</xp:eventHandler>
</xp:comboBox>
In this example, the datefield is inputText1 and looks like this:
<xp:inputText id="inputText1">
<xp:this.converter>
<xp:convertDateTime type="time" />
</xp:this.converter>
<xp:dateTimeHelper />
</xp:inputText>
I suspect this is a silly question, but here goes...
I have two fields on a custom control, both are bound to managed bean properties (as opposed to document fields). The second field is only rendered when a specific value is chosen in the first field.
What I am seeing is that the setter for the second field is not firing after it has been rendered (the getter is firing just fine).
I have worked around the problem by computing the CSS display property on the second field to be block or none depending on the value in the first field. Everything works fine in this situation, it seems to be specifically related to whether the second field is rendered when the page is first loaded.
***Edit
Here's the sample code block:
<div class="control-group">
<xp:label value="Party Type:" id="partytypelabel" for="party_typetv">
</xp:label>
<div class="controls">
<xp:comboBox id="party_typetv" value="#{InvolvedRecord.partytypetv}"
required="true" defaultValue=""
readonly="#{javascript:!InvolvedManager.isInEditMode()}">
<xp:selectItem itemLabel="<select>" itemValue="">
</xp:selectItem>
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:InvolvedManager.getPartyTypes()}]]></xp:this.value>
</xp:selectItems>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" disableValidators="true" refreshId="partyfields">
</xp:eventHandler>
</xp:comboBox>
</div>
</div>
<xp:panel id="partyfields" tagName="fieldset">
<xp:this.rendered><![CDATA[#{javascript:InvolvedManager.hasPartyType()}]]></xp:this.rendered>
<xp:div styleClass="control-group">
<xp:label for="Adverse_Party_TypeTL" value="Type:" id="adversepartytypelabel">
</xp:label>
<div class="controls">
<span>
<xp:comboBox id="Adverse_Party_TypeTL"
value="#{InvolvedRecord.adversepartytypetl}" readonly="#{javascript:!InvolvedManager.isInEditMode()}">
<xp:selectItem itemLabel="<select>"
itemValue="">
</xp:selectItem>
<xp:selectItem itemLabel="Company" itemValue="Company">
</xp:selectItem>
<xp:selectItem itemLabel="Individual" itemValue="Individual">
</xp:selectItem>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" disableValidators="true" refreshId="adversepartyfields">
</xp:eventHandler>
</xp:comboBox>
</span>
</div>
</xp:div>
</xp:panel>
***End Edit
This is running on an 8.5.3 server.
Has anyone seen anything like this or maybe offer an explanation as I am confused!
You could render the component in all phases except the renderphase. This would allow to set the value during update phase, but would hide it to the client.
Here is an example:
Conditionally hidden edit box in a partially refreshed panel
EDIT:
<xp:this.rendered>
<![CDATA[#{javascript:
if( view.isRenderingPhase() ){
return InvolvedManager.hasPartyType();
}else{
return true;
}
}]]>
</xp:this.rendered>
Are you actually entering data into these fields after they have been rendered? I have found on many occasions that a field specifically bound to a managed bean does not actually even do anything unless some data has been entered into it. For instance, I have seen this: render the field dynamically, don't do anything to it, save the data source, no field whatsoever on the document. If I do that same activity but add data to the field, then it all works. Not an answer. Just some info.
Really looking for an idea why my XPage is doing this.
I have field with a dynamic databinding:
<xp:inputText id="CORE_Input" value="#{Document[compositeData.PARA_DataBinding]}"</xp:inputText>
That works quit well until I start to hide it based on a notes formula.
Let me tell what it does: I click a checkbox in my XPage. That checkbox is running SSJS which is calling: Document.getDocument(true) to push the data from my XPage back into the notesdocument without saving it. Once that is done I can use session.evaluate("checkbox!="something"") to hide the inputText field.
It works quit well but the problem is that once I untick the checkbox the value is gone from the inputfield.
If you know a better way to use notes formulas for hiding or the reason why the inputfield is empty once it comes back would be highly appreciated. Here is an example:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:checkBox id="checkBox1" value="#{Document.Check}" text="hide" checkedValue="hide">
<xp:eventHandler event="onchange" submit="false">
<xp:this.script><![CDATA[document.getElementById("#{id:hide}").click()]]></xp:this.script>
</xp:eventHandler>
</xp:checkBox>
<xp:panel id="test">
<xp:inputText id="CORE_Input" type="#{compositeData.NODE}"
value="#{Document[compositeData.PARA_DataBinding]}"
defaultValue="#{javascript:compositeData.PARA_DefaultValue}" style="margin-left:24px">
<xp:this.styleClass><![CDATA[#{javascript:DOMElement.getAttribute("stylesize");}]]></xp:this.styleClass> <xp:this.rendered><![CDATA[#{javascript:var doc:NotesXspDocument=Document;
var erg=session.evaluate('Check="hide"',doc.getDocument());
if(#Text(erg)=="1")
{return false}
else
{return true}}]]></xp:this.rendered>
</xp:inputText>
<xp:button value="hide" id="hide">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="test">
<xp:this.action>
<![CDATA[#{javascript:var doc:NotesXspDocument=Document;doc.getDocument(true)}]]></xp:this.action>
</xp:eventHandler></xp:button>
<xp:button value="unhide" id="unhide">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="test">
<xp:this.action><![CDATA[#{javascript:sessionScope.hide=""}]]></xp:this.action>
</xp:eventHandler></xp:button>
</xp:panel></xp:view>
The problem you have is your default value: As soon the component is unhidden, the value is recalculated. You have to check if the component is partially refreshed. If so, stop the recalculation:
<xp:this.defaultValue>
<![CDATA[#{javascript:
importPackage( com.ibm.xsp.ajax );
if( AjaxUtil.isAjaxPartialRefresh(facesContext) == true )
return;
compositeData.PARA_DefaultValue
}]]>
</xp:this.defaultValue>
This should solve your problem