How to use single_media_upload - sulu

I am looking for an example for simple use of single_media_upload in SULU AdminUI.
I have a player form, and it has single_media_selection type of field, and it works OK.
Now, how can I use single_media_upload, because, when I replace it instead of single_media_selection, it shows not picture in form after save (but it saves image).
<property name="photo" type="single_media_selection" colspan="4" >
<meta>
<title>playerinfo.playerimage</title>
</meta>
<params>
<param name="types" value="image"/>
</params>
</property>
I replace with
<property name="photo" type="single_media_upload" colspan="4" spaceAfter="2">
<params>
<param name="upload_text">
<meta>
<info_text>app.player_info_upload</info_text>
</meta>
</param>
<param name="skin" value="default"/>
<param name="empty_icon" value="su-user"/>
<param
name="collection_id"
type="expression"
value="service('sulu_media.system_collections.manager').getSystemCollection('sulu_media')"
/>
</params>
</property>
In Entity itself, field is MediaInterface type.

The single_media_upload field-type is not interchangeable with the single_media_selection type. It was implemented for managing the avatar/logo of the built-in contact/account entity and was not optimized for other usecases yet. At the moment, the single_media_upload creates a new media version for the selected media entity rather than creating a separate media entity when uploading a file. This behaviour differs substantially from the single_media_selection and might not fit your usecase. This is also the reason why the field-type is not listed in the Sulu documentation yet.
That said, the reason for your problem is likely that the single_media_upload field-type uses a different data format than the single_media_selection. In general, the field-types of the Sulu form view expect that your API returns the data in the same format as it is sent to the server when submitting the form (see the Form configuration section in the Sulu documentation). You can see the data that is sent to the server by inspecting the request that is made when pressing the save button in the network panel development tools of your browser.
In the case of the single_media_upload field-type, the data that is sent to the server looks like this:
{
"id": 33,
"url": "/media/33/download/photo-1535683939029-0030b4de2382.jpeg?v=1",
"thumbnails": {
"sulu-400x400": "/uploads/media/sulu-400x400/03/33-photo-1535683939029-0030b4de2382.jpg?v=1-0",
...
}
}
If you want to use the field-type in the form of your custom entity, you need to adjust your controller (or the serialization of your entity) to match this format.

Related

Disable form fields in Sulu's admin frontend after the entity has been persisted

I'd like to connect the key of a category in the Sulu CMS with specific business logic. But therefore the key must not be changeable in the admin area. Is there a way to disable a form field once the entity is persisted?
It's possible to override any form configuration by creating a file with the same name and the same <key> in the config/forms/ directory of your project. In case of the category details form, create a config/forms/category_details.xml file with <key>category_details</key> containing only the properties you want to override, in your case the <property name="key">. You can omit the other properties, because all the form configurations with the same key will be merged together. Then you can use a disabledCondition to configure when this property should be disabled and when it should be possible to edit, in your case something like disaledCondition="!!id", because then the property is only editable, as long as it doesn't have an id, which is only the case when you create a new category. You probably also want to add the mandatory="true" attribute, if your application depends on the key of a category. So the whole file should look like this:
<?xml version="1.0" ?>
<form xmlns="http://schemas.sulu.io/template/template"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd"
>
<key>category_details</key>
<properties>
<property name="key" type="text_line" mandatory="true" disabledCondition="!!id">
<meta>
<title>sulu_admin.key</title>
</meta>
</property>
</properties>
</form>

WebMethods Integration Server pub.client.soapclient changes the request element names

I have an issue with build-in (non accessible) webMethods Integration Server soapClient service. Somehow it changes the request it should send while processing it, renaming parameter items to item.
what is send to the method:
<request>
<t1>1</t1>
<operation>op</operation>
<service>1</service>
<params>
<count>1</count>
<items>
<key>12</key>
<value>12</value>
</items>
</params>
</request>
what request webmethods sends:
<request>
<t1>1</t1>
<operation>op</operation>
<service>1</service>
<params>
<count>1</count>
<item>
<key>12</key>
<value>12</value>
</item>
</params>
</request>
I'd be grateful for any workaround/idea for a solution.
I see in your example code that you first create an document named "items", then you map this document to a document list named "items". This is not valid. Please note that the pipeline in IntegrationServer is nothing but a key-value map, and the keys must be unique. That is the reason why you still have a single document named "items" instead of a document list. Rename your document to something like "item", and then use appendToDocumentList to add it to the "items" doc list.

Alfresco Share constraint default empty value

i have a simple question.
Is there a simple config file or line that can be edited in order to achieve this:
I need that constraints from Alfresco content model have an empty field (like "unselected") in Advanced Search and Edit Metadata forms.
So a constraint of:
<constraint name="custom:customList" type="LIST">
<parameter name="allowedValues">
<list>
<value>first type</value>
<value>second type</value>
</list>
</parameter>
</constraint>
I need to view these in a "SELECT" form but with the first selection empty, like:
<select>
<value></value>
<value>first type</value>
<value>second type</value>
</select>
Hope I made that clear.
P.S. I don't want to insert a in the custom content model XML file. There should be another way to achieve this.
Thanks to all.
You need to override the presentation logic, i.e. customize or create a new form control template. The default one is implemented in selectone.ftl, you can customize it or start from it for a brand new control template which you can later assign to your metadata field in the forms configuration.

Struts 2 - Persist property value for redirect action

I want to retain a property value after redirecting to a different action. I know that the value will go away since we are navigating to different action (request). But I need to some how that how can I achieve this ?
Here is my code :
<action name="save" class="saveAction" method="saveData">
<result name="success" type="redirectAction">redirectedPageAction</result>
<result name="successView" >successView.jsp</result>
<result name="error" >error.jsp</result>
</action>
<action name="redirectedPageAction" class="month" method="">
<result name="success">employeesList.jsp</result>
</action>
In save action class I am using addActionMessage(String msg) method to set a value. Also I have getter/setter for the same.
I tried this but didn't get success :
<action name="redirectedPageAction" class="month" method="">
<result name="success">employeesList.jsp>
<param name="msg">${msg}</param>
</result>
</action>
I want value which was set by adActionMessage(msg) in my employeelist.jsp page. I am getting null pointer struts exception.
Please help..
Actions are created per-request. If you don't actually pass anything from the first action to the second, there won't be anything for the second action to retrieve. Getters don't change HTTP mechanics.
If you're interested specifically in messages/etc., use the MessageStoreInterceptor, or do it manually.
Since you already mentioned that and you know that it will create a new request cycle and Actions and created per request since they work as Data object also ,which means your request/response parameters will be lost.
Now you have few option
Try using the Struts2 build in support for this message-store-interceptor.
This interceptor has been created to store a ValidationAware action's messages / errors and field errors into HTTP Session and is very useful in your use-case.
If you want wider scope either you can store data in the session and retrieve that at later stage or can pass values as query parameters.
I've faced this problem before, sometimes you need to show a whole new view after an action and the redirect result does not take into consideration any previous data (http request stuff).
We wanted to create a custom interceptor, but before doing it I found this
http://www.mail-archive.com/user#struts.apache.org/msg77854.html
It really helped us a lot.
Having said that, what version of Struts 2 are you using? We use Struts 2.2.3 and the parameters passed to the redirectAtion works fine.
Do you have setter and getters in both actions?
You can pass your property variable with redirectAction as a parameter like this
<action name="save" class="saveAction" method="saveData">
<result name="success" type="redirectAction">
<param name="actionName">redirectedPageAction</param>
<param name="msg">${msg}</param>
</result>
<result name="successView" >successView.jsp</result>
<result name="error" >error.jsp</result>
</action>
Also, dont miss to add getter/setter for msg variable in your redirectedPageAction action

Populate fields after redirect in struts 2

I'm trying to understand if there is an easiest and shorter way to populate the fields of a form, after it fails validation and it's redirected (following the pattern described here).
I have a form that is called from addPerson.action action, and submit action is savePerson.action.
If it fails validation, I redirect passing all parameters, so that the redirected page will populate the fields with the data inserted by the user, avoiding the user the hassle to start from scratch.
The problem of this solution is that I have to list every single parameter of the form in the struts.xml, like in the example below:
<action name="savePerson" class="personAction" method="savePerson">
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
<interceptor-ref name="myStack" />
<result name="success" type="redirectAction">
<param name="actionName">listPeople</param>
</result>
<result name="input" type="redirectAction">
<param name="actionName">addPerson</param>
<param name="parse">true</param>
<param name="person.name">${person.name}</param>
<param name="person.surname">${person.surname}</param>
<param name="person.gender">${person.gender}</param>
<param name="person.email">${person.email}</param>
<param name="person.mobile">${person.mobile}</param>
</result>
</action>
<action name="addPerson" class="personAction" method="addPerson">
<interceptor-ref name="store">
<param name="operationMode">RETRIEVE</param>
</interceptor-ref>
<interceptor-ref name="myStack" />
<result name="success">/person/add.jsp</result>
<result name="input">/person/add.jsp</result>
</action>
I had to use the MessageStoreInterceptor in order to save and retrieve the validation error messages from a redirect.
I'm already using the ajax validation, but I wish to make my pages work in non javascript mode as well. With the code above everything works as expected, but looks weird that I have to list all my parameters inside the result tag.
Is there a better and shorter way of doing it?
thanks
With a redirect you start over, you throw out the value stack except for the parameters you explicitly pass in. What you probably want is chain, which snowballs the value stack.
See here for a list of result types, the link to Chain has some examples: http://struts.apache.org/2.2.1.1/docs/result-types.html
You can then just use the basic result tag and probably will not need a body.
See nmc's comment. This is what I do too, it isn't a good idea to use chain or redirectAction... creates spaghetti actions.