How do I get an attribute using the 'amazon-ecs' gem? - ruby-on-rails
I am using Amazon Product Advertising API (amazon-ecs) gem, but I am using the item_lookup method instead of item_search, which is the only one documented.
I am looking to return the item TradeInValue but I am confused as to how to do that. It is clearly being returned, but I am not sure how to parse it.
This is the call:
Amazon::Ecs.item_lookup('9780521153348', :response_group => 'ItemAttributes', :id_type => 'ISBN', :search_index => 'Books')
And this is the return, which I am not sure what to do with. The methods in amazon-ecs don't seem to work for item_lookup and XPath isn't working either:
#<Amazon::Ecs::Response:0x007ff3325250d0 #doc=#<Nokogiri::XML::Document:0x3ff9992927a0 name="document" children=[#<Nokogiri::XML::Element:0x3ff997067414 name="ItemLookupResponse" children=[#<Nokogiri::XML::Element:0x3ff99706b924 name="OperationRequest" children=[#<Nokogiri::XML::Element:0x3ff99706b474 name="HTTPHeaders" children=[#<Nokogiri::XML::Element:0x3ff99706f470 name="Header" attributes=[#<Nokogiri::XML::Attr:0x3ff99706f0ec name="Name" value="UserAgent">, #<Nokogiri::XML::Attr:0x3ff99706f074 name="Value" value="Ruby">]>]>, #<Nokogiri::XML::Element:0x3ff9970760cc name="RequestId" children=[#<Nokogiri::XML::Text:0x3ff999296468 "053626d3-e3cd-47d2-bc8b-7ac6a0c5f6d2">]>, #<Nokogiri::XML::Element:0x3ff99929f6f8 name="Arguments" children=[#<Nokogiri::XML::Element:0x3ff9992a3bb8 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992a3960 name="Name" value="Operation">, #<Nokogiri::XML::Attr:0x3ff9992a3938 name="Value" value="ItemLookup">]>, #<Nokogiri::XML::Element:0x3ff9992a73f8 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992a7204 name="Name" value="Signature">, #<Nokogiri::XML::Attr:0x3ff9992a7010 name="Value" value="IMd3D0DGgAcaLR6XcuObzdAgFbOya7mbIRtZFbNijVA=">]>, #<Nokogiri::XML::Element:0x3ff9992ab41c name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992ab2dc name="Name" value="AssociateTag">, #<Nokogiri::XML::Attr:0x3ff9992ab2c8 name="Value" value="textscom-20">]>, #<Nokogiri::XML::Element:0x3ff9992af774 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992af6ac name="Name" value="ItemId">, #<Nokogiri::XML::Attr:0x3ff9992af698 name="Value" value="9780521153348">]>, #<Nokogiri::XML::Element:0x3ff9992b0c3c name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992b0b4c name="Name" value="IdType">, #<Nokogiri::XML::Attr:0x3ff9992b0b10 name="Value" value="ISBN">]>, #<Nokogiri::XML::Element:0x3ff9992b7794 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992b7578 name="Name" value="AWSAccessKeyId">, #<Nokogiri::XML::Attr:0x3ff9992b7550 name="Value" value="AKIAJLOCEGWTFXZKXLEQ">]>, #<Nokogiri::XML::Element:0x3ff9992b2244 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992b208c name="Name" value="Timestamp">, #<Nokogiri::XML::Attr:0x3ff9992b2064 name="Value" value="2013-05-07T17:46:35Z">]>, #<Nokogiri::XML::Element:0x3ff9992bffc0 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992bff20 name="Name" value="ResponseGroup">, #<Nokogiri::XML::Attr:0x3ff9992bff0c name="Value" value="ItemAttributes">]>, #<Nokogiri::XML::Element:0x3ff9992be1e8 name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992c38c8 name="Name" value="SearchIndex">, #<Nokogiri::XML::Attr:0x3ff9992c3a30 name="Value" value="Books">]>, #<Nokogiri::XML::Element:0x3ff9992ca95c name="Argument" attributes=[#<Nokogiri::XML::Attr:0x3ff9992ca344 name="Name" value="Service">, #<Nokogiri::XML::Attr:0x3ff9992ca2a4 name="Value" value="AWSECommerceService">]>]>, #<Nokogiri::XML::Element:0x3ff9992d3d7c name="RequestProcessingTime" children=[#<Nokogiri::XML::Text:0x3ff9992d382c "0.0289960000000000">]>]>, #<Nokogiri::XML::Element:0x3ff9992d7eb8 name="Items" children=[#<Nokogiri::XML::Element:0x3ff9992d7148 name="Request" children=[#<Nokogiri::XML::Element:0x3ff9992d6900 name="IsValid" children=[#<Nokogiri::XML::Text:0x3ff9992dae10 "True">]>, #<Nokogiri::XML::Element:0x3ff9992da758 name="ItemLookupRequest" children=[#<Nokogiri::XML::Element:0x3ff9992df884 name="IdType" children=[#<Nokogiri::XML::Text:0x3ff9992df014 "ISBN">]>, #<Nokogiri::XML::Element:0x3ff9992de678 name="ItemId" children=[#<Nokogiri::XML::Text:0x3ff9992e2e1c "9780521153348">]>, #<Nokogiri::XML::Element:0x3ff9983a5580 name="ResponseGroup" children=[#<Nokogiri::XML::Text:0x3ff9983a59b8 "ItemAttributes">]>, #<Nokogiri::XML::Element:0x3ff9983a510c name="SearchIndex" children=[#<Nokogiri::XML::Text:0x3ff9983a43c4 "Books">]>, #<Nokogiri::XML::Element:0x3ff9983a925c name="VariationPage" children=[#<Nokogiri::XML::Text:0x3ff9983a8d0c "All">]>]>]>, #<Nokogiri::XML::Element:0x3ff9983a8244 name="Item" children=[#<Nokogiri::XML::Element:0x3ff9983add70 name="ASIN" children=[#<Nokogiri::XML::Text:0x3ff9983ad6f4 "0521153344">]>, #<Nokogiri::XML::Element:0x3ff9983acc04 name="DetailPageURL" children=[#<Nokogiri::XML::Text:0x3ff9983ac4d4 "http://www.amazon.com/Turgot-Progress-Sociology-Economics-Philosophical/dp/0521153344%3FSubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0521153344">]>, #<Nokogiri::XML::Element:0x3ff9983b1768 name="ItemLinks" children=[#<Nokogiri::XML::Element:0x3ff9983b1024 name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983b0a20 name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983b028c "Technical Details">]>, #<Nokogiri::XML::Element:0x3ff9983b5b60 name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983b5638 "http://www.amazon.com/Turgot-Progress-Sociology-Economics-Philosophical/dp/tech-data/0521153344%3FSubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983b5034 name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983b4a58 name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983b46d4 "Add To Baby Registry">]>, #<Nokogiri::XML::Element:0x3ff9983b406c name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983b9ad0 "http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3D0521153344%26SubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983b95d0 name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983b9080 name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983b8cd4 "Add To Wedding Registry">]>, #<Nokogiri::XML::Element:0x3ff9983b8a2c name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983b834c "http://www.amazon.com/gp/registry/wedding/add-item.html%3Fasin.0%3D0521153344%26SubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983bcff0 name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983bc49c name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983bc0f0 "Add To Wishlist">]>, #<Nokogiri::XML::Element:0x3ff9983c1b40 name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983c158c "http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3D0521153344%26SubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983c01dc name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983c5da8 name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983c595c "Tell A Friend">]>, #<Nokogiri::XML::Element:0x3ff9983c5358 name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983c4674 "http://www.amazon.com/gp/pdp/taf/0521153344%3FSubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983c9750 name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983c8828 name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983cc888 "All Customer Reviews">]>, #<Nokogiri::XML::Element:0x3ff9983d1f18 name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983d19c8 "http://www.amazon.com/review/product/0521153344%3FSubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>, #<Nokogiri::XML::Element:0x3ff9983d152c name="ItemLink" children=[#<Nokogiri::XML::Element:0x3ff9983d107c name="Description" children=[#<Nokogiri::XML::Text:0x3ff9983d02d0 "All Offers">]>, #<Nokogiri::XML::Element:0x3ff9983d5730 name="URL" children=[#<Nokogiri::XML::Text:0x3ff9983d4e48 "http://www.amazon.com/gp/offer-listing/0521153344%3FSubscriptionId%3DAKIAJLOCEGWTFXZKXLEQ%26tag%3Dtextscom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0521153344">]>]>]>, #<Nokogiri::XML::Element:0x3ff9983dd00c name="ItemAttributes" children=[#<Nokogiri::XML::Element:0x3ff9983dc33c name="Author" children=[#<Nokogiri::XML::Text:0x3ff9983e1364 "Ronald L. Meek">]>, #<Nokogiri::XML::Element:0x3ff9983e0af4 name="Binding" children=[#<Nokogiri::XML::Text:0x3ff9983e04a0 "Paperback">]>, #<Nokogiri::XML::Element:0x3ff9983e0068 name="EAN" children=[#<Nokogiri::XML::Text:0x3ff9983e5c34 "9780521153348">]>, #<Nokogiri::XML::Element:0x3ff9983e5270 name="EANList" children=[#<Nokogiri::XML::Element:0x3ff9983e4424 name="EANListElement" children=[#<Nokogiri::XML::Text:0x3ff9983d7c60 "9780521153348">]>]>, #<Nokogiri::XML::Element:0x3ff9983d7724 name="ISBN" children=[#<Nokogiri::XML::Text:0x3ff9983d7120 "0521153344">]>, #<Nokogiri::XML::Element:0x3ff9983d6cc0 name="IsEligibleForTradeIn" children=[#<Nokogiri::XML::Text:0x3ff9983d6130 "1">]>, #<Nokogiri::XML::Element:0x3ff9983d99c0 name="ItemDimensions" children=[#<Nokogiri::XML::Element:0x3ff9983d963c name="Height" attributes=[#<Nokogiri::XML::Attr:0x3ff9983d959c name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff9983d83cc "902">]>, #<Nokogiri::XML::Element:0x3ff9983ed7a4 name="Length" attributes=[#<Nokogiri::XML::Attr:0x3ff9983ed448 name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff9983f3244 "598">]>, #<Nokogiri::XML::Element:0x3ff9983f290c name="Weight" attributes=[#<Nokogiri::XML::Attr:0x3ff9983f26f0 name="Units" value="hundredths-pounds">] children=[#<Nokogiri::XML::Text:0x3ff9983e93c0 "64">]>, #<Nokogiri::XML::Element:0x3ff9983e8f38 name="Width" attributes=[#<Nokogiri::XML::Attr:0x3ff9983e8e34 name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff9983efa2c "43">]>]>, #<Nokogiri::XML::Element:0x3ff9983ef144 name="Label" children=[#<Nokogiri::XML::Text:0x3ff9983eecbc "Cambridge University Press">]>, #<Nokogiri::XML::Element:0x3ff9983ee988 name="Languages" children=[#<Nokogiri::XML::Element:0x3ff9983ee410 name="Language" children=[#<Nokogiri::XML::Element:0x3ff99a80009c name="Name" children=[#<Nokogiri::XML::Text:0x3ff99a801a14 "English">]>, #<Nokogiri::XML::Element:0x3ff99a8010f0 name="Type" children=[#<Nokogiri::XML::Text:0x3ff99a800948 "Unknown">]>]>, #<Nokogiri::XML::Element:0x3ff99a800574 name="Language" children=[#<Nokogiri::XML::Element:0x3ff99a8002b8 name="Name" children=[#<Nokogiri::XML::Text:0x3ff99a80419c "English">]>, #<Nokogiri::XML::Element:0x3ff99a805484 name="Type" children=[#<Nokogiri::XML::Text:0x3ff99a804b10 "Original Language">]>]>, #<Nokogiri::XML::Element:0x3ff99a804070 name="Language" children=[#<Nokogiri::XML::Element:0x3ff99a808d64 name="Name" children=[#<Nokogiri::XML::Text:0x3ff99a80d6d4 "English">]>, #<Nokogiri::XML::Element:0x3ff99a80c680 name="Type" children=[#<Nokogiri::XML::Text:0x3ff99a8110a4 "Published">]>]>]>, #<Nokogiri::XML::Element:0x3ff99a8157a8 name="ListPrice" children=[#<Nokogiri::XML::Element:0x3ff99a8142cc name="Amount" children=[#<Nokogiri::XML::Text:0x3ff99a819358 "2899">]>, #<Nokogiri::XML::Element:0x3ff99a818d04 name="CurrencyCode" children=[#<Nokogiri::XML::Text:0x3ff99a818764 "USD">]>, #<Nokogiri::XML::Element:0x3ff99a81c8a0 name="FormattedPrice" children=[#<Nokogiri::XML::Text:0x3ff99a81d534 "$28.99">]>]>, #<Nokogiri::XML::Element:0x3ff99a81ccb0 name="Manufacturer" children=[#<Nokogiri::XML::Text:0x3ff99a81c648 "Cambridge University Press">]>, #<Nokogiri::XML::Element:0x3ff99a81c2d8 name="NumberOfItems" children=[#<Nokogiri::XML::Text:0x3ff99a821cec "1">]>, #<Nokogiri::XML::Element:0x3ff99a821580 name="NumberOfPages" children=[#<Nokogiri::XML::Text:0x3ff99a82043c "194">]>, #<Nokogiri::XML::Element:0x3ff99a825bbc name="PackageDimensions" children=[#<Nokogiri::XML::Element:0x3ff99a824cd0 name="Height" attributes=[#<Nokogiri::XML::Attr:0x3ff99a824b68 name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff99a824168 "63">]>, #<Nokogiri::XML::Element:0x3ff99a829d98 name="Length" attributes=[#<Nokogiri::XML::Attr:0x3ff99a829d20 name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff99a828eac "890">]>, #<Nokogiri::XML::Element:0x3ff99a828c68 name="Weight" attributes=[#<Nokogiri::XML::Attr:0x3ff99a828b8c name="Units" value="hundredths-pounds">] children=[#<Nokogiri::XML::Text:0x3ff99a828074 "66">]>, #<Nokogiri::XML::Element:0x3ff9983f69d0 name="Width" attributes=[#<Nokogiri::XML::Attr:0x3ff9983f68f4 name="Units" value="hundredths-inches">] children=[#<Nokogiri::XML::Text:0x3ff997c6340c "598">]>]>, #<Nokogiri::XML::Element:0x3ff997c62cf0 name="ProductGroup" children=[#<Nokogiri::XML::Text:0x3ff997c623b8 "Book">]>, #<Nokogiri::XML::Element:0x3ff9961e1d2c name="ProductTypeName" children=[#<Nokogiri::XML::Text:0x3ff9961e0e40 "ABIS_BOOK">]>, #<Nokogiri::XML::Element:0x3ff9961e0508 name="PublicationDate" children=[#<Nokogiri::XML::Text:0x3ff9961e7b28 "2010-06-10">]>, #<Nokogiri::XML::Element:0x3ff9961e75c4 name="Publisher" children=[#<Nokogiri::XML::Text:0x3ff9961e727c "Cambridge University Press">]>, #<Nokogiri::XML::Element:0x3ff9961e70b0 name="SKU" children=[#<Nokogiri::XML::Text:0x3ff9961e6bc4 "Y9780521153348">]>, #<Nokogiri::XML::Element:0x3ff9961e682c name="Studio" children=[#<Nokogiri::XML::Text:0x3ff9961ebc64 "Cambridge University Press">]>, #<Nokogiri::XML::Element:0x3ff9961ea120 name="Title" children=[#<Nokogiri::XML::Text:0x3ff996f67ac8 "Turgot on Progress, Sociology and Economics: A Philosophical Review of the Successive Advances of the Human Mind on Universal History Reflections on ... in the History and Theory of Politics)">]>, #<Nokogiri::XML::Element:0x3ff996f676cc name="TradeInValue" children=[#<Nokogiri::XML::Element:0x3ff996f67028 name="Amount" children=[#<Nokogiri::XML::Text:0x3ff996f66ca4 "310">]>, #<Nokogiri::XML::Element:0x3ff996f669d4 name="CurrencyCode" children=[#<Nokogiri::XML::Text:0x3ff996f663a8 "USD">]>, #<Nokogiri::XML::Element:0x3ff996fadbb8 name="FormattedPrice" children=[#<Nokogiri::XML::Text:0x3ff996fad014 "$3.10">]>]>]>]>]>]>]>>
Okay, I figured it out. I was trying to treat item_lookup as a single return value, rather than a hash the way search is returned.
item_lookup is basically the same as item_search:
res = Amazon::Ecs.item_lookup('9780521153348', :response_group => 'ItemAttributes', :id_type => 'ISBN', :search_index => 'Books')
res.items.each do |item|
puts item.get('ItemAttributes/TradeInValue/FormattedPrice')
end
Related
RESTier OData Function that support $expand and $filter
With the help of the RESTier team, I manage to create an RESTier function that return a list of my entity. Here's the code protected EdmModel OnModelExtending(EdmModel model) { var ns = model.DeclaredNamespaces.First(); // PointLoc.Data var entityContainer = (EdmEntityContainer) model.EntityContainer; var locationEntityType = (IEdmEntityType) model.FindDeclaredType(ns + "." + "Location"); var locationEntitySet = entityContainer.FindEntitySet("Locations"); var locationEntityTypeReference = new EdmEntityTypeReference(locationEntityType, false); var locationEntityCollection = EdmCoreModel.GetCollection(locationEntityTypeReference); var ambilLocationsByMarketId = new EdmFunction(ns, "AmbilLocationsByMarketId", locationEntityCollection, false, null, true); model.AddElement(ambilLocationsByMarketId); entityContainer.AddFunctionImport("AmbilLocationsByMarketId", ambilLocationsByMarketId, new EdmEntitySetReferenceExpression(locationEntitySet)); return model; } And here's my implementation on the Controller [HttpGet] [EnableQuery] [ODataRoute("AmbilLocationsByMarketId")] public IQueryable<Location> AmbilLocationsByMarketId() { var locations = DbContext.Locations.Where(l => l.Name.Contains("Hotel")).Select(l => l); return locations; } It works fine returning the list of data with i send a HTTP GET to http://localhost:21922/odata/AmbilLocationsByMarketId but when I try to add $expand or $filter, It's not working. http://localhost:21922/odata/AmbilLocationsByMarketId?$expand=Category I'm Error that reads like { "error": { "code": "", "message": "An error has occurred.", "innererror": { "message": "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; odata.metadata=minimal'.", "type": "System.InvalidOperationException", "stacktrace": "", "internalexception": { "message": "'DbQuery`1' cannot be serialized using the ODataMediaTypeFormatter.", "type": "System.Runtime.Serialization.SerializationException", "stacktrace": " at System.Web.OData.Formatter.ODataMediaTypeFormatter.GetSerializer(Type type, Object value, IEdmModel model, ODataSerializerProvider serializerProvider)\\\r\\\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)\\\r\\\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\\\r\\\n--- End of stack trace from previous location where exception was thrown ---\\\r\\\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\\\r\\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\\r\\\n at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\\\r\\\n at System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext()" } } } } Here's my metadata <EntityType Name="Location"> <Key> <PropertyRef Name="Id" /> </Key> <Property Name="Id" Type="Edm.Int32" Nullable="false"> <Annotation Term="Org.OData.Core.V1.Computed" Bool="true" /> </Property> <Property Name="Name" Type="Edm.String" Nullable="false" MaxLength="500" /> <Property Name="Address" Type="Edm.String" Nullable="false" MaxLength="2000" /> <Property Name="City" Type="Edm.String" MaxLength="500" /> <Property Name="Postcode" Type="Edm.String" MaxLength="100" /> <Property Name="Phone" Type="Edm.String" MaxLength="50" /> <Property Name="Email" Type="Edm.String" MaxLength="200" /> <Property Name="Latitude" Type="Edm.Decimal" Nullable="false" Precision="9" Scale="6" /> <Property Name="Longitude" Type="Edm.Decimal" Nullable="false" Precision="9" Scale="6" /> <Property Name="Street" Type="Edm.String" MaxLength="1000" /> <Property Name="UpVotes" Type="Edm.Int32" Nullable="false" /> <Property Name="DownVotes" Type="Edm.Int32" Nullable="false" /> <Property Name="CategoryId" Type="Edm.Int32" Nullable="false" /> <Property Name="StatusId" Type="Edm.Int32" Nullable="false" /> <Property Name="StateId" Type="Edm.Int32" Nullable="false" /> <Property Name="TitleSlug" Type="Edm.String" MaxLength="200" /> <NavigationProperty Name="Category" Type="PointLoc.Data.Category" Nullable="false" Partner="Locations"> <ReferentialConstraint Property="CategoryId" ReferencedProperty="Id" /> </NavigationProperty> </EntityType> and here's the EntityContainer <EntityContainer Name="DatabaseContext"> <EntitySet Name="Categories" EntityType="PointLoc.Data.Category"> <NavigationPropertyBinding Path="Locations" Target="Locations" /> </EntitySet> <EntitySet Name="Locations" EntityType="PointLoc.Data.Location"> <NavigationPropertyBinding Path="Accesses" Target="Accesses" /> <NavigationPropertyBinding Path="Category" Target="Categories" /> <NavigationPropertyBinding Path="Contents" Target="Contents" /> <NavigationPropertyBinding Path="State" Target="States" /> <NavigationPropertyBinding Path="Status" Target="Status" /> <NavigationPropertyBinding Path="LocationMarketMaps" Target="LocationMarketMaps" /> <NavigationPropertyBinding Path="LocationTagMaps" Target="LocationTagMaps" /> </EntitySet> <FunctionImport Name="AmbilLocationsByMarketId" Function="PointLoc.Data.AmbilLocationsByMarketId" EntitySet="Locations" /> </EntityContainer>
dispalay tag table pass value to requestURI
How do I set value to requestURI by action class in Struts2 or another form. I need to change value of requestURI according to tile.
Option 1: Pass value from action (Better way) In yourAction.java private String myActionName; public String execute() { myActionName="action1.action"; return SUCCESS; } public void setMyActionName(String myActionName) { this.myActionName = myActionName; } public String getMyActionName() { return myActionName; } In jsp file <display:table id="u" name="userlist" pagesize="10" requestURI="${myActionName}" > ... </display:table> If you want to pass your own parameter in url <s:url action="%{myActionName}" var="requrl" > <s:param name="myparam">myvalue1</s:param> </s:url> <display:table id="u" name="userlist" pagesize="10" requestURI="${requrl}" > ... </display:table> Option 2: Pass value from tile (Not Recommanded) In tiles.xml <definition name="baseLayout" template="/BaseLayout.jsp"> <put-attribute name="title" value="" type="string" /> <put-attribute name="header" value="/Header.jsp" /> <put-attribute name="menu" value="/Menu.jsp" /> <put-attribute name="body" value="" /> <put-attribute name="footer" value="/Footer.jsp" /> <put-attribute name="myattribute" value="" type="string" /> </definition> <definition name="/welcome.tiles" extends="baseLayout"> <put-attribute name="title" value="Welcome" type="string" /> <put-attribute name="body" value="/Welcome.jsp" /> <put-attribute name="myActionName" cascade="true" value="tileAction1.action" /> </definition> Note: Use proper tiles version and tiles.xml dtd to use cascade="true". In welcome.jsp <tiles:useAttribute name="myActionName" /> <display:table id="u" name="userlist" pagesize="10" requestURI="${myActionName}" > ... </display:table>
render composite component based on a Boolean condition
I developed a composite JSF 2 component, and it is working pretty well. In one of the pages where I use my custom component, it is necessary that composite component should be rendered according to a boolean condition. Pretty Much similar as the rendered attribute works in JSF standard components. So I tried to implement it like this: <cc:interface componentType="ciudadComponent"> <cc:attribute name="paises" type="java.util.List" required="true" /> <cc:attribute name="departamentos" type="java.util.List" required="true" /> <cc:attribute name="ciudades" type="java.util.List" required="true" /> <cc:attribute name="name" type="java.lang.String" required="true" /> <cc:attribute name="value" type="org.colfuturo.model.to.CiudadTO" required="true"## Heading ## /> <cc:attribute name="etiquetaPais" type="java.lang.String" /> <cc:attribute name="etiquetaBotonOK" type="java.lang.String" /> <cc:attribute name="etiquetaBotonCancelar" type="java.lang.String" /> <cc:attribute name="etiquetaDepartamento" type="java.lang.String" /> <cc:attribute name="etiquetaCiudad" type="java.lang.String" /> <cc:attribute name="styleClass" type="java.lang.String" /> <cc:attribute name="backGroundColor" type="java.lang.String" default="#b0c4de" /> <cc:attribute name="rendered" type="java.lang.Boolean" required="false" default="true" /> </cc:interface> <cc:implementation> <h:inputText id="seleccionado" binding="#{cc.seleccionado}" disabled="true" rendered="#{cc.rendered}"> <f:converter converterId="CiudadConverter" /> </h:inputText> </cc:implementation> In the page where I insert the composite component, it is like this: <gambatte:ciudad paises="#{menuTreeBean.listaPaises}" departamentos="#{menuTreeBean.listaDepartamentos}" ciudades="#{menuTreeBean.listaCiudades}" styleClass="mySelectStyle" etiquetaBotonOK="#{msg['perfil.common.btnOK']}" etiquetaBotonCancelar="#{msg['perfil.common.btnCancelar']}" etiquetaPais="#{msg['perfil.common.lblPais']}" etiquetaDepartamento="#{msg['perfil.common.lblDepartamento']}" etiquetaCiudad="#{msg['perfil.common.lblCiudad']}" name="otraSedeCiudad" value="#{EstudiosRealizadosBean.otraSedeCiudad}" rendered="#{EstudiosRealizadosBean.showOtraSede()}" /> The method EstudiosRealizadosBean.showOtraSede() returns java.lang.Boolean. I get the following Exception when rendering the page: java.lang.IllegalArgumentException: rendered How can I solve this ? I have also tried to put a boolean condition, but the same exception is raised I am posting my whole component code: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j" xmlns:cc="http://java.sun.com/jsf/composite"> <cc:interface componentType="ciudadComponent"> <cc:attribute name="paises" type="java.util.List" required="true" /> <cc:attribute name="departamentos" type="java.util.List" required="true" /> <cc:attribute name="ciudades" type="java.util.List" required="true" /> <cc:attribute name="name" type="java.lang.String" required="true" /> <cc:attribute name="value" type="org.colfuturo.model.to.CiudadTO" required="true" /> <cc:attribute name="etiquetaPais" type="java.lang.String" /> <cc:attribute name="etiquetaBotonOK" type="java.lang.String" /> <cc:attribute name="etiquetaBotonCancelar" type="java.lang.String" /> <cc:attribute name="etiquetaDepartamento" type="java.lang.String" /> <cc:attribute name="etiquetaCiudad" type="java.lang.String" /> <cc:attribute name="styleClass" type="java.lang.String" /> <cc:attribute name="backGroundColor" type="java.lang.String" default="#b0c4de" /> <cc:attribute name="cacheInterface" type="org.colfuturo.business.interfaces.IServicioCache" required="false" /> </cc:interface> <cc:implementation> <span id="#{cc.clientId}" style="white-space:nowrap"> <h:inputText id="seleccionado" binding="#{cc.seleccionado}" disabled="true" > <f:converter converterId="CiudadConverter" /> </h:inputText> <a4j:commandButton execute="#none" immediate="true" value=".." oncomplete="document.getElementById('#{cc.attrs.name}').style.position = 'absolute'; document.getElementById('#{cc.attrs.name}').style.display = 'inline-block';" /> <br /> <ui:fragment> <div id="#{cc.attrs.name}" layout="block" style="border-radius: 10px; background-color:#{cc.attrs.backGroundColor}; display:none;" > <table border="0"> <tr> <td><h:outputText value="#{cc.attrs.etiquetaPais}" /></td> <td> <rich:select id="pais" binding="#{cc.pais}" styleClass="#{cc.attrs.styleClass}" defaultLabel="Seleccione un PaĆs" > <f:selectItems value="#{cc.listaPaises}" /> <f:ajax event="selectitem" execute="#this" listener="#{cc.updatePais}" /> </rich:select> </td> </tr> <tr> <td><h:outputText value="#{cc.attrs.etiquetaDepartamento}" /></td> <td> <rich:select id="departamento" binding="#{cc.departamento}" styleClass="#{cc.attrs.styleClass}" defaultLabel="Seleccione un Departamento" > <f:selectItems value="#{cc.listaDepartamentos}" /> <f:ajax event="selectitem" execute="#this" listener="#{cc.updateDepartamento}" /> </rich:select> <a4j:outputPanel layout="block" binding="#{cc.panelOtroDepartamento}" > <h:inputText id="otroDepartamento" binding="#{cc.otroDepartamento}" > <f:ajax event="keyup" listener="#{cc.enableSubmit}" execute="#this otraCiudad" /> </h:inputText> </a4j:outputPanel> </td> </tr> <tr> <td><h:outputText value="#{cc.attrs.etiquetaCiudad}" /></td> <td> <rich:select id="ciudad" binding="#{cc.ciudad}" styleClass="#{cc.attrs.styleClass}" defaultLabel="Seleccione una Ciudad" > <f:selectItems value="#{cc.listaCiudades}" /> <f:ajax event="selectitem" execute="#this" listener="#{cc.updateCiudad}" /> </rich:select> <a4j:outputPanel layout="block" binding="#{cc.panelOtraCiudad}" > <h:inputText id="otraCiudad" binding="#{cc.otraCiudad}" > <f:ajax event="keyup" listener="#{cc.enableSubmit}" execute="#this otroDepartamento" /> </h:inputText> </a4j:outputPanel> </td> </tr> <tr> <td> <h:commandButton value="#{cc.attrs.etiquetaBotonOK}" disabled="true" binding="#{cc.botonAcccion}" onclick="document.getElementById('#{cc.attrs.name}').style.position = 'absolute'; document.getElementById('#{cc.attrs.name}').style.display = 'none';" > <f:ajax execute="ciudad" listener="#{cc.submit}" /> </h:commandButton> </td> <td> <a4j:commandButton value="#{cc.attrs.etiquetaBotonCancelar}" execute="#none" immediate="true" oncomplete="document.getElementById('#{cc.attrs.name}').style.position = 'absolute'; document.getElementById('#{cc.attrs.name}').style.display = 'none';" /> </td> </tr> </table> </div> </ui:fragment> <div style="display:block;" ></div> </span> </cc:implementation> </html>
Get rid of <cc:attribute name="rendered">. It's already defined in UIComponent class, which <cc:implementation> extends from. You don't need to redefine it. The same story applies to id and binding attributes, by the way. You also don't need to re-apply rendered="#{cc.rendered}" on the composite component's first child. You can also just get rid of it. The <my:composite rendered> already applies on the whole composite component itself.
Nested tool-bar button in xul
I am having a toolbar-button with type "menu-button". Can I have two toolbar-buttons inside this one?
Since you would like to have a button inside a menu-button, here you go. But, this is not a pretty good UI. <?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <window id="main-window"> <toolbox id="navigator-toolbox"> <toolbar id="xulschoolhello-toolbar" toolbarname="xulschoolhello.toolbarName.label;" customizable="true" mode="icons" context="toolbar-context-menu" defaultset="xulschoolhello-hello-world-button" insertbefore="PersonalToolbar" /> <hbox> <row> <button flex="1" type="menu" label="Menu"> <menupopup> <menuitem label="Option 1" oncommand="setText('menu-text','Option 1');" /> <menuitem label="Option 2" oncommand="setText('menu-text','Option 2');" /> <menuitem label="Option 3" oncommand="setText('menu-text','Option 3');" /> <menuitem label="Option 4" oncommand="setText('menu-text','Option 4');" /> </menupopup> </button> </row> <row> <button flex="1" type="menu-button" label="MenuButton" oncommand="alert('Button was pressed!');"> <menupopup> <menuitem label="Option A" oncommand="setText('menu-text','Option A');" /> <menuitem label="Option B" oncommand="setText('menu-text','Option B');" /> <menuitem label="Option C" oncommand="setText('menu-text','Option C');" /> <menuitem label="Option D" oncommand="setText('menu-text','Option D');" /> </menupopup> </button></row> </hbox> <hbox pack="center"> <description id="menu-text" value="Testing" /> </hbox> </toolbox> </window> </window>
"An item with the same key has already been added" error when calling Context AddObject
Can somebody please help me with this error. I have an ASP.NET WebApp, within the Entity Model I have an entity called tb_AdminUser, with a UserID property as GUID. This is also the Entity Key. The entity is not in any relationship with any other entity. I get the error when calling the AddObject() function. In my code I call the following... SQL2008R2_824852_leapdbEntities temp = new SQL2008R2_824852_leapdbEntities(); tb_AdminUser au = new tb_AdminUser(); au.UserID = Guid.NewGuid(); au.Username = "TEST"; au.Password = "pete#webinspired.net"; au.LockedOut = false; au.Surname = "Feehan"; au.Forename = "Pete"; temp.tb_AdminUser.AddObject(au); //error occurs here temp.SaveChanges(); The EDMX XML Code is as follows <EntityType Name="tb_AdminUser"> <Key> <PropertyRef Name="UserID" /> </Key> <Property Name="UserID" Type="uniqueidentifier" Nullable="false" /> <Property Name="Forename" Type="nvarchar" Nullable="false" MaxLength="50" /> <Property Name="Surname" Type="nvarchar" Nullable="false" MaxLength="50" /> <Property Name="Username" Type="nvarchar" Nullable="false" MaxLength="50" /> <Property Name="Password" Type="nvarchar" Nullable="false" MaxLength="50" /> <Property Name="LockedOut" Type="bit" Nullable="false" /> </EntityType>