Hello Community!
I have a question about Multifield variables.
Previous post, I could make Multifield on my dialog with tutorial (Creating an AEM HTML Template Language 6.3 component that uses a Multifield )
Now, I'm lost track of how to get those variable via JS-use API.
I have following structure in my multifield
multifield
field
layout
items
column
items
text
id
in my js file (subMenu.js)
in the html
as test variables I have following set up
So I was expected to obtain JSON object that contain both text and id.
I tried one from js api and the other uses properties.<propertiy_name>
However, neither of them return blank.
I think it should be similar to retrieving regular form variable.
so I assume properties.get() method or some similar method should obtain the object . (but I'm still learning AEM development so I might wrong)
If you know how to get those variables, Please help me solve this
Thank you for your time!
Ryu
Views
Replies
Total Likes
Using Java is a better approach for this use case - why are you trying to use JavaScript when WCMUsePojo is a much better way to proceed when reading values that an AEM author entered into a Multifield?
Using Java - you can use Object-Oriented Programming techniques that let you set objects as you read the MF values.
Views
Replies
Total Likes
This method in Java lets you read the values in the MF and set a List that is read in HTL
private
List<TouchMultiBean> setMultiFieldItems() {
@SuppressWarnings
(
"deprecation"
)
JSONObject jObj;
try
{
String[] itemsProps = getProperties().get(
"myUserSubmenu"
, String[].
class
);
if
(itemsProps ==
null
) {
LOGGER.info(
"PROPS IS NULL"
) ;
}
if
(itemsProps !=
null
) {
for
(
int
i =
0
; i < itemsProps.length; i++) {
jObj =
new
JSONObject(itemsProps[i]);
TouchMultiBean menuItem =
new
TouchMultiBean();
String title = jObj.getString(
"title"
);
String link = jObj.getString(
"link"
);
String flag = jObj.getString(
"flag"
);
menuItem.setTitle(title);
menuItem.setLink(link);
menuItem.setFlag(flag);
submenuItems.add(menuItem);
}
}
}
catch
(Exception e){
LOGGER.error(
"Exception while Multifield data {}"
, e.getMessage(), e);
}
return
submenuItems;
}
Views
Replies
Total Likes
Thank you @smacdonald2008
I thought JS-USE API and Java API are doing the same thing.
I just curious, our project has done by JS-USE API, Is it okay to mix with Java and JS API ?
Also I noticed that crx de does not quite handle Java well. so is that mean I need to set up Eclipse ?
Ryu
Views
Replies
Total Likes
Yeah - do not write Java in CRXDE - bad idea - use Eclipse.
Never mix up WCMUSEPOJO and JS API. I recommend using either Sling Models or WCMUsePojo for HTL compnent development.
Now not all HTL components even need a Java backend. You can read the dialog values from HTL directly - see this:
Scott's Digital Community: Creating a custom Image Text component for Experience Manager 6.3
This component was created without using Java at all.
However - when using HTL - you should know how to use Java and compile it and deploy to AEM as an OSGi bundle. See this article and you can watch the video that shows you everything to get this Getting Started HTL component up and running:
Views
Replies
Total Likes
Got it!
I will install Eclipse and Let's see what happen!
Thank you smacdonald2008 and Ratna Kumar!
Views
Replies
Total Likes
Go through the other article too that I listed.
Views
Replies
Total Likes
No, You cannot Java and JS API... You need to use Eclipse to create Java class that extends WCMUSEPojo.
Creating an AEM HTML Template Language 6.3 component that uses a Multifield
~Ratna.
Views
Replies
Total Likes
Yes, I agree with Scott..Please use Java for creating Multifields. Java is the best way to create using WCMUsePojo.
~Ratna
Views
Replies
Total Likes
Getting multifield data without using use Api. Getting data in Jquery:https://aemsimplifiedbynikhil.wordpress.com/2018/07/29/multifield-and-dialog-data-in-jquery/
Multifield and Dialog data in Jquery | AEM 6.3 + – AEM Queries & Solutions
Views
Replies
Total Likes
Views
Like
Replies
Views
Likes
Replies