How to display the ID of an item in a List resource and a Datagrid instead of the object's IRI? - react-admin

I noticed that every time an item is displayed in a List resource or a Datagrid component the element's ID property is presented as an IRI string.
I understand this is due to the relationship between HydraAdmin and JSON-LD content negotiation:
Sends proper HTTP requests to the API and decodes them using Hydra and JSON-LD formats
But my (simple) question is: how to display the ID and not the entire context? I only want the last part (the unique ID itself) to be displayed in the Datagrid or List resource column but by no means can I do this even though my API returning an entire ID property cannot display (example image below). Anyway, the value of "#id" (string) is always displayed due to Hydra and JSON-LD relationship.

Debugging the response headers and using useListContext I was able to find that there is an injected property called originId in the data object and that it is possible to display the original ID and not reference it to "#id" as the default for the property ID using as source "originId" and not "id".
in the DataGrid I used source="originId"
...
const {data, ids, basePath} = useListContext();
return (
<Datagrid fullWidth>
// here is the magic, use originId instead id
<TextField source={"originId"} label={"ID"}/>
<TextField source={"created_at"} label={"Data"}/>
<TextField source={"author"} label={"Autor"}/>
<TextField source={"content"} />
<TextField source={"is_public"} />
</Datagrid>
)

Related

How can I add a Datagrid reflecting currect state of ReferenceArrayInput to a react-admin edit form?

I'm writing a user management using react-admin and try to make adding users to groups easier, i.e. by adding groups from a user's edit page using auto-complete. Starting with an example, I've got some success using the following:
<ReferenceArrayInput
label="Group"
source="groups"
reference="groups"
>
<AutocompleteArrayInput
{...props}
resettable={true}
allowEmpty={true}
optionText="name"
fullWidth
/>
</ReferenceArrayInput>
However, this method uses Chip component to display selected items inline. I would like to use a Datagrid instead. I know from the source code that I cannot override the display part of an auto-complete (yet?), so I thought I could resort to hiding Chips via CSS, but I would still need a way to display a Datagrid with current selection. So I tried this (it's wrapped in FormWithRedirect, hence formProps):
<ReferenceArrayField
{...formProps}
label="Group"
source="groups"
reference="groups"
>
<Datagrid>
<TextField source="name" />
</Datagrid>
</ReferenceArrayField>
<ReferenceArrayInput
{...formProps}
label="Group"
source="groups"
reference="groups"
>
<AutocompleteArrayInput
resettable={true}
allowEmpty={true}
optionText="name"
fullWidth
/>
</ReferenceArrayInput>
This works almost exactly as I want it, a Datagrid is displayed and it shows the right data for the selection, however, it's not updated when selected items on AutocompleteArrayInput change. How ever I tried (been through probably all the hooks and contexts), I could not make it work.
Is this possible? How can I make Datagrid update when selection changes on AutocompleteArrayInput?

passing model back to controller with checkboxes comes back empty

trying to grasp how to pass back the following data as a model to the controller. I want to consume the model and add everything to a database afterwards. When I submit the form back to the controller, the model is empty. Is it because every thing else is null? do I have to pass everything else back as hidden fields? How do I sort that all out on the View before getting to the controller?
My controller basically deserializes an xml file that looks like this back to the view
<category>
<id>1</id>
<description>movies</description>
<genre>
<genres>
<id>1</id>
<name>comedy</name>
</genres>
<genres>
<id>2</id>
<name>action</name>
</genres>
<genres>
<id>3</id>
<name>adventure</name>
</genres>
<genres>
<id>4</id>
<name>drama</name>
</genres>
<genres>
<id>5</id>
<name>romance</name>
</genres>
</genres>
</category>
The view / form looks like this
<form>
<ul>
#for (int x = 0; x < Model.categories[i].genres.Count(); x++)
{
<li>
<label for="#Model.categories[i].genres[x].name">
<input type="checkbox" name="#Model.categories[i].genres[x].name" value="#Model.categories[i].genres[x].id" checked="#Model.categories[i].genres[x].selected" /> #Model.categories[i].genres[x].name
</label>
</li>
}
</ul>
</form>
Give all your checkboxes a fixed name, like GenreIds.
Then, in your action you should receive a string[] genreIds parameter.
When posting the form, the genreIds is posted as am array, so it must be received in an array parameter.
If this doesn't work because you have many categories and want to receive each group of GenreIds in its own category, then you can send a JSON representation of the form values and receive and deserialize it on the server side. To do so:
On the razor template:
Use the name of the genre to name all the checkboxes in each category
Handle the form sumit event, and:
Use jQuery serializeArray, to put all the form elements in an array
Then use JSON.stringify to convert this array to JSON format
Finally copy this string to a hidden field with a fixed name and post the form. I.e. in a hidden field with the name "serializedFormValues"
On the server side:
Add a parameter to your action with the name "serializedFormValues", and type = string
get the value of this parameter and deserialize the received JSON string, and use it on the server side
If you use JSON.NET you can convert the JSON to XML, or to an anonymous type object. There are another posibilities.
Remember that in any case, the genre Ids will always be string[] (or int, if ti's the case) and this arrays will only contain the checked values.
There is a last posibility which is processing the Request.Form "manually". But this is harder to do.
Try using CheckboxFor instead of the input tag.
As for your code, you don't have an ID associated with your checkbox. How are you supposed to be receiving it back in your controller?

how to combine html:text and bean:write

I am using <bean:write/> tag in my struts program to catch my data into text field but I want to update/edit those data which is coming by this tag so I want to use <html:text/> tag with <bean:write/>, is it possible?
is there any other option to update <bean:write/> tag's data.
I am using this tag like -
<bean:write name="Customer" property="lastname"/>
It's not entirely clear to me what you want to update, and under what circumstances.
If you're saying to want to have the customer's last name be an editable text field, then initialize the ActionForm with the appropriate values before displaying it to the user; you don't need the <bean:write> tag at all if you're just trying to initialize/show a form field.

SharePoint 2010: RemoveFieldRef and Inherits="TRUE"

I have created a custom content type that inherits from the OOTB SharePoint Picture content type. The only customisations I have made is to add a simple URL field, and remove two of the fields on the base type. See below:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Parent ContentType: Picture (0x010102) -->
<ContentType ID="0x0101020027f16ab27e6e45a6848c25c47aaa7053"
Name="Custom Picture"
Description=""
Group="Custom"
Inherits="TRUE"
Version="0">
<FieldRefs>
<RemoveFieldRef ID="{b66e9b50-a28e-469b-b1a0-af0e45486874}" Name="Keywords" />
<RemoveFieldRef ID="{a5d2f824-bc53-422e-87fd-765939d863a5}" Name="ImageCreateDate" />
<FieldRef ID="{c29e077d-f466-4d8e-8bbe-72b66c5f205c}" Name="URL" DisplayName="URL" Required="FALSE" />
</FieldRefs>
</ContentType>
</Elements>
If I create a picture library based on my custom content type, the "URL" field that I added appears in the new/edit forms, however the two fields that I have attempted to remove are also displayed, i.e. the RemoveFieldRef's are being ignored. If I look at the content type in "Site Settings -> Content Type Gallery", these two fields are still listed there.
Setting Inherits="FALSE" on my custom content type (see MSDN definition) successfully removes just these two fields from the "Site Settings -> Content Type Gallery" page, however then none of the base fields are displayed in the new/edit forms -- only my custom "URL" field.
What can I do to ensure that all the fields from the base "Picture" content type are displayed on the new/edit forms of my picture library except the two fields that I have specifically removed?
I believe the nature of this issue to be the understanding of how content type inheritance works.
From MSDN (http://msdn.microsoft.com/en-us/library/aa544268.aspx)
If Inherits is TRUE, the child content type inherits all fields that are in the parent, >including fields that users have added.
If Inherits is FALSE or absent and the parent content type is a built-in type, the child >content type inherits only the fields that were in the parent content type when >SharePoint Foundation was installed. The child content type does not have any fields that >users have added to the parent content type.
If Inherits is FALSE or absent and the parent content type was provisioned by a sandboxed >solution, the child does not inherit any fields from the parent.
I think the key phrase above is "If Inherits is TRUE, the child content type inherits ALL fields that are in the parent including fields that users have added."
This means that in order to accomplish what you set out to do you will have inherits set to false and you will have to include FieldRef elements for all fields you wish to use in your content type.
You make no reference / don't include code for how the content type was added to your list instance. Make sure this has been updated to support the removal or setting of inherits to false.
These sites support what is described here.
http://kvdlinden.blogspot.com/2011/06/issues-with-removefieldref-and.html
http://nelsonlamprecht.wordpress.com/2010/08/25/sharepoint-2010-removefieldref-and-inherits%E2%80%9Dtrue%E2%80%9D/

struts form and JSTL

How to access a form variable using JSTL ?
e.g.
<html:text property="abc" ... />
<c:out value="${abc}"/>
abc is always blank, even though I have value set by action sending to this page.
If you refer with ActionForm, you can retrieve the value. "abc" is one of the property of ActionForm(you created) which will be available in request scope as it has been set in ActionServlet during processing request.
So get the value like this, suppose your ActionForm is 'TestForm', then retrieve as ${TestForm.abc} or <c:out value="${TestForm.abc}"/>