Populate DDLFormScreenlet fields programmaticallyPopulate DDLFormScreenlet fields programmaticallyhttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=800831412024-03-28T19:42:31Z2024-03-28T19:42:31ZRE: Populate DDLFormScreenlet fields programmaticallyJavier Gamarrahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=826868172016-11-22T11:26:18Z2016-11-22T11:26:18ZThank you for your persistence!<br /><br />We will take into account that problem for the next versions <img alt="emoticon" src="@theme_images_path@/emoticons/happy.gif" >Javier Gamarra2016-11-22T11:26:18ZRE: Populate DDLFormScreenlet fields programmaticallyArne Leemanhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=826193302016-11-20T23:06:43Z2016-11-20T23:06:43ZUtimately solved it by:<br /><br />1. Setting the app fixed to en_US<br />2. taking care that values for preset fields do not contain ANY special characters (even : =/ etc.) as these somehow break the json.<br /><br />For those interested I enclose the app code to enjoy..<br /><br />Cheers,<br />ArneArne Leeman2016-11-20T23:06:43ZRE: Populate DDLFormScreenlet fields programmaticallyArne Leemanhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=818095502016-10-28T20:13:37Z2016-10-28T20:13:37ZHi Javier,<br /><br />I'm sorry to say that I can't get it done, intercepting the Json object sent to the server.<br /><br />The obvious thing to do for me would be to log the json object in DDLRecordConnector62.java.<br />I just don't know how to do this. Can you give me some more pointers?<br /><br />Thanks,<br />ArneArne Leeman2016-10-28T20:13:37ZRE: Populate DDLFormScreenlet fields programmaticallyArne Leemanhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=816392882016-10-25T08:48:23Z2016-10-25T08:48:23ZHi Javier,<br /><br />I use the same setup, that is: Liferay 6.2 (GA2), 1.3.0 plugin and 1.4.1 version of screens.<br /><br />I just want to preset some fields, no internal record fields like recordId and such.<br />I'm trying to run the debug test but haven't managed to do it yet.<br /><br />For reference I enclose the android project.<br />If anyone can use it, or parts of it, please enjoy..<br /><br />Arne.Arne Leeman2016-10-25T08:48:23ZRE: Populate DDLFormScreenlet fields programmaticallyJavier Gamarrahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=814739362016-10-20T11:26:46Z2016-10-20T11:26:46Z<html><head></head><body>Uhm... I've tried my code against Liferay 6.2 with a 1.3.0 plugin and using the latest released version of screens (1.4.1) and it works when submitting the field...<br><br>What are the fields you are setting? are you trying to change an internal field of the record or just to preset some fields?<br><br>Can you check or pass me the json sent to the server? You can add a debug breakpoint in the line:<br><br><pre><code>
_command.put("/ddlrecord/add-record", _params);
</code></pre><br><br>of the class DDLRecordService (for 6.2) ?</body></html>Javier Gamarra2016-10-20T11:26:46ZRE: Populate DDLFormScreenlet fields programmaticallyArne Leemanhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=813804282016-10-18T12:15:22Z2016-10-18T12:15:22Z<html><head></head><body>Well, I tried the second suggested method of accessing EditText views directly as well:<br><br><pre><code>
ViewGroup container = (ViewGroup) findViewById(R.id.ddlfields_container);
DDLFieldTextView subject = (DDLFieldTextView) container.getChildAt(1);
EditText ev = (EditText) subject.getChildAt(1);
ev.setText(_recSubject);
</code></pre><br><br>Again, the value appears correctly in the form but on submit I get the same exception mentioned earlier about stuff missing in the json object sent to the server. If I enter the (same) value manually in the form, everything runs allright!<br><br>So, presetting field values in a form this way apparently is a nono, at least to my knowledge..<br><br>Anyone else has a suggestion how to solve this?<br><br>Would it be feasible to somehow alter a predefined field value in the used ddm structure when the form is loaded?</body></html>Arne Leeman2016-10-18T12:15:22ZRE: Populate DDLFormScreenlet fields programmaticallyArne Leemanhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=812772982016-10-15T09:54:45Z2016-10-15T09:54:45Z<html><head></head><body>Hi Javier,<br><br>Had to devote my time to other matters but picked up yesterday where I left off.<br><br>Your code (below) does have the effect that the form is (pre)set with the desired values.<br>However, submitting the form generates the following exception:<br><br><pre><code>
10-15 11:29:24.773 30157-30157/com.liferay.mobile.screens.testapp E/MessagesReplyActivity: onDDLFormRecordAddFailed
com.liferay.mobile.android.exception.ServerException: Expected a ',' or '}' at character 50
at com.liferay.mobile.android.http.Response.checkPortalException(Response.java:98)
at com.liferay.mobile.android.http.Response.getBody(Response.java:49)
at com.liferay.mobile.android.callback.BaseCallback.inBackground(BaseCallback.java:56)
at com.liferay.mobile.android.http.client.OkHttpClientImpl$1.onResponse(OkHttpClientImpl.java:192)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:170)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
</code></pre><br><br>This is my code:<br><br><pre><code>
@Override
public void onDDLFormLoaded(Record record) {
_loaded = true;
if (record != null) {
// set default reply values
Map<string, object> values = new HashMap<string, object>();
values.put("toUserId", Long.toString(_recUserId));
values.put("subject", _recSubject);
values.put("_threadId", Long.toString(_recThreadId));
record.setValues(values);
_screenlet.onDDLFormRecordLoaded(record);
}
}
@Override
public void onDDLFormRecordLoaded(Record record) {
// do nothing
}
</string,></string,></code></pre><br><br>I tried to follow the trace to pinpoint the cause but got lost..<br><br>Any suggestions how to fix this?<br><br>Best,<br>Arne<br><br><br><div class="quote-title">Javier Gamarra:</div><blockquote>Sorry, I forgot you are on 1.4 or master... it should be something like this:<br><br><pre><code>
Map<string, object> values = new HashMap&lt;&gt;();
values.put("Title", "TESTING");
record.setValues(values);
_screenlet.onDDLFormRecordLoaded(record);
</string,></code></pre></blockquote></body></html>Arne Leeman2016-10-15T09:54:45ZRE: Populate DDLFormScreenlet fields programmaticallyJavier Gamarrahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=802863652016-09-30T14:31:13Z2016-09-30T14:31:13Z<html><head></head><body>Sorry, I forgot you are on 1.4 or master... it should be something like this:<br><br><pre><code>
Map<string, object> values = new HashMap&lt;&gt;();
values.put("Title", "TESTING");
record.setValues(values);
_screenlet.onDDLFormRecordLoaded(record);
</string,></code></pre></body></html>Javier Gamarra2016-09-30T14:31:13ZRE: Populate DDLFormScreenlet fields programmaticallyArne Leemanhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=802164762016-09-29T14:07:28Z2016-09-29T14:07:28Z<html><head></head><body>Hi Javier,<br><br>I'm sorry to say that your first solution doesn't work: onDDLFormRecordLoaded only takes 1 argument of type Record..<br>(haven't tried the second yet)<br><br>This is what I did:<br><br><pre><code>
@Override
public void onDDLFormLoaded(Record record) {
_loaded = true;
Map<string, object> modelValues = new HashMap&lt;&gt;();
modelValues.put("toUserId", Long.toString(_recUserId));
modelValues.put("subject", _recSubject);
modelValues.put("_threadId", Long.toString(_recThreadId));
Map<string, object> data = new HashMap&lt;&gt;();
data.put("modelValues", modelValues);
_screenlet.onDDLFormRecordLoaded(record, data);
/*
if ((record != null) &amp;&amp; !_recSetDef) {
_recSetDef = true;
// set default reply data
Map<string, object> data = new HashMap<string, object>();
data.put("toUserId", Long.toString(_recUserId));
data.put("subject", _recSubject);
data.put("_threadId", Long.toString(_recThreadId));
record.setValues(data);
_screenlet.setRecord(record);
}
*/
}
</string,></string,></string,></string,></code></pre><br><br>Could you please be more specific about the necessary coding?<br><br><br>*** quoting ***<br><br><div class="quote-title">Javier Gamarra:</div><blockquote>We are inheriting part of the structure of the data in the portal, so you should write something like this:<br><br><pre><code>
@Override
public void onDDLFormLoaded(Record record) {
loaded = true;
Map<string, object> data = new HashMap&lt;&gt;();
Map<string, object> modelValues = new HashMap&lt;&gt;();
data.put("modelValues", modelValues);
modelValues.put("TextBoxeuwq", "1");
screenlet.onDDLFormRecordLoaded(record, data);
info("Form loaded!");
}
</string,></string,></code></pre><br><br>The data for the record is stored in the "modelValues" key.<br><br>If you don't mind coupling with the UI (you should) you could also fill the values retrieving the fields directly with findViewById / Children.</blockquote></body></html>Arne Leeman2016-09-29T14:07:28ZRE: Populate DDLFormScreenlet fields programmaticallyArne Leemanhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=801741922016-09-28T21:01:58Z2016-09-28T21:01:58ZRight, I'll have a go at it.<br /><br />Thanks again,<br />ArneArne Leeman2016-09-28T21:01:58ZRE: Populate DDLFormScreenlet fields programmaticallyJavier Gamarrahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=801605942016-09-28T16:47:47Z2016-09-28T16:47:47ZUhm... this is way brittler:<br /><br />((DDLFieldTextView) ((LinearLayout) findViewById(R.id.ddlfields_container)).getChildAt(0))<br /><br />That way you can access the rendered views and either change the underline value or the edittext itself.Javier Gamarra2016-09-28T16:47:47ZRE: Populate DDLFormScreenlet fields programmaticallyArne Leemanhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=801216992016-09-28T04:51:32Z2016-09-28T04:51:32ZHi Javier,<br /><br />Thanks for your swift reply, this is usefull.<br /><br />I wouldn't mind going with the UI option, as it would allow me to not show specific fields in the form - control values for the server - as well.<br /> Could you maybe point me to snippets for this? I couldn't find any..<br /><br />Best, ArneArne Leeman2016-09-28T04:51:32ZRE: Populate DDLFormScreenlet fields programmaticallyJavier Gamarrahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=801053382016-09-27T20:19:37Z2016-09-27T20:19:37Z<html><head></head><body>We are inheriting part of the structure of the data in the portal, so you should write something like this:<br><br><pre><code>
@Override
public void onDDLFormLoaded(Record record) {
loaded = true;
Map<string, object> data = new HashMap&lt;&gt;();
Map<string, object> modelValues = new HashMap&lt;&gt;();
data.put("modelValues", modelValues);
modelValues.put("TextBoxeuwq", "1");
screenlet.onDDLFormRecordLoaded(record, data);
info("Form loaded!");
}
</string,></string,></code></pre><br><br>The data for the record is stored in the "modelValues" key.<br><br>If you don't mind coupling with the UI (you should) you could also fill the values retrieving the fields directly with findViewById / Children.</body></html>Javier Gamarra2016-09-27T20:19:37ZPopulate DDLFormScreenlet fields programmaticallyArne Leemanhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=800831402016-09-27T14:17:41Z2016-09-27T14:17:41ZHi there,<br /><br />Is there a way to set default field values in a DDLFormScreenlet besides default values defined in the structure?<br /><br />My usecase is replying to an entry (news message) from a DDLlistScreenlet.<br />I pass the default reply data as extra's in the intent used to start the reply activity<br />The reply activity contains a DDLFormScreenlet with no recordId specified.<br /><br />I tried to update the