CF Entity implicit getter putting space in front of number - coldfusion

I have the following object definition:
component persistent="true" table="settings" hint="Settings" extends="coldbox.system.orm.hibernate.ActiveEntity" {
property name="id" fieldtype="id" generator="native";
property name="type" ormtype="string" length="10" index="setting_type";
property name="name" ormtype="string" length="20" index="setting_name";
property name="ownerID" ormtype="integer" index="setting_ownerID";
property name="valueNumber" ormtype="float";
//return the appropriate value
public function getValue(){
return this.getValueNumber();
}
The problem I am having is that this.getValueNumber() is returning the number, but with spaces in front of it.
Wrapping it in trim() trim(this.getValueNumber()) doesn't remove the space before the number.
This doesn't seem to cause an issue when working with the number in CF, but it does when I place the number into a JS function and attempt to work with it in JS.
Has anyone come across this problem? Any way to stop it? It is happening on both cf9, cf10 and Railo 4.0.

Related

Consume webservice returning Complex objects in Coldfusion

We are using the Argus WS and I'm stuck at figuring out how to consume the GetUpdatedPricesInDateTimeRange method.
It returns a complex object type and I'm unable to access the element structure within the returned object.
Getting the error
Element <e.g. element name> is undefined in a Java object of type class org.tempuri.GetUpdatedPricesInDateTimeRangeResponseGetUpdatedPricesInDateTimeRangeResult.
Webservice is being invoked as follows:
<cfinvoke
webservice="http://www.argusmedia.com/ArgusWSVSTO/ArgusOnline.asmx?wsdl"
method="GetUpdatedPricesInDateTimeRange"
returnvariable="PricesResponse">
<cfinvokeargument name="authToken" value="#AuthToken#"/>
<cfinvokeargument name="fromDateTime" value="2017-03-01"/>
<cfinvokeargument name="toDateTime" value="2017-03-02"/>
<cfinvokeargument name="startId" value="0"/>
</cfinvoke>
Any pointers would be really helpful.
Edit 1: CFDump return variable
Edit 2: Based on Leigh's suggestion, this is what worked for me.
XML
PricesResponse.get_any()[2].getAsString()
The XML had namespaces in it, hence XML Search worked as follows:
XmlSearch(XMLDoc,"//*[local-name()='Element_Name']")
Based on Leigh's comment, get_any() method of the returnvariable can be used to get the underlying XML.
Dump of get_any() returns the array of Message Elements.
getAsString() method of get_any() returns the expected XML string.
<cfdump var="#PricesResponse.get_any()[1].getAsString()#">
Note : The intended XML can be in either of the MessageElement[] array element and not in the first one.
Note 2 : XMLSearch with namespaces in the XML worked as follows:
XmlSearch(XMLDoc,"//*[local-name()='Element_Name']")

Why h:selectBooleanCheckbox not is updated? [duplicate]

Here is the scenario (simplified):
There is a bean (call it mrBean) with a member and the appropriate getters/setters:
private List<String> rootContext;
public void addContextItem() {
rootContext.add("");
}
The JSF code:
<h:form id="a_form">
<ui:repeat value="#{mrBean.stringList}" var="stringItem">
<h:inputText value="#{stringItem}" />
</ui:repeat>
<h:commandButton value="Add" action="#{mrBean.addContextItem}">
<f:ajax render="#form" execute="#form"></f:ajax>
</h:commandButton>
</h:form>
The problem is, when clicking the "Add" button, the values that were entered in the <h:inputText/> that represent the Strings in the stringList aren't executed.
Actually, the mrBean.stringList setter (setStringList(List<String> stringList)) is never called.
Any idea why?
Some info -
I'm using MyFaces JSF 2.0 on Tomcat 6.
The String class is immutable and doesn't have a setter for the value. The getter is basically the Object#toString() method.
You need to get/set the value directly on the List instead. You can do that by the list index which is available by <ui:repeat varStatus>.
<ui:repeat value="#{mrBean.stringList}" varStatus="loop">
<h:inputText value="#{mrBean.stringList[loop.index]}" />
</ui:repeat>
You don't need a setter for the stringList either. EL will get the item by List#get(index) and set the item by List#add(index,item).

How do I append to a struct set in CFPROPERTY?

I'm using <cfproperty /> to make use of implicit getters and setters in ColdFusion (Railo).
However, for more complex values like structs and arrays, how can I append to these?
<cfproperty name="settings" type="struct" />
How can I append an item into the property called settings? If I do the following:
<cfset setSettings(structAppend(getSettings(), { "hello" = "world" })) />
I get the following error:
java.lang.NullPointerException
Am I missing something here? I'm new to the cfproperty tag and thought it would be a time saver, but I can't figure this out.
Also, as a bonus how would I set a default value to these complex data types?
Thanks,
Mikey
Couple things here...
<cfset setSettings(structAppend(getSettings(), { "hello" = "world" })) />
Settings is a struct but structAppend() returns a boolean. Do your struct appending before this line. Second, structs are always passed by reference, meaning, if you do getSettings() you get a struct, which you can make changes to. Another call to getSettings() will return the same struct with the updated settings.
All you need is this:
<cfset structAppend(getSettings(), { "hello" = "world" }) />
One last thing. You could be getting a null pointer exception because getSettings() starts uninitialized. In your cfc, in the constructor area (after your properties), you should set an initial settings struct, like this:
<cfset setSettings({}) />

Change message name

Here is the part of my WSDL. I'm using the code first approach.
<portType name="MyWebService">
<operation name="echoString"/>
<input message="echoString"/>
<output message="echoStringResponse"/>
</operation>
</portType>
What annotation should I add or change so to change this
<input message="echoString"/>
to read as
<input message="echoStringRequest"/>
Thanks all.
I am quite surprised myself, but after trying for a while I looked into the spec and it seems you cannot really do this in jax-ws (except in a non-standard way, depending on the implementation). Here is what the jax-ws 2.0 specification says on this issue. See Java to WSDL 1.1 Mapping, Section 3.5, page 32:
The value of a wsdl:message element’s name attribute is not
significant but by convention it is normally equal to the
corresponding operation name for input messages and the operation name
concatenated with “Response” for output messages. Naming of fault
messages is described in section section 3.7.
So the only option that comes to my mind is to rename your operation, for example by changing or adding a #WebMethod annotation. Here is an example:
#WebMethod(operationName = "echoStringRequest")
public String echoString(String echoStringRequest) {
return echoStringRequest;
}
This will generate the following portType:
<portType name="MyWebService">
<operation name="echoStringRequest">
<input message="tns:echoStringRequest"></input>
<output message="tns:echoStringRequestResponse"></output>
</operation>
</portType>
The decision of whether you are more happy with this version is up to you.
I've encountered this problem myself recently and stumbled upon this thread multiple times. In our application we have a JAX-WS servlet which must use the format of ...Request and ...Response.
After a few days of searching, I found the solution.
Let's say your echoStringRequest has one String property that should be echoed back in the response.
class EchoMessage {
private String message;
//add getter and setter
}
First add this annotation to the web service class:
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
Then annotate your web service method like this:
#WebMethod
#WebResult(name = "echoStringResponse")
public EchoMessage echoString (#WebParam(name = "echoStringRequest") EchoMessage inputMessage) {
...
}
Without the parameterStyle BARE annotation, JAX-WS would automatically generate messages like this:
<echoString>
<echoStringRequest>
...
</echoStringRequest>
</echoString>
With the annotation, the outer element does not exist anymore.
The #WebParam and #ReturnType annotations are needed to determine the names of the root elements in the SOAP request and response body.

Passing parameters as parameters in templates in JSF 2.0

I'm having difficulty finding support on this topic, because I know how to pass parameters to a template. What I want to do is pass parameters to not be used as parameters to the template but to a component within the template.
For example, in primefaces, you can write the following logic to create a button:
<p:commandButton action="#{printBean.print}">
<f:attribute name="report" value="report.jrxml" />
</p:commandButton>
This is all fine and good when I don't need to pass parameters. However, I need to construct a template which allows me to specify parameters to pass to the report dynamically. My first attempt was to do the following:
<p:commandButton actionListener="#{printBean.print}">
<f:attribute name="report" value="report.jrxml" />
<ui:insert name="reportParams" />
</p:commandButton>
Which would allow me to use the template in the following manner:
<ui:decorate template="templates/report.xhtml" >
<ui:define name="reportParams>
<f:attribute name="reportParam1" value="paramVal1" />
<f:attribute name="reportParam2" value="paramVal2" />
<f:attribute name="reportParam3" value="paramVal3" />
...
</ui:define>
</ui:decorate>
However parameters passed in this way are not received in my action listener in printBean, yet parameter "report" is. I think the attributes passed in this way are interpreted to mean that it is referring to the ui:define tag, and not to be inserted in the template as I would want.
Is there an alternative way of achieving the same way? Keep in mind I'm using JSF 2.0 and primefaces, but not Seam or any added libraries and ideally I would not have to add any libraries to make it work.
I apologize if an answer to this question already exists, but it's maddening searching for an answer to this question.
EDIT: The number of parameters is variable, meaning I can't simply use ui:param and put the value of that parameter as an attribute value within the template, because there could be many such parameters.
Use a composite component instead of a template.
Create this file /resources/mycomponents/printReport.xhtml:
<ui:component
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:p="http://primefaces.org/ui"
>
<cc:interface>
<!-- No attributes. -->
</cc:interface>
<cc:implementation>
...
<p:commandButton value="Print" action="#{printBean.print}" />
...
</cc:implementation>
</ui:component>
Use it as follows:
xmlns:my="http://java.sun.com/jsf/composite/mycomponents"
...
<my:printReport>
<f:attribute name="reportParam1" value="paramVal1" />
<f:attribute name="reportParam2" value="paramVal2" />
<f:attribute name="reportParam3" value="paramVal3" />
</my:printReport>
Rewrite the print method as follows:
public void print() {
UIComponent composite = UIComponent.getCurrentCompositeComponent(FacesContext.getCurrentInstance());
String reportParam1 = (String) composite.getAttributes().get("reportParam1");
String reportParam2 = (String) composite.getAttributes().get("reportParam2");
String reportParam3 = (String) composite.getAttributes().get("reportParam3");
// ...
}