Expand my Community achievements bar.

How to pass input field values in to java ?

Avatar

Level 1

I have designed one page using HTL . my page components contains one input text field and button. how  i can pass my text field values in to java class.

Here is my HTL code .

<sly data-sly-use.clientlib="/libs/granite/sightly/templates/clientlib.html" data-sly-call="${clientlib.all @ categories='s7.s7dataset.style'}"/>

<div data-sly-use.s7dataset="com.dam.service.Info">

<header id="header" class="hoc clear">

<form class="search foundation-form granite-omnisearch-form">

<input class="searchTerm" placeholder="search scene7 ..." /> <input

class="searchButton" type="submit" />

</form>

</header>

Here is my java code:

-------------------

package  com.dam.service

public class Info extends WCMUsePojo {

  @Override

    public void activate() throws Exception {

    

  }

}

I am not sure that can i use WCMUsePojo or not . anybody help me to get value in to java .?

3 Replies

Avatar

Level 2

You can set the form method to "GET" and use this getRequest().getParameter("id") to get the values from the input fields.

Avatar

Community Advisor

HI,

You can pass value from HTL to java like below:

HTL

<div data-sly-use.cf="${'com.aem.community.core.components.ContentFragmentContent' @ cfInput=properties.cfdata, variation=properties.variation},cfMode='some mode'">

Java

public void activate() {

  String cfInput = get("cfInput", String.class);

String cfVariation = get("cfVar", String.class);

String mode = get("cfMode", String.class);

But In your case you can't pass value from client side to Java Use API.

But value can be pass when form is submitted and value can be fetched at action page/servlet/jsp etc.



Arun Patidar

Avatar

Level 10

When using HTL - to get values to Java, you can either use:

1 - a component dialog - Creating an Adobe Experience Manager 6.4 HTL component that uses the WCMUsePojo API

2 - or use a HTTP POST or GET operation - this would be sent to a servlet however.

In your form use case - you can use AJAX to sent the values to a Java Servlet - you cannot pass that to WCMUSEPojo as that happens when the dialog is filled out.