简体   繁体   中英

How to pass form input value on submit to sightly as a parameter to WCMUsePojo

I am wondering if we have any method to pass the form input value to sightly as in the below code "@ matnumb=' Material Number from form on submit '" I tried this to pass the param to WCMUsePojo activate method as below...

----------------------------------
String matNum = get("matNum", String.class);
----------------------------------

<section>
    <form method="#" id="matNumber">
        <input type="text" name="matNum" id="matNum" placeholder="Enter Number...">
        <input type="button" value="Submit" class="fa fa-search" name="submit" id="submit">
    </form>
</section>
<div data-sly-use.info="${'com.org.core.components.MatNumberWcmUse' @ matnumb='**Material Number from form on submit**'}">
    <p>${show more data about product}</p>
</div>

Is there any method to pass this input value directly to sightly so that i can avoid unnecessary servlet coding to just pass this variable. thanks

If you don't want to go with ajax way, you can change the form method to GET and action to the actual path, then you should be able to read this parameter in the WCMUsePojo model from the request:

<section>
    <form method="GET" id="matNumber" action="some/path">
        <input type="text" name="matNum" id="matNum" placeholder="Enter Number...">
        <input type="button" value="Submit" class="fa fa-search" name="submit" id="submit">
    </form>
</section>
<div data-sly-use.info="${'com.org.core.components.MatNumberWcmUse'}">
    <p>${show more data about product}</p>
</div>

Then in model: getRequest().getParameter("matNum");

I guess this is only id of product and it is expected to appears in url. Remember about server side input validation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM