XQuery [value()] issue for Dynamic SQL variable in Select Stateemt - sql

I'm try to make the code below dynamic as there can be different names for the 'name' attribute in the page 'node'.
When I run the code below it returns the error 'XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *''
I feel my main issue is in the line
'C.value('(/level1/level2/template/page/#name)[sql:variable("#Counter")]','NVARCHAR(MAX)') AS [Page Name]'
where I am trying to make '#counter' variable dynamic.
Does anyone have any solutions please?
XML FOR ID 9371
<level1>
<level2>
<template width="594" height="500">
<page Cid="1" name="Test Page Name" colour="-3355393">
<image Cid="8" x="432" y="8" w="148" h="95" KeyImage="32861" Ratio="y" />
<formattedText Cid="14" x="9" y="22" w="253" h="38">
<p>
<p>
Text
</p>
</p>
</formattedText>
</page>
<page Cid="6" name="Properties">
<formattedText Cid="7" x="200" y="148" w="208" h="228">
<p>
<p>
<t>Created by </t>
<t b="b">Joe Bloggs</t>
</p>
<p />
<p>
<t>Date published 30/05/2017</t>
</p>
</formattedText>
</page>
</template>
</level2>
</level1>
RESULTS FROM SQL Query
** Present Result
Page Name | Demographics
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Test Page Name | <page Cid="1" name="Test Page Name" colour="-3355393"><image Cid="8" x="432" y="8" w="148" h="95" KeyImage="32861" Ratio="y" /><formattedText Cid="14" x="9" y="22" w="253" h="38"><p><p>Text</p></p> </formattedText></page>
Test Page Name | <page><formattedText Cid="7" x="200" y="148" w="208" h="228"><p><p> <t>Created by </t><t b="b">Joe Bloggs</t></p><p /><p><t>Date published 30/05/2017</t> </p></formattedText></page>
** Desired Result
Page Name | Demographics
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Test Page Name | <page Cid="1" name="Test Page Name" colour="-3355393"><image Cid="8" x="432" y="8" w="148" h="95" KeyImage="32861" Ratio="y" /><formattedText Cid="14" x="9" y="22" w="253" h="38"><p><p>Text</p></p> </formattedText></page>
Properties | <page><formattedText Cid="7" x="200" y="148" w="208" h="228"><p><p> <t>Created by </t><t b="b">Joe Bloggs</t></p><p /><p><t>Date published 30/05/2017</t> </p></formattedText></page>
DECLARE #TableName VARCHAR(40),
#opxml AS XML,
#hDoc AS INT,
#SQL NVARCHAR (MAX)
SELECT #opxml =
a.[filedata]
FROM [database].[dbo].[xmlfile2] a
where [Id] = 9371
DECLARE #Counter INT
DECLARE #MaxNo INT
SET #Counter=1
SET #MaxNo=(SELECT
COUNT(CAST('<page>' + CAST(C.query('./child::node()') as nvarchar(max)) + '</page>' as xml))
FROM #opxml.nodes('/level1/level2/template/page') AS T(C))
WHILE ( #Counter <= #MaxNo)
BEGIN
SELECT
C.value('(/level1/level2/template/page/#name)[sql:variable("#Counter")]','NVARCHAR(MAX)') AS
[Page Name],
CAST('<page>' + CAST(C.query('./child::node()') as nvarchar(max)) + '</page>' as xml) AS [Page_XML]
, ROW_NUMBER() OVER (ORDER BY t.c)
FROM #opxml.nodes('/level1/level2/template/page') AS T(C)
SET #Counter = #Counter + 1
END

I think
SELECT
C.value('#name','NVARCHAR(MAX)') AS [Page Name],
C.query('<page>{node()}</page>') AS [Page_XML],
ROW_NUMBER() OVER (ORDER BY t.c)
FROM #opxml.nodes('/level1/level2/template/page') AS T(C)
might suffice to produce the wanted result without the need for a WHILE loop.
I think the original problem with the long path inside of value() (e.g. C.value('(/level1/level2/template/page/#name)[sql:variable("#Counter")]','NVARCHAR(MAX)')) is due to the static type checking of XQuery in SQL server and to avoid it you basically need to add another predicate that ensures the type checker knows a single value is returned e.g. C.value('(/level1/level2/template/page/#name)[sql:variable("#Counter")][1]','NVARCHAR(MAX)')
For me, the code
DECLARE #opxml AS XML
SET #opxml = N'<level1>
<level2>
<template width="594" height="500">
<page Cid="1" name="Test Page Name" colour="-3355393">
<image Cid="8" x="432" y="8" w="148" h="95" KeyImage="32861" Ratio="y" />
<formattedText Cid="14" x="9" y="22" w="253" h="38">
<p>
<p>
Text
</p>
</p>
</formattedText>
</page>
<page Cid="6" name="Properties">
<formattedText Cid="7" x="200" y="148" w="208" h="228">
<p>
<p>
<t>Created by </t>
<t b="b">Joe Bloggs</t>
</p>
<p />
<p>
<t>Date published 30/05/2017</t>
</p>
</p>
</formattedText>
</page>
</template>
</level2>
</level1>'
SELECT
C.value('#name','NVARCHAR(MAX)') AS [Page Name],
C.query('<page>{node()}</page>') AS [Page_XML],
ROW_NUMBER() OVER (ORDER BY t.c)
FROM #opxml.nodes('/level1/level2/template/page') AS T(C)
produces the table
Page Name Page_XML (Kein Spaltenname)
Test Page Name <page><image Cid="8" x="432" y="8" w="148" h="95" KeyImage="32861" Ratio="y" /><formattedText Cid="14" x="9" y="22" w="253" h="38"><p><p>
Text
</p></p></formattedText></page> 1
Properties <page><formattedText Cid="7" x="200" y="148" w="208" h="228"><p><p><t>Created by </t><t b="b">Joe Bloggs</t></p><p /><p><t>Date published 30/05/2017</t></p></p></formattedText></page> 2
so at least the Page_Name seems to be easily populated by using e.g. C.value('#name','NVARCHAR(MAX)') AS [Page Name]

Related

How do I pick a value from XML column in a table with a condition. XML form contains different page

I have a xml data column. The XML data contains a form with different page headers. Each page has radio type values. I need to pick the value from one page and its values.
I need the value 'id' from Page topic='Outreach' under that, Question value="Type of Outreach", in that i need the id="1" value and also i need the id value from Question value="Reason for Assessment".
Below is the sample xml data.
<Test name="Assessment " header="" logoimg="" background="" icon="" firstPage="1" allow_abort="1" is_um="0" is_hidden="0" do_only="1" status="1" locale_id="0" version="74" category_id="150011" maxQuestionID="37" id="10234" force_start="0" user_name=" ggg bbb">
<PAGE topic="Outreach " progress="5" background="" headerid="" footerid="" flush_concepts="1" lastPage="false" id="1">
<BRANCH_CONDITION>
<NEXT_PAGE id="2" />
</BRANCH_CONDITION>
<QUESTION value="Type of Outreach " defaultvalue="" style="" tooltip="" read_only="0" usability="5" prefer_concept="0" type="radio" validation="0" id="1" pagename="Outreach ">
<OPTIONS>
<OPTION value="Outbound Telephone " id="1" url="" score="0" />
<OPTION value="Inbound Telephone" id="2" url="" score="0" />
<OPTION value="In Person" id="3" url="" score="0" />
</OPTIONS>
</QUESTION>
<QUESTION value="Reason for Assessment " defaultvalue="" style="" tooltip="" read_only="0" usability="5" prefer_concept="0" type="radio" validation="0" id="2" pagename="Outreach ">
<OPTIONS>
<OPTION value="New" id="1" url="" score="0" />
<OPTION value="Annual" id="2" url="" score="0" />
<OPTION value="Triggering Event " id="3" url="" score="0" />
<OPTION value="LOC Review" id="4" url="" score="0" />
</OPTIONS>
</QUESTION>
I tried the following sql.
SELECT TABLE.META_DATA.value('(/QUESTION//id/node())[1]','int') as outReach
,TABLE.META_DATA.value('(/QUESTION//id/node())[1]','int') as ReasonForAssessment
FROM Table
Below is my expected result
+----------+---------------------+
| Outreach | ReasonForAssessment |
+----------+---------------------+
| 1 | 2 |
Several issues:
QUESTION is not the root of the XML so you must use // or walk down tree from root: /Test/PAGE/QUESTION/.
Adjust XPath to search by attribute with # prefix and not node search as id is an attribute (not child node) of QUESTION.
Adjust node index, [#], to return the corresponding #id attribute value.
Adjusted SQL:
SELECT TABLE.META_DATA.value('(//QUESTION/#id)[1]','int') as outReach
, TABLE.META_DATA.value('(//QUESTION/#id)[2]','int') as ReasonForAssessment
FROM Table;
-- outReach ReasonForAssessment
-- 1 2
Alternatively use bracketed conditionals for columns:
SELECT TABLE.META_DATA.value('(/Test/PAGE/QUESTION[#value=''Type of Outreach '']/#id)[1]','int') as outReach
, TABLE.META_DATA.value('(/Test/PAGE/QUESTION[#value=''Reason for Assessment '']/#id)[1]','int') as ReasonForAssessment
FROM Table;
-- outReach ReasonForAssessment
-- 1 2

dataExporter cannot be rendered because of form needing

I am trying to add dataExporter component to my table.
First I had {Exporters} beside pagination facet , then after a lot of tries I got this error in the console
HTML nesting warning on closing changes: element update not explicitly closed
I solved it also but now there is nothing appears in the Exporter facet. I googled it and found that I need a form in my page because of this commandlink submit a form , so it needs a form.
My Question here is how to apply this example in my project.
Here is my code.
<ui:composition template="/template.xhtml">
<ui:define name="title">
<h:outputText value="#{bundle.ViewLfmTitle}"></h:outputText>
</ui:define>
<ui:define name="body">
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green"
layout="table" />
</h:panelGroup>
<p:dialog header="Add Task" widgetVar="dlg" position="center center"
onShow="PF('dlg').initPosition()" modal="true" closeOnEscape="true"
resizable="false">
<h:form>
<h:panelGrid columns="2">
<p:outputLabel value="#{bundle.CreateTaskLabel_name}" for="name" />
<p:inputText id="name"
value="#{ViewLfmJpaController.newTaskDTO.name}"
title="#{bundle.CreateTaskTitle_name}" />
<p:outputLabel value="#{bundle.CreateTaskLabel_durationPerMonth}"
for="durationPerMonth" />
<p:inputText id="durationPerMonth"
value="#{ViewLfmJpaController.newTaskDTO.duration}"
title="#{bundle.CreateTaskTitle_durationPerMonth}" />
<p:outputLabel value="#{bundle.CreateTaskLabel_startDate}"
for="startDate" />
<p:calendar id="startDate"
value="#{ViewLfmJpaController.newTaskDTO.startDate}"
title="#{bundle.CreateTaskTitle_startDate}" pattern="d MMM yyyy"
effect="fold">
<f:convertDateTime pattern="d MMM yyyy" />
</p:calendar>
<p:outputLabel value="#{bundle.CreateTaskLabel_endDate}"
for="endDate" />
<p:calendar id="endDate"
value="#{ViewLfmJpaController.newTaskDTO.endDate}"
title="#{bundle.CreateTaskTitle_endDate}" pattern="d MMM yyyy"
effect="fold">
<f:convertDateTime pattern="d MMM yyyy" />
</p:calendar>
<f:facet name="footer">
<p:commandButton value="Add"
actionListener="#{ViewLfmJpaController.addTask}" update="Matrix"
oncomplete="PF('dlg').hide()" />
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
<p:dataTable id="Matrix" resizableColumns="true" scrollable="true"
scrollHeight="80%"
value="#{ViewLfmJpaController.selected.tasksDtoCollection}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"
var="item" resizeMode="expand" paginator="true" rows="10"
style="margin-bottom:20px">
<f:facet name="header">
Logical Framewrok Matrix
</f:facet>
<f:facet name="{Exporters}">
<p:commandLink>
<p:graphicImage name="../resources/images/pdf.jpg" width="24" />
<p:dataExporter type="pdf" target="Matrix" fileName="lfm" />
</p:commandLink>
</f:facet>
<p:column headerText="Index" colspan="1">
<c:forEach var="i" begin="1" end="#{ViewLfmJpaController.listSize}">
<p:outputLabel value="#{i}"></p:outputLabel>
</c:forEach>
</p:column>
<p:column headerText="Task Title">
<p:outputLabel value="#{item.name}"></p:outputLabel>
</p:column>
<p:column headerText="Start Date" colspan="3">
<p:outputLabel value="#{item.formatedStartDate}"></p:outputLabel>
</p:column>
<p:column headerText="End Date" colspan="3">
<p:outputLabel value="#{item.formatedEndDate}"></p:outputLabel>
</p:column>
<c:forEach var="i" begin="1"
end="#{ViewLfmJpaController.numberOfMonths}">
<p:column headerText="m ${i}" colspan="1"></p:column>
</c:forEach>
<p:column headerText="Exptected Outcomes" colspan="4">
<ui:repeat value="#{item.tasksExpectedOutcomesCollection}" var="teo">
<li><h:outputText value="#{teo.expectation}">
</h:outputText></li>
</ui:repeat>
</p:column>
</p:dataTable>
<p:commandButton value="Add Task" oncomplete="PF('dlg').show()"></p:commandButton>
</ui:define>
</ui:composition>
I FOUND THE SOLUTION BY MYSELF.
First : You have to know that you cannot make nested forms in your page.
Second : you have to know that to submit <p:dialog> </p:dialog> or to use <h:commandLink> </h:commandLink> you need to use form.
So I had removed the form in the dialog component and add a general component contains dialog and dataTable together

How to display button and status bar items in line

How to display below mentioned two group(marked in red circle) in line?
relevant code for the same is given below
<header>
<button name="mymod_assigned" class="oe_highlight" type="workflow" string="Assigned" state="new" />
<button name="mymod_negotiation" class="oe_highlight" type="workflow" string="In Negotiation" state="assigned" />
<button name="mymod_won" class="oe_highlight" type="workflow" string="Won" state="negotiating"/>
<button name="mymod_lost" class="oe_highlight" type="workflow" string="Lost" state="negotiating"/>
<field name="state" widget="statusbar"
statusbar_visible="new,assigned,negotiation,won,lost"
statusbar_colors='{
"new":"blue",
"assigned":"blue",
"negotiation":"blue",
"won":"red",
"lost":"red"
}'
/>
</header>
Try putting left group of buttons in one div with float:left and right group in another div with float:right.

iterator over display tag column in struts?

Hi friends i have developed an application of PhotoAlbum, in show photo jsp the page shows all user information along with their uploaded image names. the output it displays on jsp is similar to the below format.
==========================================================================
| NAME | FatherName |AGE|ADDRESS | PhotoList |
==========================================================================
|nathjo r | FATHERNAME |12 | XYZ |[asasdd, asada, asada, aasasada] |
|SRT | ERNAME |12 | XYZ |[1212, 1212, 1212] |
|SRY | ERNAME |12 | XYZ |[bb, ccas, asdda, da, qwqda, qwqda, qwqda] |
==========================================================================
as you can see it is perfect, the last column[PhotoList] is a list of strings. so my question is i want to do iteration [put logical iterator tag] on the last column to do additional operation depending on the number of element present in the last column along with displaying image names. so what i thought is like this i know it is wrong any suggestion to do it like that.
<display:table id="data" name="sessionScope.UserForm.userList" requestURI="/userAction.do" pagesize="3" >
<display:column property="name" title="NAME" sortable="true" />
<display:column property="fatherName" title="User Name" sortable="true" />
<display:column property="age" title="AGE" sortable="true" />
<display:column property="address" title="ADDRESS" sortable="true" />
<logic:iterate property="photolist" id="photoId" indexId="index">
***here i want to display the image name***
</logic:iterate>
</display:table>
Thanks in Advance
Lets have iterate tag inside the <display:column> tag something like this
<display:table id="data" name="sessionScope.UserForm.userList" requestURI="/userAction.do" pagesize="3" >
<display:column property="name" title="NAME" sortable="true" />
<display:column property="fatherName" title="User Name" sortable="true" />
<display:column property="age" title="AGE" sortable="true" />
<display:column property="address" title="ADDRESS" sortable="true" />
<display:column title="Photo List">
<logic:iterate property="photolist" id="photoId" indexId="index">
<s:property />,
</logic:iterate>
</display:column>
</display:table>

Problems with XUL Grid Layout

I'm working on creating an XUL app right now and I'm stuck with a few problems at this point. My current file is here: http://projects.thecloudonline.net/gemxul/regrid.xul.
I want that second column to essentially "float: right" (like how CSS works on webpages). The red background shows me that part moved, but my content is stuck oriented left. How can I make the content go along with it?
Secondly, my overall goal is to get it so that the layout is essentially split in half. Setting maxwidth="50%" on the first column doesn't seem to do anything. Is that the correct approach, or am I way off there?
That's all for now!
This should work :
<grid style="border: #000000 solid 1px;">
<columns>
<column style="border-right: #666666 solid 1px;"/>
<column flex="1"/>
<column style="background-color:red;"/>
</columns>
<rows>
<row>
<vbox>
<label value="Launcher 1" id="l1_title"/>
<button label="button" id="l1_btn" />
<label value="This is a description for item 1." id="l1_desc"/>
</vbox>
<spacer/>
<vbox>
<label value="Launcher 2" id="l2_title"/>
<button label="button" id="l2_btn"/>
<label value="This is a description for item 2." id="l2_desc"/>
</vbox>
</row>
<row style="border-top: #666666 solid 1px;">
<vbox>
<label value="Launcher 3" id="l3_title"/>
<button label="button" id="l3_btn"/>
<label value="This is a description for item 3." id="l3_desc"/>
</vbox>
<spacer/>
<vbox>
<label value="Launcher 4" id="l4_title"/>
<button label="button" id="l4_btn"/>
<label value="This is a description for item 4." id="l4_desc"/>
</vbox>
</row>
</rows>
</grid>
There are several ways of doing this. Personally I wouldn't use grid for something like this. vbox and hbox in combination beats anything you would normally do in tables. But of course it depends entirely what your end goal is.