Add String values to ArrayList<String> field from Guided Rules

1,794 views
Skip to first unread message

AV

unread,
Nov 20, 2017, 10:42:06 AM11/20/17
to Drools Usage
Hi,

I have an object Student and which has a field Subjects which is of type private ArrayList<String>,

public class Student implements ... {
..............
...............
private ArrayList<String> subjects
..........
............
}


I need to add subjects (which is an arraylist of type String) under the Student object from a guided rule but all I get in a guided rule is a text box for literal value.

I am trying to avoid free form DRL. I tried the change and modify options for the student object in the action part but they give the same text box to put a literal value which fails during compilation.

Has anyone tried to add String values to an ArrayList of String type from a Guided rule?

Thanks,
AV

Michael Anstis

unread,
Nov 21, 2017, 10:00:19 AM11/21/17
to Drools Usage
If you bind the subjects field to a variable; you can call a method on the List to add either a literal or bound String.



rule "r2"
dialect "mvel"
when
$hl : HasList( $subjects : subjects != null )
$s : String( )
then
$subjects.add( $s );
end



--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/2856f6e8-604b-4999-a379-d41cb84b3117%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

AV

unread,
Nov 28, 2017, 4:38:19 PM11/28/17
to Drools Usage
Hi Michael,

This is what I was looking for. Thanks a ton for your help.

Is there a way I can assign populate subjects arraylist which is under the object student from a guided decision table.

I added a method called addSubjects to the java POJO I am using. Now when i add an action column and select the action to call a method on Student, it shows addSubjects and option for the String but after I click String, I have to put a value for the subject placeholder which is then applicable for all the rows in the decision table however, I need to assign different subjects from different rows which ever applicable. Is there a way to do it?


Thanks,
AV
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages