Method does not execute when boolean parameter has a value of false - codefluent

I have isolated the problem to the following lines of code in the BOM method that calls the stored procedure:
if ((includeAgeSeventeenAndUnder == CodeFluentPersistence.DefaultBooleanValue))
{
return null;
}
if ((includeAgeEighteenAndOver == CodeFluentPersistence.DefaultBooleanValue))
{
return null;
}
Because CodeFluentPersistence.DefaultBooleanValue equals False. Anytime a parameter of false is passed to the method, the method exits and returns null. How can I prevent this?

I got it working by setting the modeNullable to true.
<cf:method name="Load">
<cf:body text="LOADONE(date startDate, date endDate, bool includeAgeSeventeenAndUnder, bool includeAgeEighteenAndOver,int sisProgramId) RAW " rawText="This has been deleted because it is not relevent to question" language="tsql" />
<cf:parameter typeName="bool" name="includeAgeSeventeenAndUnder" modelNullable="True" />
<cf:parameter typeName="bool" name="includeAgeEighteenAndOver" modelNullable="True" />
</cf:method>
Meziantou suggestion is actually preferable since I really don't want the parameters to be nullable. The below snippet demonstrates the correct way to disable the default value check.
<cf:method name="Load">
<cf:body text="LOADONE(date startDate, date endDate, bool includeAgeSeventeenAndUnder, bool includeAgeEighteenAndOver,int sisProgramId) RAW " rawText="This has been deleted because it is not relevent to question" language="tsql" />
<cf:parameter typeName="bool" cfom:checkDefaultValue="false" name="includeAgeSeventeenAndUnder" modelNullable="False" />
<cf:parameter typeName="bool" cfom:checkDefaultValue="false" name="includeAgeEighteenAndOver" modelNullable="False" />
</cf:method>

Related

Excepted int for property "maxLength" of sap fiori Input component

Current I am trying to metadata binding xml, following this blog. When I did the maxLength of Input. But I got the following error.
error screenshot
demo service
init model with destination:
initModel: function() {
var sServiceUrl = "/odsrv/V2/Northwind/Northwind.svc/";
var oModel = new OM(sServiceUrl, true);
this.setModel(oModel, "oRefModel");
sap.ui.getCore().setModel(oModel, "oRefModel");
}
xml view:
<content>
<Label text="{oRefModel>/#Category/CategoryName/#type}"/>
<Input maxLength="{oRefModel>/#Category/CategoryName/#maxLength}"/>
</content>
The Label for type works fine if remove Input.
How to solve this problem...
Version with expression binding could be like that
<Input maxLength="{= isNaN(${oRefModel>/#Category/CategoryName/#maxLength}) ? 0 : parseInt(${oRefModel>/#Category/CategoryName/#maxLength})" />
typeof check is needed cause at the start of binding process value of property probably is 'NaN' and it gives an error and whole process will stop.
If you can improve that version please do :)
<Input maxLength="{parts:[{path:'oRefModel>/#Category/CategoryName/#maxLength'}],formatter: 'your.formatter.toNum' }" />
Formatter Code
toNum : function(maxlen){
return parseInt(maxlen);;
}
Converting string to integer is the key
Even shorter and without writing a custom formatter function: Use the built-in parseInt function.
<Input
maxLength="{
path: 'oRefModel>/#Category/CategoryName/#maxLength',
formatter: 'parseInt'
}" />
For some reasons expression binding does not work, maybe someone could tell me why:
<Input maxLength="{= parseInt(${oRefModel>/#Category/CategoryName/#maxLength}) }" />

Primefaces Calender Date comparison only works within the same month

I have two calendars. It shouldn´t be possible for the user to pick a date in calendar two that is before the date in calendar one. Also if calender one picks a value that is after calendar two, calender two should change automatically to the same date as calendar one.
This is the index.html. "vom" is Calendar one and "bis" is calendar two.
<p:calendar id="vom" value="#{IndexBean.vom}" maxlength="50"
navigator="true" pattern="dd.mm.yyyy" locale="de" mask="true" >
<f:ajax event="dateSelect" execute="vom" listener="#{IndexBean.dateChanger}" render="vom bis" />
</p:calendar>
<p:calendar id="bis" value="#{IndexBean.bis}" maxlength="50"
navigator="true" pattern="dd.mm.yyyy" locale="de" mask="true" mindate="#{IndexBean.vom}">
<f:ajax event="dateSelect" execute="bis" listener="#{IndexBean.dateChanger}" render="vom bis"/>
</p:calendar>
This is the dateChanger method
public void dateChanger() {
try {
if (bis.before(vom)) {
bis = (Date) vom.clone();
}
} catch (Exception e) {
}
}
The problem is everything works fine as long both calendars are in the same month. I debugged the dateChanger and I´m realy confused about the values coming from the calendars. It doesn´t seem to be dependent of the browser. The type of the dates is java.util.date.
Any clue why this happens?
Java 1.8
JSF 2.2.14
You use a wrong pattern. In
pattern="dd.mm.yyyy"
the mm means 'minutes' and not 'month'. Month is 'MM' so change it to
pattern="dd.MM.yyyy"

what error is in the code snippet below?

I have the following jsp code which uses struts tag:
<input type = "radio"
id = "<s:property value="name"/>"
name = "<s:property value="name"/>"
value = "<s:property value="value"/>"
<s:if test="fieldValue==null">
<s:if test="defaultOption==true">
checked="checked"
</s:if>
</s:if>
<s:else>
<s:if test="value==fieldValue">
checked="checked"
</s:if>
</s:else>
/>
Eclipse says that:
Start tag (input) not closed properly, expected >.
But I cannot find where is the error. Please help.
It is probably an eclipse bug because with Netbeans there is no error
if you dont want to see the error with Eclipse (and in that case only) :
in the first if, put test like that :
fieldValue==null && defaultOption==true
and get rid of the internal if
it should be the same
PS : try to find a way to use s:radio maybe
Eclipse complains because it does not accept tags (for example <s:if>) inside input tag, you can deactivate JSP validation as suggested in comments .
Go to project properties and uncheck JSP Content Validator, then clean your project
If you don't want to disable validation, here is a suggested solution:
<s:if test="fieldValue==null">
<s:if test="defaultOption==true">
<input type = "radio" id = "<s:property value="name"/>" name = "<s:property value="name"/>" value = "<s:property value="value"/>" checked="checked" />
</s:if>
</s:if>
<s:else>
<s:if test="value==fieldValue">
<input type = "radio" id = "<s:property value="name"/>" name = "<s:property value="name"/>" value = "<s:property value="value"/>" checked="checked" />
</s:if>
</s:else>
Just as a note, your JSP code give same result(I guess it's just for illustration :) ).

How to declare dynamic form field defaults inside a Coldfusion CFC?

I'm looking for a way to declare form default values dynamically in a CFC, I'm calling via AJAX. The current CFC sends orders, which I need to break down into sub-orders.
I had been using this:
<!--- static defaults --->
<cffunction name="Defaults" access="public" returntype="struct" output="false"
hint="Assign default values to instance">
<cfscript>
var formDefaults = {
versenden=""
, speichern=""
...
}
</cfscript>
<cfreturn formDefaults />
</cffunction>
<cffunction name="Commit" access="public" returntype="struct" output="false" hint="database handler">
<!--- add dynamic form fields --->
<cfscript>
var LOCAL = {};
variables.defs = THIS.Defaults();
</cfscript>
<cfloop collection="#VARIABLES.Instance.FormData#" item="formField">
<cfscript>
if ( LEFT(formField, 5) EQ "MENGE"
OR LEFT(formField, 3) EQ "EAN"
OR LEFT(formField, 12) EQ "BESTELL_TEXT"
OR LEFT(formField, 10) EQ "BESTELLTYP"
...
) {
variables.defs[formField]="";
}
</cfscript>
</cfloop>
<cfscript>
structAppend(variables.defs, VARIABLES.Instance.FormData);
LOCAL.Basket = variables.defs;
</cfscript>
...
So I first declare static form fields (single instance only) and then try to dynamically append dynamic form fields to my array, which might be transferred multiple times (MENGE38, MENGE39, MENGE40 etc)
While this works ok, I need to add another counting element to my form-names, so I would have to change MENGE to something like counter.MENGE or MENGE.counter which will then send form values like this:
MENGE.1.38
MENGE.1.40
MENGE.1.41
MENGE.2.37
With the counter denoting the sub-order, this field is used for.
Problem is, this breaks my dynamic form field declaration and I don't understand why. I'm getting the following errors:
Diagnose: Element MENGE.1 is undefined in a CFML structure referenced as part of an expression.
Question:
Can anyone give me a hint on what the problem might be? Do I have to param the form fields on the HTML page as well (shouldn't have to)?
Thanks!
EDIT:
Problem was in my validate function, I also need to declare the modifications I did above. The new function looks like this:
<cffunction name="Validate" access="public" returntype="array" output="false" hint="validate form inputs and return an array of faulty field names.">
<cfscript>
var LOCAL = {};
var double = structNew();
double.form = VARIABLES.Instance.FormData;
double.criteria = VARIABLES.Instance.Validation;
</cfscript>
<!--- add dynamic form fields for validation... I FORGOT TO UPDATE THIS--->
<cfloop collection="#VARIABLES.Instance.FormData#" item="formField">
<cfscript>
if ( LEFT(formField, 5) EQ "MENGE"
OR LEFT(formField, 10) EQ 'BESTELLTYP'
OR LEFT(formField, 3) EQ "EAN"
OR LEFT(formField, 12) EQ "BESTELL_TEXT"
...
) {
VARIABLES.Instance.Validation[formField]="pass";
}
</cfscript>
</cfloop>
<!--- Get error names and type --->
<cfinvoke component="form_validate" method="validate_fields" double="#double#" returnvariable="validation_errors"></cfinvoke>
<cfset LOCAL.ErrorMessages = validation_errors />
<cfreturn LOCAL.ErrorMessages />
Because I did not add the new updated the if-clause in this function, I was getting the error.
To build on Dan Bracuk's answer, use underscores (though you'd need to change the name of "BESTELL_TEXT"). Use this with a combination of listFirst, listGetAt, and listLast to determine field name structure, using underscore as delimiter. Note how I cleaned up your big IF a bit using list function. This code as written probably doesn't do what you need, but wanted to illustrate the concepts without having to understand your business need.
<cfscript>
var orders=structNew();
item=listFirst(formField,'_');
orderNames = "MENGE,EAN,BESTELLTEXT,BESTELLTYPE";
if (listFindNoCase(orderNames,item,'_')){
if (!structKeyExists(orders,item)){
// initialize item
orders[item]=structNew();
}
orderID="";
subOrderId="";
if (listLen(formField,'_') gt 1) {
orderID=listGetAt(formField,2,'_');
}
if (listLen(formField,'_') eq 2) {
orders[item][orderId]=formData[formField];
}
if (listLen(formField,'_') eq 3) {
subOrderId=listLast(formField,'_');
orders[item][orderId][subOrderId]=formData[formField];
}
}
</cfscript>

Automatically update database with checkboxs that are unticked (false)

I currently update my database records with an input like this
$this->my_model->update($id, $this->input->post()));
(This is after I have performed a validation on all the input. The "model" also has a white_list of data to expect.)
Problem: if I am updating a checkbox, and it is "unticked" (i.e. 'false') - then that field is not 'posted' by the browser.
For example - if I tick checkbox_two - but leave checkbox_one unticked, $_POST shows:
[field_one] = "some value"
[field_two] = "some value"
[checkbox_two] = 1
Therefore my model will not update that field - since it is not part of the post.
The same does not happen in reverse - because a "ticked" checkbox is posted as "1" - and thus is correctly updated.
[field_one] = "some value"
[field_two] = "some value"
[checkbox_one] = 1
[checkbox_two] = 1
Question: Does anyone have an elegant solution to handle this, other than having to always specifically check for each checkbox?
<input type="hidden" name="example" value="FALSE" />
<input type="checkbox" name="example" value="TRUE" />
This practice is easy and logical. If checkbox is checked, $this->input->post('example') == 'TRUE' else, $this->input->post('example') == 'FALSE'.
The latest given value of a name="" overrides previous, thus givin prio checkbox > hidden.
EDIT: this solution is equal to given most rated answer in Rick Calder's comment. I've also come to this conclusion on my own, though.