Thomas Dudziak
Jul 21st, 2005, 06:08 PM
I have trouble getting two somewhat related scenarios with multiple buttons on a form to get to work.
(1) The first one is with image buttons. If I define the button as a normal one:
<input type="submit" name="_eventId_addBlock" value="add" align="top" border="0"/>
then it works as expected giving me the ability to transition on it:
<view-state id="showStep2" view="step2">
<transition on="addBlock" to="prepareAddBlock"/>
<transition on="cancel" to="finish"/>
<transition on="save" to="saveBlocks"/>
</view-state>
However if I change it to be an image button:
<input type="image" name="_eventId_addBlock" src="images/button_add.gif" align="top" border="0"/>
it doesn't work any longer:
java.lang.IllegalArgumentException: No bean specified
at org.apache.commons.beanutils.PropertyUtilsBean.get PropertyDescriptor(PropertyUtilsBean.java:751)
at org.apache.commons.beanutils.BeanUtilsBean.setProp erty(BeanUtilsBean.java:937)
at org.apache.commons.beanutils.BeanUtilsBean.populat e(BeanUtilsBean.java:811)
at org.apache.commons.beanutils.BeanUtils.populate(Be anUtils.java:298)
at org.apache.struts.util.RequestUtils.populate(Reque stUtils.java:495)
at org.apache.struts.action.RequestProcessor.processP opulate(RequestProcessor.java:798)
at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:205)
at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
...
(and it doesn't work either when using "_mapped_eventId_addBlock"). What do I do wrong here (using current CVS version) ?
(2) The second thing is that I require indexed buttons (actually image buttons but for the sake of the discussion I'll leave them as normal ones) for instance like so:
<c:forEach var="curBlock" items="${allBlocks}" varStatus="curStatus">
...
<input type="submit" name="_eventId_editBlock_${curStatus.index}" value="edit"/>
<input type="submit" name="_eventId_deleteBlock_${curStatus.index}" value="delete"/>
</c:forEach>
But how can I transition on them, eg. to an action that handles all edit request, or to one that handles all delete requests ? My naive thinking brought me to something likes this:
<view-state id="showStep2" view="step2">
<transition on="addBlock" to="prepareAddBlock"/>
<transition on="${#result.startsWith('editBlock')}" to="prepareEditBlock"/>
<transition on="${#result.startsWith('deleteBlock')}" to="performDeleteBlock"/>
<transition on="cancel" to="finish"/>
<transition on="save" to="saveBlocks"/>
</view-state>
which works. But how do I get the index into the action ? I can read it out in the target action like this:
String id = context.getSourceEvent().getId();
Integer idx = new Integer(id.substring(id.lastIndexOf('_') + 1));
return result(SUCCESS_EVENT_ID, "idx", idx);
which I then eg. can access in the next action using getLastEvent().getParameter("idx").
But this is rather complicated. Would it perhaps be possible to have something like:
<c:forEach var="curBlock" items="${allBlocks}" varStatus="curStatus">
...
<input type="submit" name="_eventId_editBlock.idx=${curStatus.index}" value="edit"/>
<input type="submit" name="_eventId_deleteBlock.idx=${curStatus.index}" value="delete"/>
</c:forEach>
(note the dots instead of the underlines; if I try this right now, I get an exception much like the above one for the image button)
If the things after the dot would be put somehow into parameters automatically (eg. "editBlock.idx"), this would make it possible to retrieve the index, and even the position where the user clicked on an image button (eg. "addBlock.x", "addBlock.y" parameters). WDYT ?
regards,
Tom
(1) The first one is with image buttons. If I define the button as a normal one:
<input type="submit" name="_eventId_addBlock" value="add" align="top" border="0"/>
then it works as expected giving me the ability to transition on it:
<view-state id="showStep2" view="step2">
<transition on="addBlock" to="prepareAddBlock"/>
<transition on="cancel" to="finish"/>
<transition on="save" to="saveBlocks"/>
</view-state>
However if I change it to be an image button:
<input type="image" name="_eventId_addBlock" src="images/button_add.gif" align="top" border="0"/>
it doesn't work any longer:
java.lang.IllegalArgumentException: No bean specified
at org.apache.commons.beanutils.PropertyUtilsBean.get PropertyDescriptor(PropertyUtilsBean.java:751)
at org.apache.commons.beanutils.BeanUtilsBean.setProp erty(BeanUtilsBean.java:937)
at org.apache.commons.beanutils.BeanUtilsBean.populat e(BeanUtilsBean.java:811)
at org.apache.commons.beanutils.BeanUtils.populate(Be anUtils.java:298)
at org.apache.struts.util.RequestUtils.populate(Reque stUtils.java:495)
at org.apache.struts.action.RequestProcessor.processP opulate(RequestProcessor.java:798)
at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:205)
at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
...
(and it doesn't work either when using "_mapped_eventId_addBlock"). What do I do wrong here (using current CVS version) ?
(2) The second thing is that I require indexed buttons (actually image buttons but for the sake of the discussion I'll leave them as normal ones) for instance like so:
<c:forEach var="curBlock" items="${allBlocks}" varStatus="curStatus">
...
<input type="submit" name="_eventId_editBlock_${curStatus.index}" value="edit"/>
<input type="submit" name="_eventId_deleteBlock_${curStatus.index}" value="delete"/>
</c:forEach>
But how can I transition on them, eg. to an action that handles all edit request, or to one that handles all delete requests ? My naive thinking brought me to something likes this:
<view-state id="showStep2" view="step2">
<transition on="addBlock" to="prepareAddBlock"/>
<transition on="${#result.startsWith('editBlock')}" to="prepareEditBlock"/>
<transition on="${#result.startsWith('deleteBlock')}" to="performDeleteBlock"/>
<transition on="cancel" to="finish"/>
<transition on="save" to="saveBlocks"/>
</view-state>
which works. But how do I get the index into the action ? I can read it out in the target action like this:
String id = context.getSourceEvent().getId();
Integer idx = new Integer(id.substring(id.lastIndexOf('_') + 1));
return result(SUCCESS_EVENT_ID, "idx", idx);
which I then eg. can access in the next action using getLastEvent().getParameter("idx").
But this is rather complicated. Would it perhaps be possible to have something like:
<c:forEach var="curBlock" items="${allBlocks}" varStatus="curStatus">
...
<input type="submit" name="_eventId_editBlock.idx=${curStatus.index}" value="edit"/>
<input type="submit" name="_eventId_deleteBlock.idx=${curStatus.index}" value="delete"/>
</c:forEach>
(note the dots instead of the underlines; if I try this right now, I get an exception much like the above one for the image button)
If the things after the dot would be put somehow into parameters automatically (eg. "editBlock.idx"), this would make it possible to retrieve the index, and even the position where the user clicked on an image button (eg. "addBlock.x", "addBlock.y" parameters). WDYT ?
regards,
Tom