PDA

View Full Version : Button woes



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&#58; No bean specified
at org.apache.commons.beanutils.PropertyUtilsBean.get PropertyDescriptor&#40;PropertyUtilsBean.java&#58;751&#41;
at org.apache.commons.beanutils.BeanUtilsBean.setProp erty&#40;BeanUtilsBean.java&#58;937&#41;
at org.apache.commons.beanutils.BeanUtilsBean.populat e&#40;BeanUtilsBean.java&#58;811&#41;
at org.apache.commons.beanutils.BeanUtils.populate&#40;Be anUtils.java&#58;298&#41;
at org.apache.struts.util.RequestUtils.populate&#40;Reque stUtils.java&#58;495&#41;
at org.apache.struts.action.RequestProcessor.processP opulate&#40;RequestProcessor.java&#58;798&#41;
at org.apache.struts.action.RequestProcessor.process&#40; RequestProcessor.java&#58;205&#41;
at org.apache.struts.action.ActionServlet.process&#40;Act ionServlet.java&#58;1164&#41;
at org.apache.struts.action.ActionServlet.doPost&#40;Acti onServlet.java&#58;415&#41;
at javax.servlet.http.HttpServlet.service&#40;HttpServlet .java&#58;709&#41;
at javax.servlet.http.HttpServlet.service&#40;HttpServlet .java&#58;802&#41;
...

(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&#58;forEach var="curBlock" items="$&#123;allBlocks&#125;" varStatus="curStatus">
...
<input type="submit" name="_eventId_editBlock_$&#123;curStatus.index&#125;" value="edit"/>
<input type="submit" name="_eventId_deleteBlock_$&#123;curStatus.index&#125;" value="delete"/>
</c&#58;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="$&#123;#result.startsWith&#40;'editBlock'&#41;&#125;" to="prepareEditBlock"/>
<transition on="$&#123;#result.startsWith&#40;'deleteBlock'&#41;&#125;" 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&#40;&#41;.getId&#40;&#41;;
Integer idx = new Integer&#40;id.substring&#40;id.lastIndexOf&#40;'_'&#41; + 1&#41;&#41;;

return result&#40;SUCCESS_EVENT_ID, "idx", idx&#41;;

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&#58;forEach var="curBlock" items="$&#123;allBlocks&#125;" varStatus="curStatus">
...
<input type="submit" name="_eventId_editBlock.idx=$&#123;curStatus.index&#125;" value="edit"/>
<input type="submit" name="_eventId_deleteBlock.idx=$&#123;curStatus.index&#125;" value="delete"/>
</c&#58;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

Keith Donald
Jul 22nd, 2005, 12:59 AM
Tom,

I like those ideas.

We'll take a look at this tommorrow, and get some tests going for image button and submit button event parsing.

Keith

klr8
Jul 22nd, 2005, 03:28 PM
1) Keith is testing this as we speek, looks like it could be a Struts issue.

2) We don't provide this kind of thing, where you're encoding multiple parameters in a single HTTP request parameter out of the box. However, it is simple to plug it in: Just subclass ServletFlowExecutionManager, overwrite the createEvent() method and have it return a custom ServletEvent subclass that does all the special parameter parsing you want. Then all there's left to do is configure your FlowAction (or FlowController) with this custom flow execution manager using setFlowExecutionManager().

Erwin

Keith Donald
Jul 22nd, 2005, 10:14 PM
I've reproduced this issue with image buttons and Struts. The problem is indeed Struts specific and has to do with use of the SpringBindingActionForm and nested form properties (e.g _eventId_submit.x treated as a property path).

I've let Juergen know about this.

Someone mentioned you could use a custom request processor to short circuit form population for action forms that are instanceof SpringBindingActionForm adapters. That's a valid workaround until we have a fix here.

I'm optimistic Juergen will be able to quickly get to the bottom of this issue.

Keith

Keith Donald
Jul 23rd, 2005, 07:35 AM
Yes, Juergen has resolved this for Spring 1.2.3.

So you'll need Spring 1.2.3 (due out Sunday evening) and PR5 (due out shortly thereafter) for this fix.

Keith