Reputation: 255
I'm trying to write a simple calculator portlet and I have problem with passing value of one of the buttons to my portlet. There's part of my .jsp:
<portlet:actionURL var = "digit" name = "onDigitPressed">
<portlet:param name="jspPage" value = "/html/calc/view.jsp"/>
</portlet:actionURL>
<aui:form action="<%= digit %>" method="post" >
<table>
<tr><td>
<aui:button name="button" type = "submit" value="7" id="7"/>
</td><td>
<aui:button name="button" type = "submit" value="8" id="8" /> </td><td>
<aui:button name="button" type = "submit" value="9" id="9"/> </td><td>
</tr><tr><td>
.
.//more buttons
.
</tr><tr><td>
<aui:button name="button" type = "submit" value="0" id="0" /> </td><td>
<aui:button name="button" type = "submit" value="." id="." /> </td><td>
</td>
</tr>
</table>
</aui:form>
and in onDigitPressed
method:
request.getParameter("button");//returns always null
I want to pass value of the button somehow and I want to have only one actionURL to deal with all these buttons. And it would be good to have only one form too. There must be some way, but I have no idea how to do this, I'm new in portlets and JSP.
EDIT
My explanation of problem isn't very clear - I want to pass value of clicked button. I need that information to know what user wants to compute. Sure I can just spam with actionURL
s and form
s, but I want to do this with one form and actionURL. I bet it has something to do with onClick
attribute and I'm pretty sure I can't use javascript, because it has to be done on server side and javascript is executed on client side.
Upvotes: 0
Views: 2043
Reputation: 3133
What you need to do, is include an input field or portlet:param
node that will have a 'digit' specific value
Your problem is that an aui:button
of type 'submit', is meant to be used as the button that submits a form, so all your buttons will fire the same actionURL. the one stated in the attribute named 'action' of aui:form
I can see at least 3 solutions:
actionURL
for each button, with a unique 'digit' param. This would be a nice idea if your form doesn't feature other params/inputs, and if your forms are created by some iteration like a for loopUpvotes: 0
Reputation: 976
you can do it using java script.
Javascript code:
var button1 = document.getElementById("button1").value;
var button2 = document.getElementById("button2").value;
document.formName.button1 .value = button1 ;
document.formName.button2.value = button2;
document.formName.submit();
In JSP:
<aui:button type = "submit" value="1" id="button1"/>
<aui:button type = "submit" value="2" id="button2"/>
<input type="hidden" name="button_1" />
<input type="hidden" name="button_2" />
In Java:
String button_1= ParamUtil.getString(request, "button_1");
String button_2= ParamUtil.getString(request, "button_2");
Upvotes: 3