[CLOSED] Using JsonReader and everything is empty

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Using JsonReader and everything is empty

    Hi guys,
    hit somethign new to me again and not sure I understand. We have a GridPanel which we want to save the data to Oracle. So from what I understand we are using JSON reader to read the data in the Grid. I did a watch out the JSON reader and all my value are 0 or "" even though I entered data in the fields.

    I will post the code relative to this problem.

    My Store
            <asp:ObjectDataSource ID="dsWorkInv" runat="server" SelectMethod="FindByID"
                TypeName="UOttawa.BusinessObjects.WorkHoursCollection" 
                OldValuesParameterFormatString="original_{0}" >
                <SelectParameters>
                    <asp:QueryStringParameter DefaultValue="0" Name="OfferID" QueryStringField="id" Type="String" />
                </SelectParameters>
            </asp:ObjectDataSource>
            
            <ext:Store ID="stoWorkInv" runat="server" DataSourceID="dsWorkInv" OnBeforeStoreChanged="stoWorkHours_OnBeforeStoreChanged">
                <Reader>
                    <ext:JsonReader IDProperty="OfferID,SeqNr">
                        <Fields>
                            <ext:RecordField Name="OfferID" Type="Int"/>
                            <ext:RecordField Name="SeqNr" Type="Int"/>
                            <ext:RecordField Name="WorkCatgCd" Type="String"/>
                            <ext:RecordField Name="NrOfHours" Type="Float"/>
                            <ext:RecordField Name="WorkComment" Type="String"/>
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
    There's also a bit of code on the save button.
                   <ext:Button ID="btnSave" runat="server" Text="Save" Icon="Disk" OnClientClick="#{btnSave}.disable();return true;">
                        <DirectEvents>
                            <Click OnEvent="btnSave_Click" >
                                <ExtraParams>
                                    <ext:Parameter Name="WorkHours" Value="Ext.encode(#{grdWorkInv}.getRowsValues(false))" Mode="Raw" />
                                </ExtraParams>
                            </Click>
                        </DirectEvents>                
                    </ext:Button>
    My Class
    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    
    Public Class WorkHours
    
        Private _lngOfferId As Long = 0
        Private _lngSeqNr As Long = 0
    
        Private _strWorkCatgCd As String = ""
        Private _lngNrOfHours As Decimal = 0
        Private _strWorkComment As String = ""
    
    
        Public Sub New(ByVal OfferId As Long, ByVal SeqNr As Long, ByVal WorkCatgCd As String, ByVal NrOfHours As Decimal, ByVal WorkComment As String)
            _lngOfferId = OfferId
            _lngSeqNr = SeqNr
            _strWorkCatgCd = WorkCatgCd
            _lngNrOfHours = NrOfHours
            _strWorkComment = WorkComment
    
        End Sub
    
        Public Sub New()
        End Sub
    
        Public Function Validate(ByVal lang As Language, ByVal action As DatabaseAction) As StatusMessage
            'Perform data validation and return a proper code from the StatusMessage.vb list.
            'If WorkID = 0 Then
            ' Return New StatusMessage(ErrorCodes.WorkInventoryNil)
            If WorkCatgCd = "" Then
                Return New StatusMessage(ErrorCodes.WorkCategoryCodeNil)
            ElseIf NrOfHours = Nothing Then
                Return New StatusMessage(ErrorCodes.NrOfHoursNil)
            Else
                Return New StatusMessage(ErrorCodes.None)
            End If
        End Function
    
        Public Property OfferId() As Long
            Get
                Return _lngOfferId
            End Get
            Set(ByVal value As Long)
                _lngOfferId = value
            End Set
        End Property
    
        Public Property SeqNr() As Long
            Get
                Return _lngSeqNr
            End Get
            Set(ByVal value As Long)
                _lngSeqNr = value
            End Set
        End Property
    
        Public Property WorkCatgCd() As String
            Get
                Return _strWorkCatgCd
            End Get
            Set(ByVal value As String)
                _strWorkCatgCd = value
            End Set
        End Property
    
        Public Property NrOfHours() As Decimal
            Get
                Return _lngNrOfHours
            End Get
            Set(ByVal value As Decimal)
                _lngNrOfHours = value
            End Set
        End Property
    
        Public Property WorkComment() As String
            Get
                Return _strWorkComment
            End Get
            Set(ByVal value As String)
                _strWorkComment = value
            End Set
        End Property
    
    End Class
    And the function I call to read the data and put them in my class
        Private Function PopulateWorkHours() As List(Of WorkHours)
            'Get the course schedule table
            Dim jsonData As String = Session("_StudentOfferSaveAjaxEventArgs")
            'Dim xmlCourseSchedule As XmlNode = JSON.DeserializeXmlNode("{records:{record:" + jsonData + "}}")
            Dim items As List(Of WorkHours) = New List(Of WorkHours)()
            If jsonData Is Nothing Then
                Return items
            End If
            Dim settings As JsonSerializerSettings = New JsonSerializerSettings()
            settings.MissingMemberHandling = MissingMemberHandling.Ignore
            items = JsonConvert.DeserializeObject(jsonData, GetType(List(Of WorkHours)), settings)
            Return items
        End Function
    And this is what is see in my watch
    "[{"OfferID":0,"SeqNr":0,"WorkCatgCd":"","NrOfHours" :0,"WorkComment":"","OfferID,SeqNr":-2}]"

    I hope this is enough to help you out. I probably couldn't pull out the code to get a functional grid working since I wouldn't even know where to start ;)

    Thanks so much,
    Bert
    Last edited by Daniil; Jul 18, 2011 at 5:37 PM. Reason: [CLOSED]
  2. #2
    Hi,

    At the first of all - did you carefully investigate this example?
    https://examples1.ext.net/#/GridPane...ectDataSource/

    IDProperty doesn't support multiple fields. But this issue should not cause the problem you described.
    IDProperty="OfferID,SeqNr"
  3. #3
    One more thing and it can cause the issue.

    A RecordFiled's .Name and a property's name should be identical.
    <ext:RecordField Name="OfferID" Type="Int"/>
    
    Public Property OfferId() As Long
    There are different cases of "Id" and "ID".
  4. #4
    Hi Daniil,
    I looked at the example you sent and I also compared to something that was done similarly in 0.8.2 which works and is production right now. I think the structure seems right (I could be wrong though, no one's perfect :) ).

    I also changed my OfferId to OfferID so everything matches in matters of cases and I also changed the IDProperty to only use SeqNr. The reason we had 2 keys is that one is a foreign key to another table but I can always get that one from somewhere else I guess (since I have it in the parent form).

    I reran the application with the suggested mods and I still have zeroes and empties everywhere but I notice that the number at the end of the ine is gone, not sure what it was to begin with.

    Old Value
    "[{"OfferID":0,"SeqNr":0,"WorkCatgCd":"","NrOfHours" :0,"WorkComment":"","OfferID,SeqNr":-2}]"
    New Value
    "[{"SeqNr":0,"OfferID":0,"WorkCatgCd":"","NrOfHours":0,"WorkComment":""}]"
    Looking at it now makes me realize that it was probably the IDProperty.. is it gone? Is that my problem?

    Ive tried it again without changing much and this time I got this.
    "[{"SeqNr":-2,"WorkCatgCd":"","WorkComment":""}]"
    Why did some of my field disappear?

    I suspect these is the part where I loose information but I have no idea what this line does. Where can I find information on this? Sencha website?
    <ExtraParams>                 
    <ext:Parameter Name="WorkHours" Value="Ext.encode(#{grdWorkInv}.getRowsValues(false))" Mode="Raw" />             
    </ExtraParams>

    Thanks,
    Bert
    Last edited by Daniil; Jul 15, 2011 at 9:59 PM. Reason: Please use [CODE] tags
  5. #5
    Quote Originally Posted by Bert76 View Post
    Why did some of my field disappear?
    It's hard to say. Please post a simplified test sample to copy/paste and run.

    Quote Originally Posted by Bert76 View Post
    I suspect these is the part where I loose information but I have no idea what this line does. Where can I find information on this? Sencha website?
    <ExtraParams>                 
    <ext:Parameter Name="WorkHours" Value="Ext.encode(#{grdWorkInv}.getRowsValues(false))" Mode="Raw" />             
    </ExtraParams>
    Well, it's rather a question for another thread.
    Last edited by Daniil; Jul 15, 2011 at 10:11 PM.
  6. #6
    HI Daniil,
    Not sure how I could achieve that since the point of this codeis to save that data in a database, I will try to put something together. I'm just curious as to why when I do my ext.encode I get empty or null values.

    Bert
  7. #7
    Quote Originally Posted by Bert76 View Post
    Not sure how I could achieve that since the point of this codeis to save that data in a database, I will try to put something together. I'm just curious as to why when I do my ext.encode I get empty or null values.
    Please clarify are you telling that the data is in the grid, but the problem appears when you retrieve them using Ext.encode()?
  8. #8
    What I am trying to achieve is to save what was entered in the datagrid into a database, my problem occurs when I hit my save button, when I look at what the encode brings back it's all empty or zeros depending on the ext:RecordField Type.

    I've been looking at many examples since this morning and I still can't seem to find where my error is. The more I look the less I understand the results.

    This is what my JSONReader got on my last test.

    [{"SeqNr":-3,"WorkCatgCd":"","WorkComment":""},
    {"SeqNr":-2,"WorkCatgCd":"","WorkComment":""},
    {"SeqNr":0,"OfferID":0,"WorkCatgCd":"","NrOfHours" :0,"WorkComment":""}]

    How come on each line I don't have all my fields and that the SeqNr have a "-" in front?

    From what I understand, this is what happens:

    1. I click the save button
    2. ExtraParams is populated and is stored in WorkHours
                    <ext:Button ID="btnSave" runat="server" Text="Save" Icon="Disk" OnClientClick="#{btnSave}.disable();return true;">
                        <DirectEvents>
                            <Click OnEvent="btnSave_Click" >
                                <ExtraParams>
                                    <ext:Parameter Name="WorkHours" Value="Ext.encode(#{grdWorkInv}.getRowsValues(false))" Mode="Raw" />
                                </ExtraParams>
                            </Click>
                        </DirectEvents>                
                    </ext:Button>
    3. then I store it in a session value in the codeBehind on the btnSave_click event.
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As DirectEventArgs) Handles btnSave.Click
    
            If Not FollowMe.IsAllowed(SecurityRole.ProfUpdate) Then
                Ext.Net.X.Msg.Alert("Access Denied", New StatusMessage(MsgBoxCodes.NoUpdateSecurityRole).Message).Show()
                btnSave.Enabled = False
                Exit Sub
            End If
    
            Session("_StudentOfferSaveAjaxEventArgs") = e.ExtraParams("WorkHours")
    
            If (Request.QueryString("id") = "" And Me.txtOfferID.Text.Equals("")) Then
                '********** INSERT **********
                DisplayWarningIfNecessary() 'Show a warning if the student is over the maximum hours among all offers.
                Dim item As StudentOffer = PopulateItem()
                DoInsert(item)
            Else
                '********** UPDATE **********
                Dim _lngOfferID As Long = 0
                If Common.IsNumeric(txtOfferID.Text) Then
                    _lngOfferID = Convert.ToInt64(txtOfferID.Text)
                End If
    
                Dim _strOriginalStatus As String = GetOriginalOfferStatus(_lngOfferID)
                Dim _blnPromptUserQuestion As Boolean = IsEmailGoingOut(_lngOfferID, _strOriginalStatus)
                If _blnPromptUserQuestion = True Then
                    'When changing the status, we must send updates to CUPE email.
                    lblAskEmail.Text = New StatusMessage(MsgBoxCodes.SendEmailOfferAptpuo).Message
                    txtAskEmailComments.Text = txtEmailComments.Text
                    winAskEmailComment.Show()
    
                    DisplayWarningIfNecessary() 'Show a warning if the student is over the maximum hours among all offers.
                Else
                    'If this offer is in Draft, or new internal comments have been added it should hit here! (and not ask to send an email)
                    Dim item As StudentOffer = PopulateItem()
                    DoUpdate(item)
                End If
            End If
    
        End Sub
    4. After that I deserialize and read the data but I didn't get to that part yet since... My WorkHours ExtraParams are always empty. Is there a way to see if there's an error?

    So basically right now all i'm trying to do is read the data from the grid which is without success yet.
  9. #9
    3. then I store it in a session value in the codeBehind on the btnSave_click event.
    Why do you store the data in Session?

    4. After that I deserialize and read the data but I didn't get to that part yet since...
    Where do you deserialize? Did I miss it on your code?

    Please look at the request (use, for example, Fiddler or FireBug) when you click on the Save button.

    What do you see in "extraParams"? Is there correct data?
  10. #10
    I deserialize later on, I don't get there because the data in ExtraParams is not good. I posted a few examples. And I did another test where I add more than one row in the GridPanel and I suspect something is very wrong. Here's an example:

    [{"SeqNr":-4,"WorkCatgCd":"","WorkComment":""},
    {"SeqNr":-3,"WorkCatgCd":"","WorkComment":""},
    {"SeqNr":-2,"WorkCatgCd":"","WorkComment":""},
    {"SeqNr":0,"OfferID":0,"WorkCatgCd":"","NrOfHours":0,"WorkComment":""}]
    If I check the Result of the e.ExtraParams this is what I see. Not sure what the syntax is for encode but I can see that on hte 3 first line I have field missing The OfferID and NrOfHours are missing.

    Bert
    Last edited by Daniil; Jul 18, 2011 at 5:22 PM. Reason: Please use [CODE] tags
Page 1 of 2 12 LastLast

Similar Threads

  1. JSONReader problem
    By atze187 in forum 1.x Help
    Replies: 9
    Last Post: Nov 11, 2011, 1:57 PM
  2. HttpProxy and JsonReader
    By santosbj in forum 1.x Help
    Replies: 1
    Last Post: Jun 18, 2010, 5:29 AM
  3. Replies: 0
    Last Post: Jun 26, 2009, 11:32 AM
  4. Problem using ext:JsonReader
    By egodoy in forum 1.x Help
    Replies: 1
    Last Post: Dec 03, 2008, 3:46 PM
  5. JsonReader Problem
    By Casbah in forum 1.x Help
    Replies: 0
    Last Post: Oct 17, 2008, 7:57 AM

Posting Permissions