06-01-2018 05:52 AM
Hi,
I want to create drop down menu , as i created succesfully but i want user to select on one drop down menu and depending on selected item from drop down menu one , drop down menu 2 items populated.
Current problem is:
suppose there are two category “Animals” and “Vehicles”, and Sub categories are “CAT”,“DOG”,“BUS”,“CAR” , so right now issue is whatever i select in category it will display all four sub categories but now i want show sub category depending on Category selection.
code snippet right now is:
@General(title = "XYZ Parser", purpose = "Parse XYZ file", author = "NeosAlpha", docLink = "http://neosalpha.com/")
@Outputs(min = 1, max = 1, offers = ViewType.DOCUMENT)
@Errors(min = 1, max = 1, offers = ViewType.DOCUMENT)
@Version(snap = 1)
@Category(snap = SnapCategory.PARSE)
public class XYZParser extends SimpleBinaryWriteSnap implements DependencyManager {
private static final String FILE_BROWSER_PROP = "file_browser_prop";
private static final String XYZ_TYPE_PROP = "XYZ_type_prop";
private static final String XYZ_TYPE_PROP_VALUE = "Animals";
private static final String FILE_TYPE_PROP = "file_type_prop";
private static final String FILE_TYPE_PROP_VALUE = "Vehicles";
private String filePath;
@Inject
private DocumentUtility documentUtility;
@Inject
private URLEncoder urlEncoder;
@Inject
private JfsUtils jfsUtils;
String fileBrowser;
String filetype;
String XYZtype;
Map<String, Object> composite;
@Override
public Module getManagedModule() {
return new AbstractModule() {
@Override
protected void configure() {
bind(ForEx.class).to(ForExImpl.class);
bind(JfsUtils.class).toInstance(JfsUtils.getInstance());
}
};
}
// An optional file selector for providing exchange rates within a file
@Override
public void defineProperties(PropertyBuilder propertyBuilder) {
Set<String> XYZ_set = new HashSet<String>();
XYZ_set.add("");
XYZ_set.add("Animals");
XYZ_set.add("Vehicles");
Set<String> file_set = new HashSet<String>();
file_set.add("");
file_set.add("CAT");
file_set.add("CAR");
file_set.add("DOG");
file_set.add("BUS");
propertyBuilder.describe(XYZ_TYPE_PROP, "XYZ Type",
"Write XYZ ")
.withAllowedValues(XYZ_set)
.required()
.add();
propertyBuilder.describe(FILE_TYPE_PROP, "File Type",
"Write File type ")
.withAllowedValues(file_set)
.required()
.add();
}
@Override
public void configure(PropertyValues propertyValues) throws ConfigurationException {
filetype = propertyValues.getAsExpression(FILE_TYPE_PROP).eval(null);
XYZtype = propertyValues.getAsExpression(XYZ_TYPE_PROP).eval(null);
}
@Override
public void cleanup() throws ExecutionException {
// TODO Auto-generated method stub
}
@Override
protected void process(final Document document, final ReadableByteChannel readChannel) {
try (InputStream inputStream = Channels.newInputStream(readChannel)) {
if(filetype.contentEquals("Animals") && XYZtype.contentEquals("CAT"))
{
} else {
// PUT ERROR CODE HERE
}
}
else if(filetype.contentEquals("Vehicles") && XYZtype.contentEquals("BUS") )
{
}
else {
// Error Code Here
}
} catch (IOException e) {
errorViews.write(new SnapDataException(e, e.getMessage()), document);
} finally {
}
outputViews.write(documentUtility.newDocument(data),document);
}
}
What i want is given below:
For example firstly i select category which are “Animals” or “Vehicles”.
Suppose if i select Animals from category dropdown menu then in next dropdown only selections are shown is “CAT” or “DOG”
Suppose if i select Vehicles from category drop down menu then in next drop down only selections are shown is “BUS” or “CAR”
Just give me code snippet i ll do the rest.
Thanks
Nikhil Purohit
06-01-2018 08:59 AM
Hi there,
Looks like you’re attempting to put all possible subcategory selections into one drop down menu, and then hide certain ones. That could get tricky. You may want to do something more UI-tricky, and create two sub category drop down lists. One with animals, and one with cars. The default subcategory can be shown, if you default the main category to say…animals, and then if you make the main category selection, you can hide/unhide the other drop downs accordingly. That may do the trick, but then you have to be careful in your handling code, to key on the enums that you pull out of the subcategory based on the main category. I think the trickiest part here would be the hiding and unhiding of fields.
Make sure that if you go this route, that both dropdown menus are the same size and placement, otherwise the UI might look meh, if you have components on the Snap popping in and out of view, and skewing the placement of other UI components.
Thanks,
-Charlie