Forums de discussion

get value from Client side to sever Side

Sofia Lucas, modifié il y a 9 années.

get value from Client side to sever Side

New Member Publications: 13 Date d'inscription: 12/06/14 Publications récentes
Hello,

I created a select input and I need to get it's value to use it in java method , this is the form I created :

<aui:form action="" method="post" onsubmit="" name="fm1">
....
</aui:form>


I dnt know if it's right or should I add portlet parameter or use AJAX ...
I use liferay 6.2

thank you
thumbnail
Manali Lalaji, modifié il y a 9 années.

RE: get value from Client side to sever Side

Expert Publications: 362 Date d'inscription: 09/03/10 Publications récentes
Hi Sofia,

If you have something like below:
<aui:form action="" method="post" onSubmit="" name="fm1">
.......
<aui:select inlineField="true" inlineLabel="right" label="" name="portletType" id="portlet-type">
<aui:option value="Other" selected="true">Other</aui:option>
<aui:option value="Highlights" >Highlights</aui:option>
</aui:select/>
.. ....
</aui:form>

You can fetch its value in class like below after form submit:

String portletType = ParamUtil.getString(aActionRequest, "portletType");

Is that what you require or something else?

HTH!
Sofia Lucas, modifié il y a 9 années.

RE: get value from Client side to sever Side

New Member Publications: 13 Date d'inscription: 12/06/14 Publications récentes
Hi , thank you for replying so soon.

I need to get the value of the select chosen every time it's changed ..
the Id of the select can I change it or i should use the same as u said

thanks
thumbnail
Manali Lalaji, modifié il y a 9 années.

RE: get value from Client side to sever Side

Expert Publications: 362 Date d'inscription: 09/03/10 Publications récentes
Hi ,

You can go with above approach as I mentioned. Id should not be changed. You get selected value in your java class as above.

HTH!
Sofia Lucas, modifié il y a 9 années.

RE: get value from Client side to sever Side

New Member Publications: 13 Date d'inscription: 12/06/14 Publications récentes
Ok I use exactly what you posted :

  <aui:form action="" method="post" onsubmit="" name="fm1">
   <aui:select inlinefield="true" inlinelabel="left" label="Test" name="portletType" id="portlet-type">
    <aui:option label="-- Choice  --" value="0" selected="true" />
    <aui:option label="1" value="1" />
    <aui:option label="2" value="2" />
    </aui:select>
  </aui:form>
  <span>&lt;%=ParamUtil.getString(request, "portletType")%&gt;</span>



and It returns nothing the span is empty !

thank you..
thumbnail
Manali Lalaji, modifié il y a 9 années.

RE: get value from Client side to sever Side

Expert Publications: 362 Date d'inscription: 09/03/10 Publications récentes
Hi,

You want this value in java class or jsp where you are creating this aui:select ?
After form submit you shall get selected option value in your processAction of Java class.
Sofia Lucas, modifié il y a 9 années.

RE: get value from Client side to sever Side

New Member Publications: 13 Date d'inscription: 12/06/14 Publications récentes
Hi,
No I want it in the same jsp file ... even If i submit it doesnt display
thank you
thumbnail
Manali Lalaji, modifié il y a 9 années.

RE: get value from Client side to sever Side

Expert Publications: 362 Date d'inscription: 09/03/10 Publications récentes
Hi,

On server side as I mentioned, you can do : String portletType = ParamUtil.getString(aActionRequest, "portletType");

On client side for onchange event, you can get via javascript:

A.one("#<portlet:namespace/>portlet-type").on("change", function(){
alert(this.val();
)};

HTH!