Codename One TextArea Padding has no effect - codenameone

Both the TextField and the TextArea in the attached image have the same UIID. I have set the left padding be 1 mm using theme designer.
You can see that the left padding is applied to the TextField but not the TextArea.
I have also attempted to set it manually in the code using gui_TextArea.getAllStyles().setPaddingLeft(1); and gui_textArea.getAllStyles().setPadding(1,1,1,1); to no effect.
There does not appear to be a setTextUIID() method for TextArea.
How do we set the padding for this component?
Full source per Steve's request:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.this.that.gui;
import com.codename1.ui.Button;
import com.codename1.ui.Component;
import com.codename1.ui.Container;
import com.codename1.ui.Dialog;
import com.codename1.ui.Display;
import com.codename1.ui.TextField;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.layouts.FlowLayout;
import com.codename1.ui.layouts.LayeredLayout;
import com.codename1.ui.plaf.Style;
import com.this.that.Constants;
import com.this.that.Main;
import com.this.that.util.MyNetwork;
import com.this.that.util.MyToolbar;
import com.this.that.util.MyValidator;
import com.this.that.util.User;
import java.util.HashMap;
import java.util.Map;
/**
* GUI builder created Form
*/
public class Contact extends com.codename1.ui.Form {
private User user;
public Contact() {
this(com.codename1.ui.util.Resources.getGlobalResources());
}
public Contact(com.codename1.ui.util.Resources resourceObjectInstance) {
initGuiBuilderComponents(resourceObjectInstance);
Style s = gui_Message.getAllStyles();
s.setPaddingUnit(Style.UNIT_TYPE_DIPS);
s.setPadding(6, 6, 6, 6);
this.revalidate();
}
//-- DON'T EDIT BELOW THIS LINE!!!
private com.codename1.ui.Container gui_welcomeContainer = new com.codename1.ui.Container(new com.codename1.ui.layouts.BorderLayout());
private com.codename1.ui.Label gui_null = new com.codename1.ui.Label();
private com.codename1.ui.Container gui_BodyContainer = new com.codename1.ui.Container(new com.codename1.ui.layouts.BoxLayout(com.codename1.ui.layouts.BoxLayout.Y_AXIS));
private com.codename1.ui.Label gui_spacer1 = new com.codename1.ui.Label();
private com.codename1.ui.TextField gui_Subject = new com.codename1.ui.TextField();
private com.codename1.ui.TextArea gui_Message = new com.codename1.ui.TextArea();
private com.codename1.ui.Button gui_SubmitButton = new com.codename1.ui.Button();
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void guiBuilderBindComponentListeners() {
EventCallbackClass callback = new EventCallbackClass();
gui_SubmitButton.addActionListener(callback);
}
class EventCallbackClass implements com.codename1.ui.events.ActionListener, com.codename1.ui.events.DataChangedListener {
private com.codename1.ui.Component cmp;
public EventCallbackClass(com.codename1.ui.Component cmp) {
this.cmp = cmp;
}
public EventCallbackClass() {
}
public void actionPerformed(com.codename1.ui.events.ActionEvent ev) {
com.codename1.ui.Component sourceComponent = ev.getComponent();
if(sourceComponent.getParent().getLeadParent() != null && (sourceComponent.getParent().getLeadParent() instanceof com.codename1.components.MultiButton || sourceComponent.getParent().getLeadParent() instanceof com.codename1.components.SpanButton)) {
sourceComponent = sourceComponent.getParent().getLeadParent();
}
if(sourceComponent == gui_SubmitButton) {
onSubmitButtonActionEvent(ev);
}
}
public void dataChanged(int type, int index) {
}
}
private void initGuiBuilderComponents(com.codename1.ui.util.Resources resourceObjectInstance) {
guiBuilderBindComponentListeners();
setLayout(new com.codename1.ui.layouts.BoxLayout(com.codename1.ui.layouts.BoxLayout.Y_AXIS));
setInlineStylesTheme(resourceObjectInstance);
setScrollableY(false);
setInlineStylesTheme(resourceObjectInstance);
setTitle("");
setName("Contact");
addComponent(gui_welcomeContainer);
gui_welcomeContainer.setUIID("welcomeContainer");
gui_welcomeContainer.setInlineStylesTheme(resourceObjectInstance);
gui_welcomeContainer.setName("welcomeContainer");
((com.codename1.ui.layouts.BorderLayout)gui_welcomeContainer.getLayout()).setCenterBehavior(com.codename1.ui.layouts.BorderLayout.CENTER_BEHAVIOR_CENTER);
gui_welcomeContainer.addComponent(com.codename1.ui.layouts.BorderLayout.CENTER, gui_null);
gui_null.setText("Contact Us");
gui_null.setUIID("welcomeLabel");
gui_null.setInlineStylesTheme(resourceObjectInstance);
addComponent(gui_BodyContainer);
gui_BodyContainer.setInlineStylesTheme(resourceObjectInstance);
gui_BodyContainer.setName("BodyContainer");
gui_BodyContainer.addComponent(gui_spacer1);
gui_BodyContainer.addComponent(gui_Subject);
gui_BodyContainer.addComponent(gui_Message);
gui_BodyContainer.addComponent(gui_SubmitButton);
gui_spacer1.setText(" ");
gui_spacer1.setInlineStylesTheme(resourceObjectInstance);
gui_spacer1.setName("spacer1");
gui_Subject.setScrollVisible(true);
gui_Subject.setHint(" Subject");
gui_Subject.setUIID("TextField");
gui_Subject.setInlineStylesTheme(resourceObjectInstance);
gui_Subject.setName("Subject");
gui_Subject.setColumns(20);
gui_Message.setHint(" Please enter a brief message");
gui_Message.setUIID("TextField");
gui_Message.setInlineStylesTheme(resourceObjectInstance);
gui_Message.setName("Message");
gui_Message.setMaxSize(1000);
gui_Message.setColumns(20);
gui_Message.setRows(10);
gui_SubmitButton.setText("Submit");
gui_SubmitButton.setInlineStylesTheme(resourceObjectInstance);
gui_SubmitButton.setName("SubmitButton");
gui_SubmitButton.setTextPosition(com.codename1.ui.Component.BOTTOM);
gui_welcomeContainer.setUIID("welcomeContainer");
gui_welcomeContainer.setInlineStylesTheme(resourceObjectInstance);
gui_welcomeContainer.setName("welcomeContainer");
((com.codename1.ui.layouts.BorderLayout)gui_welcomeContainer.getLayout()).setCenterBehavior(com.codename1.ui.layouts.BorderLayout.CENTER_BEHAVIOR_CENTER);
gui_BodyContainer.setInlineStylesTheme(resourceObjectInstance);
gui_BodyContainer.setName("BodyContainer");
}// </editor-fold>
//-- DON'T EDIT ABOVE THIS LINE!!!
public void onSubmitButtonActionEvent(com.codename1.ui.events.ActionEvent ev) {
if (gui_Subject.getText().equals("") || gui_Message.getText().equals("")) {
Main.showDialog("You must enter all fields.");
} else {
if (user.getName() == null || user.getEmail() == null) {
requestNameOrEmail();
}
else{
sendMessage(false);
}
}
}
private void requestNameOrEmail(){
Dialog d = new Dialog(new BoxLayout(BoxLayout.Y_AXIS));
d.setTitle("Require Name/Email to Send");
Container nameLayeredLayout = new Container(new LayeredLayout());
TextField name = new TextField();
name.setHint("Name");
nameLayeredLayout.add(name);
Container emailLayeredLayout = new Container(new LayeredLayout());
TextField email = new TextField();
email.setHint("Email");
emailLayeredLayout.add(email);
if(user.getName() != null){
name.setText(user.getName());
}
if(user.getEmail() != null){
email.setText(user.getEmail());
}
Map<String, Boolean> validatorParams = new HashMap<>();
validatorParams.put("name", false);
validatorParams.put("email", false);
MyValidator v = new MyValidator(validatorParams);
v.setupLengthConstraint(nameLayeredLayout, name, 2, 30, "name", "Name must be 2-30 characters.");
v.setupEmailConstraint(emailLayeredLayout, email, "email", "Email not valid.");
Container buttonCnt = new Container();
Button cancel = new Button("Cancel");
cancel.addActionListener((l) -> {
d.dispose();
});
Button submit = new Button("Submit");
submit.addActionListener((l) -> {
if (v.isValid()) {
d.dispose();
sendMessage(true);
}
});
buttonCnt.add(cancel).add(submit);
d.add(nameLayeredLayout).add(emailLayeredLayout).add(FlowLayout.encloseCenter(buttonCnt));
d.show();
}
private void sendMessage(boolean updateUser) {
Map<String, String> params = new HashMap<>();
params.put("update_user",String.valueOf(updateUser));
params.put("sender_name", user.getName());
params.put("sender_email", user.getEmail());
params.put("sender_udid", Display.getInstance().getUdid());
params.put("subject", gui_Subject.getText());
params.put("message", gui_Message.getText());
MyNetwork.getInstance().getNetworkObject("POST", Constants.SEND_EMAIL, params, "noDialog");
Main.showDialog("Message sent.");
Home form = new Home();
MyToolbar.getInstance().setupToolbar(form);
form.show();
}
}
Here is the .gui for the form
<?xml version="1.0" encoding="UTF-8"?>
<component type="Form" layout="BoxLayout" boxLayoutAxis="Y" scrollableY="false" title="" name="Contact">
<component type="Container" layout="BorderLayout" borderLayoutAbsoluteCenter="true" uiid="welcomeContainer" name="welcomeContainer">
<component type="Label" uiid="welcomeLabel" text="Contact Us">
<layoutConstraint value="Center" />
</component>
</component>
<component type="Container" layout="BoxLayout" boxLayoutAxis="Y" name="BodyContainer">
<component type="Label" text=" " name="spacer1">
</component>
<component type="TextField" uiid="TextField" hint=" Subject" scrollVisible="true" columns="20" constraint="0" name="Subject">
</component>
<component type="TextArea" uiid="TextField" hint=" Please enter a brief message" rows="10" columns="20" maxSize="1000" constraint="0" name="Message">
</component>
<component type="Button" text="Submit" textPosition="2" name="SubmitButton" actionEvent="true">
</component>
</component>
</component>
Here are the relevant lines from theme.xml (uiid is set to TextField)
<gradient key="TextArea.bgGradient" color1="0" color2="0" posX="0.5" posY="0.5" radius="1.0" />
<val key="TextArea.bgType" value="0" />
<border key="TextArea.border" type="image" i1="TextField.borderTop_1.png" i2="TextField.borderBottom_1.png" i3="TextField.borderLeft_1.png" i4="TextField.borderRight_1.png" i5="TextField.borderTopL_1.png" i6="TextField.borderTopR_1.png" i7="TextField.borderBottomL_1.png" i8="TextField.borderBottomR_1.png" i9="TextField.borderCenter_1.png" />
<val key="TextArea.fgColor" value="0" />
<font key="TextArea.font" type="ttf" face="0" style="0" size="0" name="native:MainRegular" family="native:MainRegular" sizeSettings="3" actualSize="3.0" />
<val key="TextArea.marUnit" value="2,2,2,2" />
<val key="TextArea.margin" value="1.0,1.0,1.0,1.0" />
<val key="TextArea.padUnit" value="2,2,2,2" />
<val key="TextArea.padding" value="0.0,0.0,2.0,1.0" />
<gradient key="TextArea.press#bgGradient" color1="0" color2="0" posX="0.5" posY="0.5" radius="1.0" />
<val key="TextArea.press#bgType" value="0" />
<border key="TextArea.press#border" type="image" i1="TextField.borderTop_1.png" i2="TextField.borderBottom_1.png" i3="TextField.borderLeft_1.png" i4="TextField.borderRight_1.png" i5="TextField.borderTopL_1.png" i6="TextField.borderTopR_1.png" i7="TextField.borderBottomL_1.png" i8="TextField.borderBottomR_1.png" i9="TextField.borderCenter_1.png" />
<val key="TextArea.press#fgColor" value="0" />
<font key="TextArea.press#font" type="ttf" face="0" style="0" size="0" name="native:MainRegular" family="native:MainRegular" sizeSettings="3" actualSize="3.0" />
<val key="TextArea.press#marUnit" value="2,2,2,2" />
<val key="TextArea.press#margin" value="1.0,1.0,1.0,1.0" />
<val key="TextArea.press#padUnit" value="2,2,2,2" />
<val key="TextArea.press#padding" value="0.0,0.0,2.0,1.0" />
<val key="TextArea.press#transparency" value="0" />
<gradient key="TextArea.sel#bgGradient" color1="0" color2="0" posX="0.5" posY="0.5" radius="1.0" />
<val key="TextArea.sel#bgType" value="0" />
<border key="TextArea.sel#border" type="image" i1="TextField.borderTop_1.png" i2="TextField.borderBottom_1.png" i3="TextField.borderLeft_1.png" i4="TextField.borderRight_1.png" i5="TextField.borderTopL_1.png" i6="TextField.borderTopR_1.png" i7="TextField.borderBottomL_1.png" i8="TextField.borderBottomR_1.png" i9="TextField.borderCenter_1.png" />
<val key="TextArea.sel#fgColor" value="0" />
<font key="TextArea.sel#font" type="ttf" face="0" style="0" size="0" name="native:MainRegular" family="native:MainRegular" sizeSettings="3" actualSize="3.0" />
<val key="TextArea.sel#marUnit" value="2,2,2,2" />
<val key="TextArea.sel#margin" value="1.0,1.0,1.0,1.0" />
<val key="TextArea.sel#padUnit" value="2,2,2,2" />
<val key="TextArea.sel#padding" value="0.0,0.0,2.0,1.0" />
<val key="TextArea.sel#transparency" value="0" />
<val key="TextArea.transparency" value="0" />
<gradient key="TextField.bgGradient" color1="0" color2="0" posX="0.5" posY="0.5" radius="1.0" />
<val key="TextField.bgType" value="0" />
<border key="TextField.border" type="image" i1="TextField.borderTop_1.png" i2="TextField.borderBottom_1.png" i3="TextField.borderLeft_1.png" i4="TextField.borderRight_1.png" i5="TextField.borderTopL_1.png" i6="TextField.borderTopR_1.png" i7="TextField.borderBottomL_1.png" i8="TextField.borderBottomR_1.png" i9="TextField.borderCenter_1.png" />
<val key="TextField.fgColor" value="0" />
<font key="TextField.font" type="ttf" face="0" style="0" size="0" name="native:MainRegular" family="native:MainRegular" sizeSettings="3" actualSize="3.0" />
<val key="TextField.marUnit" value="2,2,2,2" />
<val key="TextField.margin" value="1.0,1.0,1.0,1.0" />
<val key="TextField.padUnit" value="0,2,0,2" />
<val key="TextField.padding" value="0.0,0.0,2.0,1.0" />
<gradient key="TextField.press#bgGradient" color1="0" color2="0" posX="0.5" posY="0.5" radius="1.0" />
<val key="TextField.press#bgType" value="0" />
<border key="TextField.press#border" type="image" i1="TextField.borderTop_1.png" i2="TextField.borderBottom_1.png" i3="TextField.borderLeft_1.png" i4="TextField.borderRight_1.png" i5="TextField.borderTopL_1.png" i6="TextField.borderTopR_1.png" i7="TextField.borderBottomL_1.png" i8="TextField.borderBottomR_1.png" i9="TextField.borderCenter_1.png" />
<val key="TextField.press#fgColor" value="0" />
<font key="TextField.press#font" type="ttf" face="0" style="0" size="0" name="native:MainRegular" family="native:MainRegular" sizeSettings="3" actualSize="3.0" />
<val key="TextField.press#marUnit" value="2,2,2,2" />
<val key="TextField.press#margin" value="1.0,1.0,1.0,1.0" />
<val key="TextField.press#padUnit" value="0,2,0,2" />
<val key="TextField.press#padding" value="0.0,0.0,1.0,1.0" />
<val key="TextField.press#transparency" value="0" />
<gradient key="TextField.sel#bgGradient" color1="0" color2="0" posX="0.5" posY="0.5" radius="1.0" />
<val key="TextField.sel#bgType" value="0" />
<border key="TextField.sel#border" type="image" i1="TextField.borderTop_1.png" i2="TextField.borderBottom_1.png" i3="TextField.borderLeft_1.png" i4="TextField.borderRight_1.png" i5="TextField.borderTopL_1.png" i6="TextField.borderTopR_1.png" i7="TextField.borderBottomL_1.png" i8="TextField.borderBottomR_1.png" i9="TextField.borderCenter_1.png" />
<val key="TextField.sel#fgColor" value="0" />
<font key="TextField.sel#font" type="ttf" face="0" style="0" size="0" name="native:MainRegular" family="native:MainRegular" sizeSettings="3" actualSize="3.0" />
<val key="TextField.sel#marUnit" value="2,2,2,2" />
<val key="TextField.sel#margin" value="1.0,1.0,1.0,1.0" />
<val key="TextField.sel#padUnit" value="0,2,0,2" />
<val key="TextField.sel#padding" value="0.0,0.0,1.0,1.0" />
<val key="TextField.sel#transparency" value="0" />
<val key="TextField.transparency" value="0" />
Here is a screenshot of the Theme Designer showing padding for Selected TextField UIID. Padding in millimeters is also applied to unselected and pressed. Both components share this UIID but the padding is only appearing on the text field component, not the text area component. This behavior does not change if the lines that I added in the code to set padding are present or not.
You see in the screenshot that left and right are both in mm while top/bottom are in pixels. I also set it so that all four units are mm and it did not change the behavior.
(We are using CN1 v4.0)

To resolve the issue, I ended up doing the following:
Reverted my project to a prior commit that did not have any padding styling for TextArea or TextField
In the Theme Designer I edited the padding on each state one-by-one instead of copying the styling from one state to another.
I am suspecting but cannot say for certain that the issue was caused by the act of copy/pasting the styling in the Theme Designer. AFAIK that is the only difference between the working and non-working versions of the styling. I seem to recall running into issues when doing copy/paste in the designer in the past.

setPaddingLeft(1); would override setPadding(1,1,1,1); and visa versa. You need to make sure that you do these things before the form is shown and if you do them after you need to revalidate as this will impact layout.
However, in your case I'm guessing you need to invoke setPaddingUnit(Style.UNIT_TYPE_DIPS); to make sure that padding is in a visible unit. Make sure to invoke that before the setPadding call.
Form hi = new Form("Padding", BoxLayout.y());
TextArea unpadded = new TextArea("Unpadded");
TextArea padded = new TextArea("Padded");
Style s = padded.getAllStyles();
s.setPaddingUnit(Style.UNIT_TYPE_DIPS);
s.setPadding(6, 6, 6, 6);
hi.addAll(unpadded, padded);
hi.show();

Related

Getting DevExtreme gnatt data after updating chart with React

So basically, how do I get the new data from the DevExtreme Chart after making an update? I just want to get the the task data so that I can then upload it to my database. The
DevExtreme documentation isn't helping at all in relation to listening to changes made and getting the new data when the change has been made. I tried using onOptionChanged but the only outputs I can get ar HTML elements.
import React from 'react'
import { dependencies, tasks } from '#/data/data'
import Gantt, { Tasks, Dependencies, Toolbar, Item, Column, Validation, Editing } from 'devextreme-react/gantt'
const GanttChart = () => {
return (
<div>
<h5 className="font-medium leading-tight text-xl mt-0 mb-2 text-blue-600">Set Timeline Chart</h5>
<p className="italic">Edit by clicking either the chart or the the table values</p>
<Gantt
taskListWidth={500}
scaleType="quarters"
onOptionChanged={e => console.log(e)}
height={700}>
<Tasks dataSource={tasks} />
<Dependencies dataSource={dependencies} />
<Toolbar>
<Item name="undo" />
<Item name="redo" />
<Item name="separator" />
<Item name="collapseAll" />
<Item name="expandAll" />
<Item name="separator" />
<Item name="addTask" />
<Item name="deleteTask" />
<Item name="separator" />
<Item name="zoomIn" />
<Item name="zoomOut" />
</Toolbar>
<Column dataField="title" caption="Subject" width={300} />
<Column dataField="start" caption="Start Date" />
<Column dataField="end" caption="End Date" />
<Validation autoUpdateParentTasks />
<Editing enabled />
</Gantt>
</div>
)
}
export default GanttChart

Update XML stored in a XML column in SQL Server Update

Set Url value by applying filter based on location-type value from given sample.
<page id="{Page_ID}" name="" type="dat" size="0" sequence="26" originalpagenumber="26" location_type="3" location="">
<content description="" content_format="26" />
<AdditionalInfo>
<Url>https://s3-eu-west-1/2019/may//001063/gvb140/683c82a3-b3f5-49ee-a34e-01859e8e2228.mp3</Url>
<Name />
<Encoding>audio</Encoding>
<SecurityType>IBCloud</SecurityType>
</AdditionalInfo>
The XML you've shared is invalid so I've taken the liberty to make it valid in an effort to show you how I might approach this.
I've made the assumption you're looking to update values in a table somewhere in your environment. You can run this example in SSMS.
THIS IS MEANT AS AN EXAMPLE ONLY. DO NOT BLINDLY RUN THIS AGAINST PRODUCTION DATA.
First, I created a mock-up table that holds some page XML data. I assumed that a single XML row could contain multiple page nodes with duplicate location_type values.
DECLARE #Pages TABLE ( page_xml XML );
INSERT INTO #Pages ( page_xml ) VALUES (
'<pages>
<page id="{Page_ID}" name="" type="dat" size="0" sequence="26" originalpagenumber="26" location_type="3" location="">
<content description="" content_format="26" />
<AdditionalInfo>
<Url>https://s3-eu-west-1/2019/may//001063/gvb140/683c82a3-b3f5-49ee-a34e-01859e8e2228.mp3</Url>
<Name />
<Encoding>audio</Encoding>
<SecurityType>IBCloud</SecurityType>
</AdditionalInfo>
</page>
<page id="{Page_ID}" name="" type="dat" size="0" sequence="27" originalpagenumber="27" location_type="3" location="">
<content description="" content_format="27" />
<AdditionalInfo>
<Url>https://s3-eu-west-1/2019/may//001063/gvb140/683c82a3-b3f5-49ee-a34e-01859e8e2228.mp3</Url>
<Name />
<Encoding>audio</Encoding>
<SecurityType>IBCloud</SecurityType>
</AdditionalInfo>
</page>
<page id="{Page_ID}" name="" type="dat" size="0" sequence="28" originalpagenumber="28" location_type="8" location="">
<content description="" content_format="28" />
<AdditionalInfo>
<Url>https://s3-eu-west-1/2019/may//001063/gvb140/683c82a3-b3f5-49ee-a34e-01859e8e2228.mp3</Url>
<Name />
<Encoding>audio</Encoding>
<SecurityType>IBCloud</SecurityType>
</AdditionalInfo>
</page>
</pages>' );
Selecting the current results from #Pages shows the following XML:
<pages>
<page id="{Page_ID}" name="" type="dat" size="0" sequence="26" originalpagenumber="26" location_type="3" location="">
<content description="" content_format="26" />
<AdditionalInfo>
<Url>https://s3-eu-west-1/2019/may//001063/gvb140/683c82a3-b3f5-49ee-a34e-01859e8e2228.mp3</Url>
<Name />
<Encoding>audio</Encoding>
<SecurityType>IBCloud</SecurityType>
</AdditionalInfo>
</page>
<page id="{Page_ID}" name="" type="dat" size="0" sequence="27" originalpagenumber="27" location_type="3" location="">
<content description="" content_format="27" />
<AdditionalInfo>
<Url>https://s3-eu-west-1/2019/may//001063/gvb140/683c82a3-b3f5-49ee-a34e-01859e8e2228.mp3</Url>
<Name />
<Encoding>audio</Encoding>
<SecurityType>IBCloud</SecurityType>
</AdditionalInfo>
</page>
<page id="{Page_ID}" name="" type="dat" size="0" sequence="28" originalpagenumber="28" location_type="8" location="">
<content description="" content_format="28" />
<AdditionalInfo>
<Url>https://s3-eu-west-1/2019/may//001063/gvb140/683c82a3-b3f5-49ee-a34e-01859e8e2228.mp3</Url>
<Name />
<Encoding>audio</Encoding>
<SecurityType>IBCloud</SecurityType>
</AdditionalInfo>
</page>
</pages>
There are two pages with a location_type of 3, and one with a location_type of 8.
Next, I declared a few variables which I then used to modify the XML.
DECLARE #type INT = 3, #url VARCHAR(255) = 'http://www.google.com';
/* Update each Url text for the specified location_type */
WHILE EXISTS ( SELECT * FROM #Pages WHERE page_xml.exist( '//pages/page[#location_type=sql:variable("#type")]/AdditionalInfo/Url[text()!=sql:variable("#url")]' ) = 1 )
UPDATE #Pages
SET
page_xml.modify( '
replace value of (//pages/page[#location_type=sql:variable("#type")]/AdditionalInfo/Url/text()[.!=sql:variable("#url")])[1]
with sql:variable("#url")
' );
After running the update the XML now contains:
<pages>
<page id="{Page_ID}" name="" type="dat" size="0" sequence="26" originalpagenumber="26" location_type="3" location="">
<content description="" content_format="26" />
<AdditionalInfo>
<Url>http://www.google.com</Url>
<Name />
<Encoding>audio</Encoding>
<SecurityType>IBCloud</SecurityType>
</AdditionalInfo>
</page>
<page id="{Page_ID}" name="" type="dat" size="0" sequence="27" originalpagenumber="27" location_type="3" location="">
<content description="" content_format="27" />
<AdditionalInfo>
<Url>http://www.google.com</Url>
<Name />
<Encoding>audio</Encoding>
<SecurityType>IBCloud</SecurityType>
</AdditionalInfo>
</page>
<page id="{Page_ID}" name="" type="dat" size="0" sequence="28" originalpagenumber="28" location_type="8" location="">
<content description="" content_format="28" />
<AdditionalInfo>
<Url>https://s3-eu-west-1/2019/may//001063/gvb140/683c82a3-b3f5-49ee-a34e-01859e8e2228.mp3</Url>
<Name />
<Encoding>audio</Encoding>
<SecurityType>IBCloud</SecurityType>
</AdditionalInfo>
</page>
</pages>
Using the WHILE EXISTS (... ensures that all Url nodes for the requested location_type are updated. In my example here there are two pages with a value of 3 that are updated, while location_type 8 is left alone.
Basically, what this is doing is updating the Url for any page with the requested location_type to the new #url value.
There are two key pieces here, the first being:
.exist( '//pages/page[#location_type=sql:variable("#type")]/AdditionalInfo/Url[text()!=sql:variable("#url")]' )
Which looks for the requested location_type that doesn't have the new #url value.
And the second:
page_xml.modify( '
replace value of (//pages/page[#location_type=sql:variable("#type")]/AdditionalInfo/Url/text()[.!=sql:variable("#url")])[1]
with sql:variable("#url")
' );
Which modifies (updates) the Url for the location type that has yet to be updated. The two "conditions" allow for a loop (WHILE) that ends when they're no longer met, ensuring that all page nodes for the requested location_type are updated.

Problems querying

I'm trying to query the following XML the way I always do, but due to its declaration and the empty "NextQuantity" - "NextDate" fields, I'm having troubles querying the XML.
What's the right way to do this?
Thank you.
<StocksResp xmlns="http://xxxxxx" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Stocks>
<Stock>
<Sku>30101.06-L</Sku>
<Quantity>247610</Quantity>
<NextQuantity1>15243</NextQuantity1>
<NextDate1>2019-02-27</NextDate1>
<NextQuantity2 i:nil="true" />
<NextDate2 />
<NextQuantity3 i:nil="true" />
<NextDate3 />
<NextQuantity4 i:nil="true" />
<NextDate4 />
<NextQuantity5 i:nil="true" />
<NextDate5 />
<NextQuantity6 i:nil="true" />
<NextDate6 />
</Stock>
<Stock>
<Sku>30101.06-M</Sku>
<Quantity>241606</Quantity>
<NextQuantity1 i:nil="true" />
<NextDate1 />
<NextQuantity2 i:nil="true" />
<NextDate2 />
<NextQuantity3 i:nil="true" />
<NextDate3 />
<NextQuantity4 i:nil="true" />
<NextDate4 />
<NextQuantity5 i:nil="true" />
<NextDate5 />
<NextQuantity6 i:nil="true" />
<NextDate6 />
</Stock>
</Stocks>
<Count>4837</Count>
<Currency i:nil="true" />
<Language>ES</Language>
<ErrorCode i:nil="true" />
<ErrorMessage i:nil="true" />
</StocksResp>
===============================================
DECLARE #xml XML
SELECT #xml = x.y FROM OPENROWSET (BULK 'file.xml',SINGLE_BLOB) as x(y)
SELECT
x.y.value('Sku[1]','varchar(15)'),
x.y.value('Quantity[1]','int'),
x.y.value('NextDate1[1]','varchar(20)'),
x.y.value('NextQuantity1[1]','int'),
'mr'
FROM #xml.nodes('Stocks/Stock') x(y)
Might this help?
DECLARE #xml XML=
N'<StocksResp xmlns="http://xxxxxx" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Stocks>
<Stock>
<Sku>30101.06-L</Sku>
<Quantity>247610</Quantity>
<NextQuantity1>15243</NextQuantity1>
<NextDate1>2019-02-27</NextDate1>
<NextQuantity2 i:nil="true" />
<NextDate2 />
<NextQuantity3 i:nil="true" />
<NextDate3 />
<NextQuantity4 i:nil="true" />
<NextDate4 />
<NextQuantity5 i:nil="true" />
<NextDate5 />
<NextQuantity6 i:nil="true" />
<NextDate6 />
</Stock>
<Stock>
<Sku>30101.06-M</Sku>
<Quantity>241606</Quantity>
<NextQuantity1 i:nil="true" />
<NextDate1 />
<NextQuantity2 i:nil="true" />
<NextDate2 />
<NextQuantity3 i:nil="true" />
<NextDate3 />
<NextQuantity4 i:nil="true" />
<NextDate4 />
<NextQuantity5 i:nil="true" />
<NextDate5 />
<NextQuantity6 i:nil="true" />
<NextDate6 />
</Stock>
</Stocks>
<Count>4837</Count>
<Currency i:nil="true" />
<Language>ES</Language>
<ErrorCode i:nil="true" />
<ErrorMessage i:nil="true" />
</StocksResp>';
-You need to declare the default namespace. You would not need to declare the namespace i...
WITH XMLNAMESPACES(DEFAULT 'http://xxxxxx','http://www.w3.org/2001/XMLSchema-instance' AS i)
SELECT
#xml.value(N'(/StocksResp/Count/text())[1]',N'int') AS StockResp_Count
,#xml.value(N'(/StocksResp/Currency/text())[1]',N'int') AS StockResp_Currency
,st.value(N'(Sku/text())[1]',N'nvarchar(max)') AS Stock_Sku
,st.value(N'(Quantity/text())[1]',N'int') AS Stock_Quantity
,st.value(N'(NextQuantity1/text())[1]',N'int') AS Stock_NextQuantity1
,st.value(N'(NextDate1/text())[1]',N'date') AS Stock_NextDate1
,st.value(N'(NextQuantity2/text())[1]',N'int') AS Stock_NextQuantity2
,st.value(N'(NextDate2/text())[1]',N'date') AS Stock_NextDate2
,st.value(N'(NextQuantity3/text())[1]',N'int') AS Stock_NextQuantity3
,st.value(N'(NextDate3/text())[1]',N'date') AS Stock_NextDate3
,st.value(N'(NextQuantity4/text())[1]',N'int') AS Stock_NextQuantity4
,st.value(N'(NextDate4/text())[1]',N'date') AS Stock_NextDate4
,st.value(N'(NextQuantity5/text())[1]',N'int') AS Stock_NextQuantity5
,st.value(N'(NextDate5/text())[1]',N'date') AS Stock_NextDate5
,st.value(N'(NextQuantity6/text())[1]',N'int') AS Stock_NextQuantity6
,st.value(N'(NextDate6/text())[1]',N'date') AS Stock_NextDate6
FROM #xml.nodes('/StocksResp/Stocks/Stock') A(st);
Some remarks:
It is a very bad habit to name-number elements (Date1, Date2 and so on). If you can change this, you should use a nested set of elements and number them eiter by their position or with an attribute like
<Next index="1">
<Date>2018-01-01</Date>
<Quantity>1</Quantity>
</Next>
[... more of them ...]
you can see, that I read the just-once values directly from the variable, while the repeating elements are taken from a derived table by .nodes().

WPF log4net is not writing to the log file [duplicate]

This question already has an answer here:
WPF-Log4Net used inside VSIX extension did not output log when installed at target VS
(1 answer)
Closed 4 years ago.
I have a WPF solution. I downloaded log4net dll, I added log4net.config and had set the "Copy to Output Directory" value as "Copy always".
log4net.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="myapp.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
And I added the below line in AssemblyInfo.cs:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
then the below code in my TestWindowControl.xaml.cs
public partial class TestWindowControl : UserControl
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public TestWindowControl()
{
XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));
log.Info("info testing");
log.Debug("debug testing");
log.Error("error testing");
log.Fatal("fatal testing");
log.Warn("warn testing");
}
}
But logs are not writing to the file. It's working in Console application but not working for WPF. Am I missing something?
Try to set the filter inside appender
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="WARN" />
<levelMax value="ERROR" />
</filter>

PhoneGap - Jsonp Error 404 Not Found on call

Here is a commun error, but every solution give on Stack didn't solve my problem.
I have a phonegap app, my jsonp call send me a 404 error
Here is the function of the controller (angularjs) :
$scope.pullContent = function() {
$http.jsonp($scope.yourAPI+'/?page='+$scope.pageNumber+'&callback=JSON_CALLBACK').error(function(jqXHR, textStatus, errorThrown){
alert("### ERROR ###");
alert(textStatus +' // '+ errorThrown);
alert($scope.yourAPI+'?page='+$scope.pageNumber);
}).success(function(response) {
if($scope.pageNumber > response.pages){
// hide the more news button
$('#moreButton').fadeOut('fast');
} else {
$scope.items = $scope.items.concat(response.posts);
window.localStorage.setObject('rootsPosts', $scope.items); // we save the posts in localStorage
window.localStorage.setItem('rootsDate', new Date());
window.localStorage.setItem("rootsLastPage", $scope.currentPage);
window.localStorage.setItem("rootsTotalPages", response.pages);
// For dev purposes you can remove the comment for the line below to check on the console the size of your JSON in local Storage
// for(var x in localStorage)console.log(x+"="+((localStorage[x].length * 2)/1024/1024).toFixed(2)+" MB");
$scope.totalPages = response.pages;
$scope.isFetching = false;
if($scope.pageNumber == response.pages){
// hide the more news button
$('#moreButton').fadeOut('fast');
}
}
});
}
Here is my config.xml :
<content src="index.html" />
<access origin="*" />
<feature name="http://api.phonegap.com/1.0/network"/>
<preference name="KeyboardDisplayRequiresUserAction" value="true" />
<preference name="MediaPlaybackRequiresUserAction" value="false" />
<preference name="AllowInlineMediaPlayback" value="true" />
<preference name="DisallowOverscroll" value="true" />
<preference name="webviewbounce" value="false" />
<preference name="android-installLocation" value="auto" />
<icon gap:platform="android" gap:qualifier="ldpi" src="www/res/icon/android/android-icon-36x36.png"/>
<icon gap:platform="android" gap:qualifier="mdpi" src="www/res/icon/android/android-icon-48x48.png"/>
<icon gap:platform="android" gap:qualifier="hdpi" src="www/res/icon/android/android-icon-72x72.png"/>
<icon gap:platform="android" gap:qualifier="xhdpi" src="www/res/icon/android/android-icon-96x96.png"/>
<gap:splash gap:platform="android" gap:qualifier="port-ldpi" src="www/res/screen/android/small.png"/>
<gap:splash gap:platform="android" gap:qualifier="port-mdpi" src="www/res/screen/android/medium.png"/>
<gap:splash gap:platform="android" gap:qualifier="port-hdpi" src="www/res/screen/android/large.png"/>
<gap:splash gap:platform="android" gap:qualifier="port-xhdpi" src="www/res/screen/android/xhdpi.png"/>
here is the result of "phonegap plugin list" :
cordova-plugin-whitelist 1.2.2 "Whitelist"
org.apache.cordova.inappbrowser 0.5.4 "InAppBrowser"
org.apache.cordova.network-information 0.2.14 "Network Information"
Can anybody have a solution for me ?
Add this config setting to your config.xml which should resolve the issue:
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />

Resources