问:
Retreiving value from node in parent level
I am having trouble retrieving value in node UsagePoin/mRID that is child of node MeterReading and sibling of node IntervalBlocks.

```<code>DECLARE @tbl TABLE (ID INT IDENTITY PRIMARY KEY, xml_data XML);
INSERT INTO @tbl (xml_data) VALUES
(N'<RequestMessage xmlns="http://iec.ch/TC57/2011/schema/message" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Message.xsd">
  <Header>
    <Verb>create</Verb>
    <Noun>MeterReadings</Noun>
    <Timestamp>2022-01-09T01:00:58+01:00</Timestamp>
    <Source>Y</Source>
    <AsyncReplyFlag>true</AsyncReplyFlag>
    <AckRequired>true</AckRequired>
    <MessageID>xyz_9999</MessageID>
    <CorrelationID></CorrelationID>
  </Header>
  <Payload>
    <MeterReadings xmlns="http://iec.ch/TC57/2011/MeterReadings#" xmlns:MeterReadings="http://iec.ch/TC57/2011/MeterReadings#">
      <MeterReading>
        <IntervalBlocks>
          <IntervalReadings>
            <source>999</source>
            <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
            <value>9.246</value>
            <ReadingQualities>
              <ReadingQualityType ref="3.0.0" />
            </ReadingQualities>
          </IntervalReadings>
          <IntervalReadings>
            <source>999</source>
            <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
            <value>10.404</value>
            <ReadingQualities>
              <ReadingQualityType ref="3.0.0" />
            </ReadingQualities>
          </IntervalReadings>
          <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0.3.72.0" />
        </IntervalBlocks>
        <Meter>
          <mRID>209558305</mRID>
        </Meter>
        <UsagePoint>
          <mRID>735999999999999999</mRID>
        </UsagePoint>
      </MeterReading>
      <MeterReading>
        <IntervalBlocks>
          <IntervalReadings>
            <source>999</source>
            <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
            <value>2.46</value>
            <ReadingQualities>
              <ReadingQualityType ref="3.0.0" />
            </ReadingQualities>
          </IntervalReadings>
          <IntervalReadings>
            <source>999</source>
            <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
            <value>2.52</value>
            <ReadingQualities>
              <ReadingQualityType ref="3.0.0" />
            </ReadingQualities>
          </IntervalReadings>
          <IntervalReadings>
            <source>999</source>
            <timeStamp>2022-01-08T02:00:00.000+01:00</timeStamp>
            <value>2.502</value>
            <ReadingQualities>
              <ReadingQualityType ref="3.0.0" />
            </ReadingQualities>
          </IntervalReadings>
          <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0.3.73.0" />
        </IntervalBlocks>
        <Meter>
          <mRID>999999999</mRID>
        </Meter>
        <UsagePoint>
          <mRID>735999999999999999</mRID>
        </UsagePoint>
      </MeterReading>
    </MeterReadings>
      </Payload>
</RequestMessage>');
</code>```

So I am using the following code.

```<code>WITH XMLNAMESPACES(N'http://iec.ch/TC57/2011/schema/message' as hdr,
                   N'http://iec.ch/TC57/2011/MeterReadings#' as mr)
SELECT
    --t.file_name,t.file_created_time received_timestamp,
    --h.value('(hdr:Timestamp)[1]', 'nvarchar(35)') AS created_timestamp,
    --h.value('(hdr:MessageID)[1]', 'nvarchar(50)') AS message_id,
    ir.value('(mr:timeStamp/text())[1]', 'nvarchar(35)') interval_timestamp,
    ir.value('(mr:value/text())[1]', 'nvarchar(35)') interval_value,
    ir.value('(mr:ReadingQualities/mr:ReadingQualityType/@ref)[1]', 'nvarchar(35)') interval_value_code
FROM
    load.capgemeni_sesp_xml t
OUTER APPLY
    t.xml_data.nodes('/hdr:RequestMessage/hdr:Header') AS m(h)
--OUTER APPLY
--    t.xml_data.nodes('/hdr:RequestMessage/hdr:Payload/mr:MeterReadings/mr:MeterReading') AS MeterReading(mr)
OUTER APPLY
    t.xml_data.nodes('/hdr:RequestMessage/hdr:Payload/mr:MeterReadings/mr:MeterReading/mr:IntervalBlocks/mr:IntervalReadings') AS IntervalReadings(ir)
where t.file_name = 'SESP_32717237.xml'
AND ir.value('(mr:timeStamp/text())[1]', 'nvarchar(35)') = '2022-01-08T00:00:00.000+01:00'
</code>```

It gives me output for each timestamp = '2022-01-08T00:00:00.000+01:00'. Now i need to add the UsagePoint and the ReadingType nodes. Both of them are in parent node level.

I tried traversing up hierarchy using following

```<code>ir.value('(./mr:ReadingType/@ref)[1]','nvarchar(35)')
</code>```

It doesn't work. I assumed using ./ would traverse up from within node IntervalReadings to being within node IntervalBlocks and then it should be mr:ReadingType to traverse into node ReadingType and then @ref for getting the value in the "ref" tag.

I can't figure out why it isn't working. I am having similar issue with getting data from node mRID which is within node UsagePoint which is sibling to node IntervalBlocks within node MeterReading. For each UsagePoint can be 1 or more ReadingType which then have interval values on same level.

Whatever working solution I find for ReadingType will be able to be used to also get values for UsagePoint.

EDIT: To clarify i can produce out that looks like this...

It is showing values for the timestamp '2022-01-08T00:00:00.000+01:00' but i can't add ReadingType or UsagePoint correctly. When i for example try to add ReadingType i get null...

EDIT2:
For each IntervalBlocks node you have IntervalReadings node which then has x amount of interval values and on same level as IntervalBlocks node you will have the UsagePoint for the values and within the IntervalBlocks node on same level as IntervalReadings will have 1 or more ReadingType node. The ReadingType will be after a payload of values signifying the ReadingType is for that batch of values. 1 UsagePoint can have up to 4 ReadingType values.
I should have clarified data modell by having at least 2 UsagePoint and 2 ReadingType in the XML.

I am running SQL Server 2019.
Microsoft SQL Server 2019 (RTM-CU14) (KB5007182) - 15.0.4188.2 (X64)   Nov  3 2021 19:19:51   Copyright (C) 2019 Microsoft Corporation  Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2016 Standard 10.0  (Build 14393: ) (Hypervisor)

答:
Please try the following solution.

SQL

```<code>-- DDL and sample data population, start
DECLARE @tbl TABLE (ID INT IDENTITY PRIMARY KEY, xml_data XML);
INSERT INTO @tbl (xml_data) VALUES
(N'<RequestMessage xmlns="http://iec.ch/TC57/2011/schema/message" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Message.xsd">
    <Header>
        <Verb>create</Verb>
        <Noun>MeterReadings</Noun>
        <Timestamp>2022-01-09T01:00:58+01:00</Timestamp>
        <Source>Y</Source>
        <AsyncReplyFlag>true</AsyncReplyFlag>
        <AckRequired>true</AckRequired>
        <MessageID>xyz_9999</MessageID>
        <CorrelationID></CorrelationID>
        <Property>
            <Name>CONTRACT</Name>
            <Value>xxxx</Value>
        </Property>
        <Property>
            <Name>DIVISION</Name>
            <Value>01</Value>
        </Property>
        <Property>
            <Name>RECEIVER</Name>
            <Value>xxx</Value>
        </Property>
        <Property>
            <Name>SERVICE</Name>
            <Value>xxxx</Value>
        </Property>
    </Header>
    <Payload>
        <MeterReadings xmlns="http://iec.ch/TC57/2011/MeterReadings#" xmlns:MeterReadings="http://iec.ch/TC57/2011/MeterReadings#">
            <MeterReading>
                <IntervalBlocks>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
                        <value>9.246</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
                        <value>10.404</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0.3.72.0"/>
                </IntervalBlocks>
                <IntervalBlocks>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
                        <value>9.246</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
                        <value>10.404</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0.3.72.0"/>
                </IntervalBlocks>
                <Meter>
                    <mRID>xxxx</mRID>
                </Meter>
                <UsagePoint>
                    <mRID>zzzz</mRID>
                </UsagePoint>
            </MeterReading>
            <MeterReading>
                <IntervalBlocks>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
                        <value>9.246</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
                        <value>10.404</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0.3.72.0"/>
                </IntervalBlocks>
                <IntervalBlocks>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
                        <value>9.246</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
                        <value>10.404</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0.3.72.0"/>
                </IntervalBlocks>
                <Meter>
                    <mRID>kkkkk</mRID>
                </Meter>
                <UsagePoint>
                    <mRID>qqqqq</mRID>
                </UsagePoint>
            </MeterReading>
        </MeterReadings>
    </Payload>
</RequestMessage>');
-- DDL and sample data population, end

WITH XMLNAMESPACES(N'http://iec.ch/TC57/2011/schema/message' as hdr,
                   N'http://iec.ch/TC57/2011/MeterReadings#' as mr)
SELECT
    --t.file_name,t.file_created_time received_timestamp,
    --h.value('(hdr:Timestamp)[1]', 'nvarchar(35)') AS created_timestamp,
    --h.value('(hdr:MessageID)[1]', 'nvarchar(50)') AS message_id,
     ir.value('(mr:timeStamp/text())[1]', 'nvarchar(35)') interval_timestamp
    , ir.value('(mr:value/text())[1]', 'nvarchar(35)') interval_value
    , ir.value('(mr:ReadingQualities/mr:ReadingQualityType/@ref)[1]', 'nvarchar(35)') interval_value_code
    , mr.value('(mr:UsagePoint/mr:mRID/text())[1]', 'nvarchar(50)') UsagePoint
    , ir.value('(../mr:ReadingType/@ref)[1]', 'nvarchar(35)') ReadingType
FROM @tbl t
OUTER APPLY t.xml_data.nodes('/hdr:RequestMessage/hdr:Header') AS m(h)
OUTER APPLY t.xml_data.nodes('/hdr:RequestMessage/hdr:Payload/mr:MeterReadings/mr:MeterReading') AS MeterReading(mr)
OUTER APPLY MeterReading.mr.nodes('mr:IntervalBlocks/mr:IntervalReadings') AS IntervalReadings(ir)
--WHERE --t.file_name = 'SESP_32717237.xml' AND
--  ir.value('(mr:timeStamp/text())[1]', 'nvarchar(35)') = '2022-01-08T00:00:00.000+01:00'
</code>```

Output

```<code>+-------------------------------+----------------+---------------------+------------+-------------------------------------+
|      interval_timestamp       | interval_value | interval_value_code | UsagePoint |             ReadingType             |
+-------------------------------+----------------+---------------------+------------+-------------------------------------+
| 2022-01-08T00:00:00.000+01:00 |          9.246 |               3.0.0 | zzzz       | 11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0. |
| 2022-01-08T01:00:00.000+01:00 |         10.404 |               3.0.0 | zzzz       | 11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0. |
| 2022-01-08T00:00:00.000+01:00 |          9.246 |               3.0.0 | zzzz       | 11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0. |
| 2022-01-08T01:00:00.000+01:00 |         10.404 |               3.0.0 | zzzz       | 11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0. |
| 2022-01-08T00:00:00.000+01:00 |          9.246 |               3.0.0 | qqqqq      | 11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0. |
| 2022-01-08T01:00:00.000+01:00 |         10.404 |               3.0.0 | qqqqq      | 11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0. |
| 2022-01-08T00:00:00.000+01:00 |          9.246 |               3.0.0 | qqqqq      | 11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0. |
| 2022-01-08T01:00:00.000+01:00 |         10.404 |               3.0.0 | qqqqq      | 11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0. |
+-------------------------------+----------------+---------------------+------------+-------------------------------------+
</code>```

Body:
I am having trouble retrieving value in node UsagePoin/mRID that is child of node MeterReading and sibling of node IntervalBlocks.

DECLARE @tbl TABLE (ID INT IDENTITY PRIMARY KEY, xml_data XML);
INSERT INTO @tbl (xml_data) VALUES
(N'<RequestMessage xmlns="http://iec.ch/TC57/2011/schema/message" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Message.xsd">

    <Verb>create</Verb>
    <Noun>MeterReadings</Noun>
    <Timestamp>2022-01-09T01:00:58+01:00</Timestamp>
    <Source>Y</Source>
    <AsyncReplyFlag>true</AsyncReplyFlag>
    <AckRequired>true</AckRequired>
    <MessageID>xyz_9999</MessageID>
    <CorrelationID></CorrelationID>

  <Payload>
    <MeterReadings xmlns="http://iec.ch/TC57/2011/MeterReadings#" xmlns:MeterReadings="http://iec.ch/TC57/2011/MeterReadings#">
      <MeterReading>
        <IntervalBlocks>
          <IntervalReadings>
            <source>999</source>
            <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
            <value>9.246</value>
            <ReadingQualities>
              <ReadingQualityType ref="3.0.0" />
            </ReadingQualities>
          </IntervalReadings>
          <IntervalReadings>
            <source>999</source>
            <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
            <value>10.404</value>
            <ReadingQualities>
              <ReadingQualityType ref="3.0.0" />
            </ReadingQualities>
          </IntervalReadings>
          <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0.3.72.0" />
        </IntervalBlocks>
        <Meter>
          <mRID>209558305</mRID>
        </Meter>
        <UsagePoint>
          <mRID>735999999999999999</mRID>
        </UsagePoint>
      </MeterReading>
      <MeterReading>
        <IntervalBlocks>
          <IntervalReadings>
            <source>999</source>
            <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
            <value>2.46</value>
            <ReadingQualities>
              <ReadingQualityType ref="3.0.0" />
            </ReadingQualities>
          </IntervalReadings>
          <IntervalReadings>
            <source>999</source>
            <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
            <value>2.52</value>
            <ReadingQualities>
              <ReadingQualityType ref="3.0.0" />
            </ReadingQualities>
          </IntervalReadings>
          <IntervalReadings>
            <source>999</source>
            <timeStamp>2022-01-08T02:00:00.000+01:00</timeStamp>
            <value>2.502</value>
            <ReadingQualities>
              <ReadingQualityType ref="3.0.0" />
            </ReadingQualities>
          </IntervalReadings>
          <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0.3.73.0" />
        </IntervalBlocks>
        <Meter>
          <mRID>999999999</mRID>
        </Meter>
        <UsagePoint>
          <mRID>735999999999999999</mRID>
        </UsagePoint>
      </MeterReading>
    </MeterReadings>
      </Payload>
</RequestMessage>');

So I am using the following code.

WITH XMLNAMESPACES(N'http://iec.ch/TC57/2011/schema/message' as hdr,
                   N'http://iec.ch/TC57/2011/MeterReadings#' as mr)
SELECT
    --t.file_name,t.file_created_time received_timestamp,
    --h.value('(hdr:Timestamp)[1]', 'nvarchar(35)') AS created_timestamp,
    --h.value('(hdr:MessageID)[1]', 'nvarchar(50)') AS message_id,
    ir.value('(mr:timeStamp/text())[1]', 'nvarchar(35)') interval_timestamp,
    ir.value('(mr:value/text())[1]', 'nvarchar(35)') interval_value,
    ir.value('(mr:ReadingQualities/mr:ReadingQualityType/@ref)[1]', 'nvarchar(35)') interval_value_code
FROM
    load.capgemeni_sesp_xml t
OUTER APPLY
    t.xml_data.nodes('/hdr:RequestMessage/hdr:Header') AS m(h)
--OUTER APPLY
--    t.xml_data.nodes('/hdr:RequestMessage/hdr:Payload/mr:MeterReadings/mr:MeterReading') AS MeterReading(mr)
OUTER APPLY
    t.xml_data.nodes('/hdr:RequestMessage/hdr:Payload/mr:MeterReadings/mr:MeterReading/mr:IntervalBlocks/mr:IntervalReadings') AS IntervalReadings(ir)
where t.file_name = 'SESP_32717237.xml'
AND ir.value('(mr:timeStamp/text())[1]', 'nvarchar(35)') = '2022-01-08T00:00:00.000+01:00'

It gives me output for each timestamp = '2022-01-08T00:00:00.000+01:00'. Now i need to add the UsagePoint and the ReadingType nodes. Both of them are in parent node level.

I tried traversing up hierarchy using following

ir.value('(./mr:ReadingType/@ref)[1]','nvarchar(35)')

It doesn't work. I assumed using ./ would traverse up from within node IntervalReadings to being within node IntervalBlocks and then it should be mr:ReadingType to traverse into node ReadingType and then @ref for getting the value in the "ref" tag.

I can't figure out why it isn't working. I am having similar issue with getting data from node mRID which is within node UsagePoint which is sibling to node IntervalBlocks within node MeterReading. For each UsagePoint can be 1 or more ReadingType which then have interval values on same level.

Whatever working solution I find for ReadingType will be able to be used to also get values for UsagePoint.

EDIT: To clarify i can produce out that looks like this...

It is showing values for the timestamp '2022-01-08T00:00:00.000+01:00' but i can't add ReadingType or UsagePoint correctly. When i for example try to add ReadingType i get null...

EDIT2:
For each IntervalBlocks node you have IntervalReadings node which then has x amount of interval values and on same level as IntervalBlocks node you will have the UsagePoint for the values and within the IntervalBlocks node on same level as IntervalReadings will have 1 or more ReadingType node. The ReadingType will be after a payload of values signifying the ReadingType is for that batch of values. 1 UsagePoint can have up to 4 ReadingType values.
I should have clarified data modell by having at least 2 UsagePoint and 2 ReadingType in the XML.

I am running SQL Server 2019.
Microsoft SQL Server 2019 (RTM-CU14) (KB5007182) - 15.0.4188.2 (X64)   Nov  3 2021 19:19:51   Copyright (C) 2019 Microsoft Corporation  Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2016 Standard 10.0  (Build 14393: ) (Hypervisor)

Body:
Please try the following solution.

SQL

-- DDL and sample data population, start
DECLARE @tbl TABLE (ID INT IDENTITY PRIMARY KEY, xml_data XML);
INSERT INTO @tbl (xml_data) VALUES
(N'<RequestMessage xmlns="http://iec.ch/TC57/2011/schema/message" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Message.xsd">
    <Header>
        <Verb>create</Verb>
        <Noun>MeterReadings</Noun>
        <Timestamp>2022-01-09T01:00:58+01:00</Timestamp>
        <Source>Y</Source>
        <AsyncReplyFlag>true</AsyncReplyFlag>
        <AckRequired>true</AckRequired>
        <MessageID>xyz_9999</MessageID>
        <CorrelationID></CorrelationID>
        <Property>
            <Name>CONTRACT</Name>
            <Value>xxxx</Value>
        </Property>
        <Property>
            <Name>DIVISION</Name>
            <Value>01</Value>
        </Property>
        <Property>
            <Name>RECEIVER</Name>
            <Value>xxx</Value>
        </Property>
        <Property>
            <Name>SERVICE</Name>
            <Value>xxxx</Value>
        </Property>
    </Header>
    <Payload>
        <MeterReadings xmlns="http://iec.ch/TC57/2011/MeterReadings#" xmlns:MeterReadings="http://iec.ch/TC57/2011/MeterReadings#">
            <MeterReading>
                <IntervalBlocks>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
                        <value>9.246</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
                        <value>10.404</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0.3.72.0"/>
                </IntervalBlocks>
                <IntervalBlocks>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
                        <value>9.246</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
                        <value>10.404</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0.3.72.0"/>
                </IntervalBlocks>
                <Meter>
                    <mRID>xxxx</mRID>
                </Meter>
                <UsagePoint>
                    <mRID>zzzz</mRID>
                </UsagePoint>
            </MeterReading>
            <MeterReading>
                <IntervalBlocks>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
                        <value>9.246</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
                        <value>10.404</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0.3.72.0"/>
                </IntervalBlocks>
                <IntervalBlocks>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T00:00:00.000+01:00</timeStamp>
                        <value>9.246</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <IntervalReadings>
                        <source>x</source>
                        <timeStamp>2022-01-08T01:00:00.000+01:00</timeStamp>
                        <value>10.404</value>
                        <ReadingQualities>
                            <ReadingQualityType ref="3.0.0"/>
                        </ReadingQualities>
                    </IntervalReadings>
                    <ReadingType ref="11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0.3.72.0"/>
                </IntervalBlocks>
                <Meter>
                    <mRID>kkkkk</mRID>
                </Meter>
                <UsagePoint>
                    <mRID>qqqqq</mRID>
                </UsagePoint>
            </MeterReading>
        </MeterReadings>
    </Payload>
</RequestMessage>');
-- DDL and sample data population, end

WITH XMLNAMESPACES(N'http://iec.ch/TC57/2011/schema/message' as hdr,
                   N'http://iec.ch/TC57/2011/MeterReadings#' as mr)
SELECT
    --t.file_name,t.file_created_time received_timestamp,
    --h.value('(hdr:Timestamp)[1]', 'nvarchar(35)') AS created_timestamp,
    --h.value('(hdr:MessageID)[1]', 'nvarchar(50)') AS message_id,
     ir.value('(mr:timeStamp/text())[1]', 'nvarchar(35)') interval_timestamp
    , ir.value('(mr:value/text())[1]', 'nvarchar(35)') interval_value
    , ir.value('(mr:ReadingQualities/mr:ReadingQualityType/@ref)[1]', 'nvarchar(35)') interval_value_code
    , mr.value('(mr:UsagePoint/mr:mRID/text())[1]', 'nvarchar(50)') UsagePoint
    , ir.value('(../mr:ReadingType/@ref)[1]', 'nvarchar(35)') ReadingType
FROM @tbl t
OUTER APPLY t.xml_data.nodes('/hdr:RequestMessage/hdr:Header') AS m(h)
OUTER APPLY t.xml_data.nodes('/hdr:RequestMessage/hdr:Payload/mr:MeterReadings/mr:MeterReading') AS MeterReading(mr)
OUTER APPLY MeterReading.mr.nodes('mr:IntervalBlocks/mr:IntervalReadings') AS IntervalReadings(ir)
--WHERE --t.file_name = 'SESP_32717237.xml' AND
--  ir.value('(mr:timeStamp/text())[1]', 'nvarchar(35)') = '2022-01-08T00:00:00.000+01:00'

Output

+-------------------------------+----------------+---------------------+------------+-------------------------------------+
|      interval_timestamp       | interval_value | interval_value_code | UsagePoint |             ReadingType             |
+-------------------------------+----------------+---------------------+------------+-------------------------------------+
| 2022-01-08T00:00:00.000+01:00 |          9.246 |               3.0.0 | zzzz       | 11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0. |
| 2022-01-08T01:00:00.000+01:00 |         10.404 |               3.0.0 | zzzz       | 11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0. |
| 2022-01-08T00:00:00.000+01:00 |          9.246 |               3.0.0 | zzzz       | 11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0. |
| 2022-01-08T01:00:00.000+01:00 |         10.404 |               3.0.0 | zzzz       | 11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0. |
| 2022-01-08T00:00:00.000+01:00 |          9.246 |               3.0.0 | qqqqq      | 11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0. |
| 2022-01-08T01:00:00.000+01:00 |         10.404 |               3.0.0 | qqqqq      | 11.0.7.1.1.2.12.1.1.0.0.0.0.1010.0. |
| 2022-01-08T00:00:00.000+01:00 |          9.246 |               3.0.0 | qqqqq      | 11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0. |
| 2022-01-08T01:00:00.000+01:00 |         10.404 |               3.0.0 | qqqqq      | 11.0.7.1.1.2.12.1.1.0.0.0.0.1102.0. |
+-------------------------------+----------------+---------------------+------------+-------------------------------------+


来源: stackexchange

问:
How to retain CheckedTextView Checked status after Orientation changes
I've created an application that uses recyclerView and adapter. I want to use onSaveInstanceState to save the state of my checkedtextview upon orientation it was refreshed. How can I retain the state of it? I want to use onSave and onRestore Instances.

```<code>import android.net.wifi.rtt.CivicLocationKeys
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.LinearLayoutManager
import android.os.Parcelable
import android.widget.CheckedTextView
import android.net.wifi.rtt.CivicLocationKeys.STATE

import androidx.annotation.NonNull

class MainActivity : AppCompatActivity() {
    //TODO declare the grocery list as an ArrayList?
    val grocerList: ArrayList<String> = arrayListOf("Cilantro", "Beans", "Cheese",
        "Oil","Tomato", "Salt", "Pepper", "Flour", "Garlic",
        "Lime", "Onion", "Rice", "Cabbage", "Avocado")

    //TODO implement the recyclerview
    //TODO implement the adapter for the recyclerview IN A SEPARATE CLASS

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val rc : RecyclerView = findViewById(R.id.recyclerViewGroceryList)
        rc.layoutManager = LinearLayoutManager(this)

        val rcAdapter = GroceryAdapter(grocerList)
        rc.adapter = rcAdapter
        Log.d("MainActivity","onCreate()") //onCreate()
    }

    //TODO override all the activity callbacks, don't forget to call super!
    //onStart()
    override fun onStart() {
        super.onStart()
        Log.d("MainActivity","onStart()")
    }

    //onResume()
    override fun onResume() {
        super.onResume()
        Log.d("MainActivity","onResume()")
    }

    //onPause()
    override fun onPause(){
        super.onPause()
        Log.d("MainActivity","onPause()")
    }

    //onStop()
    override fun onStop() {
        super.onStop()
        Log.d("MainActivity","onStop()")
    }

    //onDestroy()
    override fun onDestroy() {
        super.onDestroy()
        Log.d("MainActivity","onDestroy()")
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)

    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)

    }
}
</code>```

This is the adapter that I use to take in the string array. I want to save the state of my recyclerView so when it orientates my checkedTextView tick did not remove.

```<code>import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckedTextView
import androidx.recyclerview.widget.RecyclerView
import android.os.PersistableBundle

import android.os.Bundle

class GroceryAdapter(private val gList: ArrayList<String>) : RecyclerView.Adapter<GroceryAdapter.GroceryViewHolder>() {

    // create new views
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GroceryViewHolder {
        // inflates the card_view_design view
        // that is used to hold list item
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.grocery_list, parent, false)

        return GroceryViewHolder(view)
    }

    // binds the list items to a view
    override fun onBindViewHolder(holder: GroceryViewHolder, position: Int) {
        // sets the text to the textview from our itemHolder class
        holder.gItem.text = gList[position]
        holder.gItem.setOnClickListener {
                if (holder.gItem.isChecked) {
                    holder.gItem.isChecked = false
                } else holder.gItem.isChecked = !holder.gItem.isChecked
        }

    }
        /* return the number of the items in the list */
        override fun getItemCount(): Int {
            return gList.size
        }

        // Holds the views for adding it to text
        class GroceryViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
            val gItem: CheckedTextView = itemView.findViewById(R.id.groceryCTV)
        }

}
</code>```

答:
Have a boolean array/list of the form

val checkedState=mutableArrayOf<Boolean>(false,false,false,false)

considering there are 4 checkboxes.

Now use the checked listener to manipulate the checkedState variable.

(if the 2nd and fourth are checked the value would be false,true,false,true)

On reorientation simply use the values in the checkedState to assign the value as checked or not

ContentLicense: CC BY-SA 4.0

Body:
I've created an application that uses recyclerView and adapter. I want to use onSaveInstanceState to save the state of my checkedtextview upon orientation it was refreshed. How can I retain the state of it? I want to use onSave and onRestore Instances.

import android.net.wifi.rtt.CivicLocationKeys
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.LinearLayoutManager
import android.os.Parcelable
import android.widget.CheckedTextView
import android.net.wifi.rtt.CivicLocationKeys.STATE

import androidx.annotation.NonNull

class MainActivity : AppCompatActivity() {
    //TODO declare the grocery list as an ArrayList?
    val grocerList: ArrayList<String> = arrayListOf("Cilantro", "Beans", "Cheese",
        "Oil","Tomato", "Salt", "Pepper", "Flour", "Garlic",
        "Lime", "Onion", "Rice", "Cabbage", "Avocado")

    //TODO implement the recyclerview
    //TODO implement the adapter for the recyclerview IN A SEPARATE CLASS

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val rc : RecyclerView = findViewById(R.id.recyclerViewGroceryList)
        rc.layoutManager = LinearLayoutManager(this)

        val rcAdapter = GroceryAdapter(grocerList)
        rc.adapter = rcAdapter
        Log.d("MainActivity","onCreate()") //onCreate()
    }

    //TODO override all the activity callbacks, don't forget to call super!
    //onStart()
    override fun onStart() {
        super.onStart()
        Log.d("MainActivity","onStart()")
    }

    //onResume()
    override fun onResume() {
        super.onResume()
        Log.d("MainActivity","onResume()")
    }

    //onPause()
    override fun onPause(){
        super.onPause()
        Log.d("MainActivity","onPause()")
    }

    //onStop()
    override fun onStop() {
        super.onStop()
        Log.d("MainActivity","onStop()")
    }

    //onDestroy()
    override fun onDestroy() {
        super.onDestroy()
        Log.d("MainActivity","onDestroy()")
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)

    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)

    }
}

This is the adapter that I use to take in the string array. I want to save the state of my recyclerView so when it orientates my checkedTextView tick did not remove.

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckedTextView
import androidx.recyclerview.widget.RecyclerView
import android.os.PersistableBundle

import android.os.Bundle

class GroceryAdapter(private val gList: ArrayList<String>) : RecyclerView.Adapter<GroceryAdapter.GroceryViewHolder>() {

    // create new views
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GroceryViewHolder {
        // inflates the card_view_design view
        // that is used to hold list item
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.grocery_list, parent, false)

        return GroceryViewHolder(view)
    }

    // binds the list items to a view
    override fun onBindViewHolder(holder: GroceryViewHolder, position: Int) {
        // sets the text to the textview from our itemHolder class
        holder.gItem.text = gList[position]
        holder.gItem.setOnClickListener {
                if (holder.gItem.isChecked) {
                    holder.gItem.isChecked = false
                } else holder.gItem.isChecked = !holder.gItem.isChecked
        }

    }
        /* return the number of the items in the list */
        override fun getItemCount(): Int {
            return gList.size
        }

        // Holds the views for adding it to text
        class GroceryViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
            val gItem: CheckedTextView = itemView.findViewById(R.id.groceryCTV)
        }

}


问:
How can I check two arrays at the same index?
I want to determine how many of the items in these two arrays match, then store that in state as a number.

For example

const [score, setScore] = React.useState(0)

const selections = ["one", "two", "three"]
const allCorrectAnswers = ["four", "two", "three"]
// this should return 2
```
<p>I tried</p>
<pre class="lang-js prettyprint-override"><code>function checkSelectedAnswer(selections, allCorrectAnswers) {
  selections.map(eachChoice =>
    eachChoice === allCorrectAnswers.map(eachAnswer => eachAnswer)
      ? setScore(prevScore => prevScore + 1) : 0
  )
}
</code>```

Please explain why my code isn't working as well if you can.

答:
First of all, I would suggest to use a Set to avoid duplicate values and then an intersection to see what element matches.

```<code>const a = new Set([1,2,3]);
const b = new Set([4,3,2]);
const intersection = new Set([...a].filter(x => b.has(x)));
    // {2,3}

</code>```

Using Set, you will also improve performance since there is no duplicate values.

Here is a small benchmark

Checked test: Javascript Set intersection x 70,358 ops/sec ±2.26% (61 runs sampled)
Checked test: Javascript Array intersection x 40,687 ops/sec ±1.22% (67 runs sampled)
Success! Validation completed.
```

Your code does not work since you comparing the answer (a string) with an array of item which end up to be always false.

Body:
I want to determine how many of the items in these two arrays match, then store that in state as a number.

For example

const [score, setScore] = React.useState(0)

const selections = ["one", "two", "three"]
const allCorrectAnswers = ["four", "two", "three"]
// this should return 2

I tried

function checkSelectedAnswer(selections, allCorrectAnswers) {
  selections.map(eachChoice =>
    eachChoice === allCorrectAnswers.map(eachAnswer => eachAnswer)
      ? setScore(prevScore => prevScore + 1) : 0
  )
}

Please explain why my code isn't working as well if you can.

Body:
First of all, I would suggest to use a Set to avoid duplicate values and then an intersection to see what element matches.

const a = new Set([1,2,3]);
const b = new Set([4,3,2]);
const intersection = new Set([...a].filter(x => b.has(x)));
    // {2,3}

Using Set, you will also improve performance since there is no duplicate values.

Here is a small benchmark

Checked test: Javascript Set intersection x 70,358 ops/sec ±2.26% (61 runs sampled)
Checked test: Javascript Array intersection x 40,687 ops/sec ±1.22% (67 runs sampled)
Success! Validation completed.

Your code does not work since you comparing the answer (a string) with an array of item which end up to be always false.


问:
java.lang.IllegalStateException: getOutputStream() has already been called for this response when calling JasperReport
I am trying iReport/JasperReport in JSF 2
But while i am generating The PDF i got this error.
I searched and found some similar problems and solutions, but nothing worked. Sorry for posting the same question again. But I tried all the possible solutions i found, but none worked for me. Please help

```<code>java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:637)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:214)
at com.sun.faces.context.ExternalContextImpl.getResponseOutputWriter(ExternalContextImpl.java:723)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1009)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:382)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
</code>```

Following are the functions

```<code>public void init() throws IOException, JRException {
    JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(listReportObjects);
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
    servletOutputStream = httpServletResponse.getOutputStream();
    ServletContext servletContext = (ServletContext) externalContext.getContext();
    String reportLocation = servletContext.getRealPath("/web/ireport/monthlyReport.jasper");
    jasperPrint = JasperFillManager.fillReport(reportLocation, new HashMap<String, Object>(), beanCollectionDataSource);
}

public void PDF(ActionEvent actionEvent) throws IOException, JRException {
    System.out.println("*****************PDF*********************");
    init();
    JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
}
</code>```

And the XHTML CODE:
    ;

My POM FILE :

```<code><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.nic</groupId>
<artifactId>RFD</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>RFD</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <netbeans.hint.deploy.server>Tomcat</netbeans.hint.deploy.server>
</properties>

<dependencies>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>2.0.3</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
        <version>2.3.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.13</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.13</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>
    <!-- PrimeFaces -->
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>3.4.1</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces.extensions</groupId>
        <artifactId>all-themes</artifactId>
        <version>1.0.8</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces.extensions</groupId>
        <artifactId>primefaces-extensions</artifactId>
        <version>0.6.1</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.2.6.ga</version>
        <exclusions>
            <exclusion>
                <artifactId>antlr</artifactId>
                <groupId>antlr</groupId>
            </exclusion>
            <exclusion>
                <artifactId>commons-logging</artifactId>
                <groupId>commons-logging</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.3.2.GA</version>
        <exclusions>
            <exclusion>
                <artifactId>commons-logging</artifactId>
                <groupId>commons-logging</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>javax.sql</groupId>
        <artifactId>jdbc-stdext</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.21</version>
    </dependency>
    <dependency>
        <groupId>c3p0</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.servicemix.bundles</groupId>
        <artifactId>org.apache.servicemix.bundles.jettison</artifactId>
        <version>1.0.1_5</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.1.Final</version>
        <type>jar</type>
        <exclusions>
            <exclusion>
                <artifactId>antlr</artifactId>
                <groupId>antlr</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>2.7.7</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.8.3</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.5</version>
    </dependency>
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>4.8.0</version>
        <exclusions>
            <exclusion>
                <artifactId>commons-beanutils</artifactId>
                <groupId>commons-beanutils</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jasperreports-maven-plugin</artifactId>
            <version>1.0-beta-2</version>
            <configuration>
                <sourceDirectory>/web/ireport</sourceDirectory>
                <outputDirectory>/web/ireport</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile-reports</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<repositories>
    <repository>
        <url>http://download.eclipse.org/rt/eclipselink/maven.repo/</url>
        <id>eclipselink</id>
        <layout>default</layout>
        <name>Repository for library EclipseLink (JPA 2.0)</name>
    </repository>
    <repository>
        <url>http://repository.primefaces.org/</url>
        <id>primefaces</id>
        <layout>default</layout>
        <name>Repository for library PrimeFaces 3.2</name>
    </repository>
</repositories>
</code>```

Please Help

I have not used the Function getOutputStream() anywhere else in my project.

答:
I solved moving my commandbutton after h:form, I mean, outside of any containner and it works, so Im asumming theres something while the command its inside a div or a container, and i'have notice beacuse the "ajax" atributte was set to False but still givin me and "Update" for the conntainers.

I hove this help.

ContentLicense: CC BY-SA 3.0

Body:
I am trying iReport/JasperReport in JSF 2
But while i am generating The PDF i got this error.
I searched and found some similar problems and solutions, but nothing worked. Sorry for posting the same question again. But I tried all the possible solutions i found, but none worked for me. Please help

java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:637)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:214)
at com.sun.faces.context.ExternalContextImpl.getResponseOutputWriter(ExternalContextImpl.java:723)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1009)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:382)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

Following are the functions

public void init() throws IOException, JRException {
    JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(listReportObjects);
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
    servletOutputStream = httpServletResponse.getOutputStream();
    ServletContext servletContext = (ServletContext) externalContext.getContext();
    String reportLocation = servletContext.getRealPath("/web/ireport/monthlyReport.jasper");
    jasperPrint = JasperFillManager.fillReport(reportLocation, new HashMap<String, Object>(), beanCollectionDataSource);
}

public void PDF(ActionEvent actionEvent) throws IOException, JRException {
    System.out.println("*****************PDF*********************");
    init();
    JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
}

And the XHTML CODE:
    ;

My POM FILE :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.nic</groupId>
<artifactId>RFD</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>RFD</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <netbeans.hint.deploy.server>Tomcat</netbeans.hint.deploy.server>
</properties>

<dependencies>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>2.0.3</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
        <version>2.3.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.13</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.13</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>

    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>3.4.1</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces.extensions</groupId>
        <artifactId>all-themes</artifactId>
        <version>1.0.8</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces.extensions</groupId>
        <artifactId>primefaces-extensions</artifactId>
        <version>0.6.1</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.2.6.ga</version>
        <exclusions>
            <exclusion>
                <artifactId>antlr</artifactId>
                <groupId>antlr</groupId>
            </exclusion>
            <exclusion>
                <artifactId>commons-logging</artifactId>
                <groupId>commons-logging</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.3.2.GA</version>
        <exclusions>
            <exclusion>
                <artifactId>commons-logging</artifactId>
                <groupId>commons-logging</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>javax.sql</groupId>
        <artifactId>jdbc-stdext</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.21</version>
    </dependency>
    <dependency>
        <groupId>c3p0</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.servicemix.bundles</groupId>
        <artifactId>org.apache.servicemix.bundles.jettison</artifactId>
        <version>1.0.1_5</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.1.Final</version>
        <type>jar</type>
        <exclusions>
            <exclusion>
                <artifactId>antlr</artifactId>
                <groupId>antlr</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>2.7.7</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.8.3</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.5</version>
    </dependency>
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>4.8.0</version>
        <exclusions>
            <exclusion>
                <artifactId>commons-beanutils</artifactId>
                <groupId>commons-beanutils</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jasperreports-maven-plugin</artifactId>
            <version>1.0-beta-2</version>
            <configuration>
                <sourceDirectory>/web/ireport</sourceDirectory>
                <outputDirectory>/web/ireport</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile-reports</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<repositories>
    <repository>
        <url>http://download.eclipse.org/rt/eclipselink/maven.repo/</url>
        <id>eclipselink</id>
        <layout>default</layout>
        <name>Repository for library EclipseLink (JPA 2.0)</name>
    </repository>
    <repository>
        <url>http://repository.primefaces.org/</url>
        <id>primefaces</id>
        <layout>default</layout>
        <name>Repository for library PrimeFaces 3.2</name>
    </repository>
</repositories>

Please Help

I have not used the Function getOutputStream() anywhere else in my project.


问:
How to draw outer labels for polar chart using ng2-charts and chart.js at fixed positions outside the rings?
I am drawing polar chart with chart.js ^2.8.0 and ng2-charts ^2.3.0 in Angular. I have used chartjs-plugin-datalabels to display labels but this does not support lables outside at fixed positions outside the polar chart rings like this plugin for chart.js display labels outside the pie chart.

CODE:

```<code>myColors = [{ backgroundColor: ["rgb(203, 75, 75, 0.5)", "rgb(237, 194, 64, 0.5)", "rgb(175, 216, 248, 0.5)"] }];

ChartPlugins = [pluginDataLabels];

polarAreaChartOptions: ChartOptions = {

    plugins: {
      datalabels: {
         color: '#000000',
         anchor: 'end',
         align: 'end',
         padding: 50,
         display: true,
         font: {
           weight: 'bolder'
         },
         formatter: function(value, ctx) {
          return `${ctx.chart.data.labels[ctx.dataIndex]} - ${value} %`;
       },
      },
    },
    scale: {
      ticks: {
          beginAtZero: true,
          max: 100,
          min: 0,
          stepSize: 10
      },
      gridLines: {
        color: ['gray', 'gray', 'gray', 'gray', 'red','gray', 'gray', 'gray', 'gray', 'gray'],
        lineWidth: [1, 1, 1, 1, 3, 1, 1, 1, 1, 1]
      }
    }
  };

polarAreaChartType: ChartType = "polarArea";
</code>```

Markup

```<code><canvas id="polar-chart" baseChart height="40vh" width="120vw"
                        [data]="polarAreaChartData"
                        [labels]="polarAreaChartLabels"
                        [legend]="polarAreaLegend"
                        [plugins]="ChartPlugins"
                        [options]="polarAreaChartOptions"
                        [chartType]="polarAreaChartType"
                        [colors]="myColors">
                    </canvas>
</code>```

Is there any plugin or addon to display the labels outside the rings in polar chart.js and ng2-charts ?

答:
If you update to chart.js V3 you can use the build in pointLabels and center them:

const options = {
  type: 'polarArea',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      backgroundColor: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"]
    }]
  },
  options: {
    scales: {
      r: {
        pointLabels: {
          display: true,
          centerPointLabels: true
        }
      }
    }
  }
}

const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.0/chart.js"></script>
</body></code>```

Body:
I am drawing polar chart with chart.js ^2.8.0 and ng2-charts ^2.3.0 in Angular. I have used chartjs-plugin-datalabels to display labels but this does not support lables outside at fixed positions outside the polar chart rings like this plugin for chart.js display labels outside the pie chart.

CODE:

myColors = [{ backgroundColor: ["rgb(203, 75, 75, 0.5)", "rgb(237, 194, 64, 0.5)", "rgb(175, 216, 248, 0.5)"] }];

ChartPlugins = [pluginDataLabels];

polarAreaChartOptions: ChartOptions = {

    plugins: {
      datalabels: {
         color: '#000000',
         anchor: 'end',
         align: 'end',
         padding: 50,
         display: true,
         font: {
           weight: 'bolder'
         },
         formatter: function(value, ctx) {
          return `${ctx.chart.data.labels[ctx.dataIndex]} - ${value} %`;
       },
      },
    },
    scale: {
      ticks: {
          beginAtZero: true,
          max: 100,
          min: 0,
          stepSize: 10
      },
      gridLines: {
        color: ['gray', 'gray', 'gray', 'gray', 'red','gray', 'gray', 'gray', 'gray', 'gray'],
        lineWidth: [1, 1, 1, 1, 3, 1, 1, 1, 1, 1]
      }
    }
  };

polarAreaChartType: ChartType = "polarArea";

Markup

<canvas id="polar-chart" baseChart height="40vh" width="120vw"
                        [data]="polarAreaChartData"
                        [labels]="polarAreaChartLabels"
                        [legend]="polarAreaLegend"
                        [plugins]="ChartPlugins"
                        [options]="polarAreaChartOptions"
                        [chartType]="polarAreaChartType"
                        [colors]="myColors">
                    </canvas>

Is there any plugin or addon to display the labels outside the rings in polar chart.js and ng2-charts ?

Body:
If you update to chart.js V3 you can use the build in pointLabels and center them:

const options = {
  type: 'polarArea',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      backgroundColor: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"]
    }]
  },
  options: {
    scales: {
      r: {
        pointLabels: {
          display: true,
          centerPointLabels: true
        }
      }
    }
  }
}

const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);

<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.0/chart.js"></script>
</body>


问:
Error: Unable to resolve module @react-native-community/async-storage IOS
I am trying to run my react native project In my IOS device. I start my server with npx react-native start then I start my app with Xcode. And I get this error:

```<code>error: Error: Unable to resolve module @react-native-community/async-storage from /Users/nicolelopez/dev/LeksPlay/src/Core/onboarding/utils/AuthDeviceStorage.js: @react-native-community/async-storage could not be found within the project or in these directories:
  node_modules
  ../../node_modules

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
> 1 | import AsyncStorage from '@react-native-community/async-storage'
    |                           ^
  2 |
  3 | const SHOULD_SHOW_ONBOARDING_FLOW = 'SHOULD_SHOW_ONBOARDING_FLOW'
</code>```

what I have tried:

I have followed the commands I get In the error message:

```<code> 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
</code>```

i have deleted node_modules and my package.lock.json and have re-installed yarn and done a pod install.

i have tried to restart the computer

i have tried to do a yarn add @react-native-community/async-storage

i am running on node 14 - because I have run in to similar issues with a higher version of node.

i am running Xcode in Rosetta mode - since I am on a Mac M1.

i have tried to change my AsyncStorage import to import AsyncStorage from '@react-native-async-storage/async-storage';

I have also tried to add pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'

but they all result in the same issue - with is the error code I posted. It gets no different no matter what I try. I am really new to react native, this may be a common issue but I can't seem to find anything that helps.

答:
You should use the proper package called @react-native-async-storage/async-storage.

The one you are using is deprecated, check it out on : https://www.npmjs.com/package/@react-native-community/async-storage

Having the two will lead to issues.

If the issue still persist, try to clear all the cached, there is a good tool that will help you clean your react native project: https://github.com/taboulot/rn-game-over

```<code>npx rn-game-over --all
</code>```

If you still have the issue afterward, please update your question with the new detail.

Body:
I am trying to run my react native project In my IOS device. I start my server with npx react-native start then I start my app with Xcode. And I get this error:

error: Error: Unable to resolve module @react-native-community/async-storage from /Users/nicolelopez/dev/LeksPlay/src/Core/onboarding/utils/AuthDeviceStorage.js: @react-native-community/async-storage could not be found within the project or in these directories:
  node_modules
  ../../node_modules

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
> 1 | import AsyncStorage from '@react-native-community/async-storage'
    |                           ^
  2 |
  3 | const SHOULD_SHOW_ONBOARDING_FLOW = 'SHOULD_SHOW_ONBOARDING_FLOW'

what I have tried:

I have followed the commands I get In the error message:

 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*

i have deleted node_modules and my package.lock.json and have re-installed yarn and done a pod install.

i have tried to restart the computer

i have tried to do a yarn add @react-native-community/async-storage

i am running on node 14 - because I have run in to similar issues with a higher version of node.

i am running Xcode in Rosetta mode - since I am on a Mac M1.

i have tried to change my AsyncStorage import to import AsyncStorage from '@react-native-async-storage/async-storage';

I have also tried to add pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'

but they all result in the same issue - with is the error code I posted. It gets no different no matter what I try. I am really new to react native, this may be a common issue but I can't seem to find anything that helps.

Body:
You should use the proper package called @react-native-async-storage/async-storage.

The one you are using is deprecated, check it out on : https://www.npmjs.com/package/@react-native-community/async-storage

Having the two will lead to issues.

If the issue still persist, try to clear all the cached, there is a good tool that will help you clean your react native project: https://github.com/taboulot/rn-game-over

npx rn-game-over --all

If you still have the issue afterward, please update your question with the new detail.


问:
Aggregating data with automatic selection
I am trying to summarize my data. Below you can see my example of data

```<code>data = {'id':['1','2','3','4','5'],
        'name': ['Company1', 'Company1', 'Company3', 'Company4', 'Company5'],
        'employee': [10.2, 3.5, 5, 1, 0],
        'sales': [10, 10, 55, 1, 0],
        'streets':['1a', '3b', 5, 1, 0],
       }
df = pd.DataFrame(data, columns = ['id','name', 'employee','sales','streets'])
</code>```

Now I want to summarize all numerical values from my dataset. I summarize with lines below:

```<code>df = df.groupby(['id','name',]).agg({'employee':sum,
                                    'sales':sum,
                                    }).reset_index()
</code>```

But this is only a small example, usually, I have a dataset with around 10 numerical values to summarize so can anybody help me how to aggregate all of this data in a simple way?

I try with this code below

```<code>df = df.groupby(['id','name',]).agg({df.select_dtypes(include = ['float64', 'int64'])
                                    }).reset_index()
</code>```

but I received error unhashable type: 'DataFrame'

So can anybody help me how to solve this problem?

答:
df.select_dtypes returns a subset of the df's columns based on the column dtypes, so you can groupby the relevant columns of df (in this example, "id" and "name" columns) and apply a function to this subset:

```<code>out = df.select_dtypes(include = ['float64', 'int64']).groupby([df['id'],df['name']]).sum()
</code>```

Output:

```<code>             employee  sales
id name
1  Company1      10.2     10
2  Company1       3.5     10
3  Company3       5.0     55
4  Company4       1.0      1
5  Company5       0.0      0
</code>```

Body:
I am trying to summarize my data. Below you can see my example of data

data = {'id':['1','2','3','4','5'],
        'name': ['Company1', 'Company1', 'Company3', 'Company4', 'Company5'],
        'employee': [10.2, 3.5, 5, 1, 0],
        'sales': [10, 10, 55, 1, 0],
        'streets':['1a', '3b', 5, 1, 0],
       }
df = pd.DataFrame(data, columns = ['id','name', 'employee','sales','streets'])

Now I want to summarize all numerical values from my dataset. I summarize with lines below:

df = df.groupby(['id','name',]).agg({'employee':sum,
                                    'sales':sum,
                                    }).reset_index()

But this is only a small example, usually, I have a dataset with around 10 numerical values to summarize so can anybody help me how to aggregate all of this data in a simple way?

I try with this code below

df = df.groupby(['id','name',]).agg({df.select_dtypes(include = ['float64', 'int64'])
                                    }).reset_index()

but I received error unhashable type: 'DataFrame'

So can anybody help me how to solve this problem?

Body:
df.select_dtypes returns a subset of the df's columns based on the column dtypes, so you can groupby the relevant columns of df (in this example, "id" and "name" columns) and apply a function to this subset:

out = df.select_dtypes(include = ['float64', 'int64']).groupby([df['id'],df['name']]).sum()

Output:

             employee  sales
id name
1  Company1      10.2     10
2  Company1       3.5     10
3  Company3       5.0     55
4  Company4       1.0      1
5  Company5       0.0      0


问:
Reactive forms - Warning when using the disabled attribute
I want to disable a select box in one of my forms while there is nothing to select in it until the data for this select box was returned from the server. I need to do this because the data shown in the select box depends on what was selected in another select box. Whenever something is selected in that other select box, I need to load the corresponding options from the server. To disable the select box while there is no data available for it, I am using the disabled attribute like this:

```<code><mat-select formControlName="formId" [disabled]="formNames.length === 0">
  <mat-option
    *ngFor="let formName of formNames"
    [value]="formName.id"
  >
    {{ formName.formName }}
  </mat-option>
</mat-select>
</code>```

I then subscribed to the valueChanges event of the other select box like this:

```<code>this.createForm.controls.formTypeId.valueChanges.subscribe((value: number) => {
  this.formsService.getFormNames(value).subscribe((formNames) => {
    this.formNames = formNames;
  });
});
</code>```

While this seems to work perfectly fine, I keep getting the following warning in the browser console:

```<code>  It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true
  when you set up this control in your component class, the disabled attribute will actually be set in the DOM for
  you. We recommend using this approach to avoid 'changed after checked' errors.

  Example:
  form = new FormGroup({
    first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
    last: new FormControl('Drew', Validators.required)
  });
</code>```

I do not understand what this warning means and the suggested solution also doesn't really help me because I do not simply want to set the disabled property to true. What am I supposed to actually do to achieve the desired behavior of disabling the select box while there are no form names available? Or is my approach fine and I should just ignore this warning?

答:
The warning you are getting is because there is another way to do it in Angular. I assume that in your .ts file you have something like this:</p>
```<code>ngOnInit(): void {
this.createForm = this.fb.group({
formName: [{value: this.formName, disabled: this.formNames.length === 0}]
}
</code>```

Body:
I want to disable a select box in one of my forms while there is nothing to select in it until the data for this select box was returned from the server. I need to do this because the data shown in the select box depends on what was selected in another select box. Whenever something is selected in that other select box, I need to load the corresponding options from the server. To disable the select box while there is no data available for it, I am using the disabled attribute like this:

<mat-select formControlName="formId" [disabled]="formNames.length === 0">
  <mat-option
    *ngFor="let formName of formNames"
    [value]="formName.id"
  >
    {{ formName.formName }}
  </mat-option>
</mat-select>

I then subscribed to the valueChanges event of the other select box like this:

this.createForm.controls.formTypeId.valueChanges.subscribe((value: number) => {
  this.formsService.getFormNames(value).subscribe((formNames) => {
    this.formNames = formNames;
  });
});

While this seems to work perfectly fine, I keep getting the following warning in the browser console:

  It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true
  when you set up this control in your component class, the disabled attribute will actually be set in the DOM for
  you. We recommend using this approach to avoid 'changed after checked' errors.

  Example:
  form = new FormGroup({
    first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
    last: new FormControl('Drew', Validators.required)
  });

I do not understand what this warning means and the suggested solution also doesn't really help me because I do not simply want to set the disabled property to true. What am I supposed to actually do to achieve the desired behavior of disabling the select box while there are no form names available? Or is my approach fine and I should just ignore this warning?

Body:
The warning you are getting is because there is another way to do it in Angular. I assume that in your .ts file you have something like this:

ngOnInit(): void {
this.createForm = this.fb.group({
formName: [{value: this.formName, disabled: this.formNames.length === 0}]
}


答:
From the usage documentation, it looks like you're importing Async Storage incorrectly. You should be importing from @react-native-async-storage and not from @react-native-community. Further, you seem to be confusing the two packages. Ensure you've completed the relevant installation steps as well.

To install the correct package:

```<code>yarn add @react-native-async-storage/async-storage
</code>```

And to import Async Storage:

```<code>import AsyncStorage from '@react-native-async-storage/async-storage';
</code>```

Title: Error: Unable to resolve module @react-native-community/async-storage IOS

Body:
From the usage documentation, it looks like you're importing Async Storage incorrectly. You should be importing from @react-native-async-storage and not from @react-native-community. Further, you seem to be confusing the two packages. Ensure you've completed the relevant installation steps as well.

To install the correct package:

yarn add @react-native-async-storage/async-storage

And to import Async Storage:

import AsyncStorage from '@react-native-async-storage/async-storage';


问:
Inherit autocomplete/suggestion proptypes in wrapper component
I am creating my own custom "wrapper" around a chakraui component, so I can add my own props, methods and whatever I might need later on.

However, one downside of doing this is that I don't get suggestions for the imported chakraui-Button proptypes in Visual Studio Code, but only the new proptype "testPropColor". The other properties are still working, but is there any way of passing them further down so I can see them as suggestions as well?

What I have is this:
custom-component/button.js

import { Button as ChakraButton } from '@chakra-ui/react'

export default function Button(properties) {
  const { testPropColor, children, ...props } = properties

  return (
    <ChakraButton color="testPropColor" {...props}>
      {children}
    </ChakraButton>
  )
}```
</div>
</div>
</p>
<p>And how I am using this in a view:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>import Button from 'custom-component/Button'

export default function ViewComponent() {
  return (
    <Button
      bg="red"
      testPropColor="blue">Test</Button>
  )
}</code>```

答:
Javascript doesn't come with type support. So no type-intellisense in VSCode.

I highly highly highly suggest adding TypeScript to your JS React project.

e.g:

```<code>interface ButtonProps extends ChakraButton {
    // you need to get the `ChakraButton` properties type, from '@chakra-ui/react'.
    // You should be able to import it.
    testPropColor: string;
    bg: string;

}
export function Button(properties: ButtonProps) {

}
</code>```

Just a quick article I found for example here.

If for some reason you don't add TS(?!. you really should) -> then there's prop-types, but I don't suggest using it, compared to TS.

import PropTypes from 'prop-types';
```

Good luck

Body:
I am creating my own custom "wrapper" around a chakraui component, so I can add my own props, methods and whatever I might need later on.

However, one downside of doing this is that I don't get suggestions for the imported chakraui-Button proptypes in Visual Studio Code, but only the new proptype "testPropColor". The other properties are still working, but is there any way of passing them further down so I can see them as suggestions as well?

What I have is this:
custom-component/button.js

import { Button as ChakraButton } from '@chakra-ui/react'

export default function Button(properties) {
  const { testPropColor, children, ...props } = properties

  return (
    <ChakraButton color="testPropColor" {...props}>
      {children}
    </ChakraButton>
  )
}

And how I am using this in a view:

import Button from 'custom-component/Button'

export default function ViewComponent() {
  return (
    <Button
      bg="red"
      testPropColor="blue">Test</Button>
  )
}

Body:
Javascript doesn't come with type support. So no type-intellisense in VSCode.

I highly highly highly suggest adding TypeScript to your JS React project.

e.g:

interface ButtonProps extends ChakraButton {
    // you need to get the `ChakraButton` properties type, from '@chakra-ui/react'.
    // You should be able to import it.
    testPropColor: string;
    bg: string;

}
export function Button(properties: ButtonProps) {

}

Just a quick article I found for example here.

If for some reason you don't add TS(?!. you really should) -> then there's prop-types, but I don't suggest using it, compared to TS.

import PropTypes from 'prop-types';

Good luck


问:
Goldengate get an unique constraint error during insert into a simple table
I have a two node gg1 and gg2 setup of goldengate. Seem to work. However when I insert a row into my table T1

```<code>connect sender/oracle
create table t1 (f1 char, f2 char);
alter table t1 add constraint t1_i1 primary key (f1);
</code>```

I get an error

2022-01-30T19:16:05.705-0500  WARNING OGG-01154  Oracle GoldenGate Delivery for Oracle, d_rep.prm:  SQL error 1 mapping SENDER.T1 to SENDER.T1 OCI Error ORA-00001: unique constraint (SENDER.T1_I1) violated (status = 1), SQL <INSERT INTO "SENDER"."T1" ("F1","F2") VALUES (:a0,:a1)>.

enter image description here

enter image description here

enter image description here

here are prm files for gg1

```<code># cat s_ext.prm
extract s_ext
userid ggs_owner, password Newpassword_2
tranlogoptions excludeuser ggs_owner
exttrail /u01/gg/dirdat/lt
ddl include all
getupdatebefores
sequence sender.*;
table sender.*;

# cat s_pmp.prm
extract s_pmp
userid ggs_owner, password Newpassword_2
rmthost 10.10.0.216, mgrport 7809
rmttrail /u01/gg/dirdat/rt
passthru
sequence sender.*;
table sender.*;

# cat d_rep.prm
replicat d_rep
userid ggs_owner, password Newpassword_2
assumetargetdefs
discardfile /u01/gg/dirrpt/drep1.dsc, append
reperror (default, exception)
map sender.*, target sender.*;
MACRO #exception_handler
 BEGIN
 , TARGET GGS_OWNER.GGS_EXCEPTIONS
 , COLMAP ( rep_name = @GETENV('GGENVIRONMENT', 'GROUPNAME')
 , TABLE_NAME = @GETENV ('GGHEADER', 'TABLENAME')
 , ERRNO = @GETENV ('LASTERR', 'DBERRNUM')
 , DBERRMSG = @GETENV ('LASTERR', 'DBERRMSG')
 , OPTYPE = @GETENV ('LASTERR', 'OPTYPE')
 , ERRTYPE = @GETENV ('LASTERR', 'ERRTYPE')
 , LOGRBA = @GETENV ('GGHEADER', 'LOGRBA')
 , LOGPOSITION = @GETENV ('GGHEADER', 'LOGPOSITION')
 , COMMITTIMESTAMP = @GETENV ('GGHEADER', 'COMMITTIMESTAMP')
 , GGS_FILENAME = @GETENV('GGFILEHEADER', 'FILENAME')
 , CDRFAIL = @GETENV('DELTASTATS','CDR_RESOLUTIONS_FAILED')
 , CDRSUC = @GETENV('DELTASTATS','CDR_RESOLUTIONS_SUCCEEDED')
 , CDRDETECT = @GETENV('DELTASTATS','CDR_CONFLICTS'))
 , INSERTALLRECORDS
 , EXCEPTIONSONLY;
 END;
MAP sender.* #exception_handler();
</code>```

site gg2 is similar.

All row that i insert get insert with no abends but the warning confuses me.

答:
According to the message you are getting a Key violation. Does the target table already have a record with the same key?  Your exceptions mapping is handling it and you should see records in the ggs.ggs_exceptions table.  Also, do a STATS on Replicat.

STATS REPLICAT repname TOTAL

and look for discards or collisions.

Body:
I have a two node gg1 and gg2 setup of goldengate. Seem to work. However when I insert a row into my table T1

connect sender/oracle
create table t1 (f1 char, f2 char);
alter table t1 add constraint t1_i1 primary key (f1);

I get an error

2022-01-30T19:16:05.705-0500  WARNING OGG-01154  Oracle GoldenGate Delivery for Oracle, d_rep.prm:  SQL error 1 mapping SENDER.T1 to SENDER.T1 OCI Error ORA-00001: unique constraint (SENDER.T1_I1) violated (status = 1), SQL <INSERT INTO "SENDER"."T1" ("F1","F2") VALUES (:a0,:a1)>.

enter image description here

enter image description here

enter image description here

here are prm files for gg1

# cat s_ext.prm
extract s_ext
userid ggs_owner, password Newpassword_2
tranlogoptions excludeuser ggs_owner
exttrail /u01/gg/dirdat/lt
ddl include all
getupdatebefores
sequence sender.*;
table sender.*;

# cat s_pmp.prm
extract s_pmp
userid ggs_owner, password Newpassword_2
rmthost 10.10.0.216, mgrport 7809
rmttrail /u01/gg/dirdat/rt
passthru
sequence sender.*;
table sender.*;

# cat d_rep.prm
replicat d_rep
userid ggs_owner, password Newpassword_2
assumetargetdefs
discardfile /u01/gg/dirrpt/drep1.dsc, append
reperror (default, exception)
map sender.*, target sender.*;
MACRO #exception_handler
 BEGIN
 , TARGET GGS_OWNER.GGS_EXCEPTIONS
 , COLMAP ( rep_name = @GETENV('GGENVIRONMENT', 'GROUPNAME')
 , TABLE_NAME = @GETENV ('GGHEADER', 'TABLENAME')
 , ERRNO = @GETENV ('LASTERR', 'DBERRNUM')
 , DBERRMSG = @GETENV ('LASTERR', 'DBERRMSG')
 , OPTYPE = @GETENV ('LASTERR', 'OPTYPE')
 , ERRTYPE = @GETENV ('LASTERR', 'ERRTYPE')
 , LOGRBA = @GETENV ('GGHEADER', 'LOGRBA')
 , LOGPOSITION = @GETENV ('GGHEADER', 'LOGPOSITION')
 , COMMITTIMESTAMP = @GETENV ('GGHEADER', 'COMMITTIMESTAMP')
 , GGS_FILENAME = @GETENV('GGFILEHEADER', 'FILENAME')
 , CDRFAIL = @GETENV('DELTASTATS','CDR_RESOLUTIONS_FAILED')
 , CDRSUC = @GETENV('DELTASTATS','CDR_RESOLUTIONS_SUCCEEDED')
 , CDRDETECT = @GETENV('DELTASTATS','CDR_CONFLICTS'))
 , INSERTALLRECORDS
 , EXCEPTIONSONLY;
 END;
MAP sender.* #exception_handler();

site gg2 is similar.

All row that i insert get insert with no abends but the warning confuses me.


问:
X-Content-Type-Options causes image to display as gibberish text [nginx]
I have setup to reverse proxy port 8086. Port 8086 is running a javascript that display random a image in webp format. If I try to visit the domain it displays the image as gibberish text. It works fine if I visit the ip address but not the domain.

I have out that more_set_headers "X-Content-Type-Options : nosniff" is causing the image to display as gibberish text. Is there a way to remove that setting for a specific site only? cause X-Content-Type-Options : nosniff is set to apply to all sites.

nginx conf

```<code>server {

    server_name sub.example.com www.sub.example.com;

    access_log /var/log/nginx/sub.example.com.access.log ;
    error_log /var/log/nginx/sub.example.com.error.log;

    add_header X-Proxy-Cache $upstream_cache_status;
    location / {
        proxy_pass http://xxx.xxx.xxx.xxx:8086/img;
        proxy_redirect      off;
        proxy_set_header X-Content-Type-Options "";
    }
}
</code>```

How to remove X-Content-Type-Options : nosniff from specific site?

答: This can be done in a "functional" way: always add the header with a value from map{}. Map $host $nosniff {myhost ''; default nosniff;}</p>

Body:
I have setup to reverse proxy port 8086. Port 8086 is running a javascript that display random a image in webp format. If I try to visit the domain it displays the image as gibberish text. It works fine if I visit the ip address but not the domain.

I have out that more_set_headers "X-Content-Type-Options : nosniff" is causing the image to display as gibberish text. Is there a way to remove that setting for a specific site only? cause X-Content-Type-Options : nosniff is set to apply to all sites.

nginx conf

server {

    server_name sub.example.com www.sub.example.com;

    access_log /var/log/nginx/sub.example.com.access.log ;
    error_log /var/log/nginx/sub.example.com.error.log;

    add_header X-Proxy-Cache $upstream_cache_status;
    location / {
        proxy_pass http://xxx.xxx.xxx.xxx:8086/img;
        proxy_redirect      off;
        proxy_set_header X-Content-Type-Options "";
    }
}

How to remove X-Content-Type-Options : nosniff from specific site?


问:
Cannot access 'db' before initialization - Firebase
I'm getting a problem where my React app is crashing due to not being able to access db.

I am initialising the firebase app in src/index.js

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { BrowserRouter } from "react-router-dom";
import { initializeApp } from "firebase/app";
import { firebaseConfig } from "./firebase";
import { getFirestore } from "firebase/firestore";

initializeApp(firebaseConfig);
export const db = getFirestore();

ReactDOM.render(
  <React.StrictMode>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </React.StrictMode>,
  document.getElementById("root")
);```
</div>
</div>
</p>
<p>Then in a different file thats in src/dashboard/signup/SignupForm.js I try to update db to add a registered user when user submits a validated form ( the only way I have been able to figure out how to list all registered users is through db since there is no direct feature that lets you do that ).</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>import { db } from "../../..";

// const db = getFirestore()

const unsub = onSnapshot(doc(db, "users", "userCount"), (doc) => {
  console.log("Current data: ", doc.data());
});</code>```

Here I'm trying to sub to live changes so that if a few users register at the same time the value updates correctly.

However in both ways, if I set db in src/index.js or in the form folder my app crashes.

答:
Ok,

The problem was that I didn't move the db initialisation into the return of component

Body:
I'm getting a problem where my React app is crashing due to not being able to access db.

I am initialising the firebase app in src/index.js

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { BrowserRouter } from "react-router-dom";
import { initializeApp } from "firebase/app";
import { firebaseConfig } from "./firebase";
import { getFirestore } from "firebase/firestore";

initializeApp(firebaseConfig);
export const db = getFirestore();

ReactDOM.render(
  <React.StrictMode>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </React.StrictMode>,
  document.getElementById("root")
);

Then in a different file thats in src/dashboard/signup/SignupForm.js I try to update db to add a registered user when user submits a validated form ( the only way I have been able to figure out how to list all registered users is through db since there is no direct feature that lets you do that ).

import { db } from "../../..";

// const db = getFirestore()

const unsub = onSnapshot(doc(db, "users", "userCount"), (doc) => {
  console.log("Current data: ", doc.data());
});

Here I'm trying to sub to live changes so that if a few users register at the same time the value updates correctly.

However in both ways, if I set db in src/index.js or in the form folder my app crashes.