You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by jr...@ups.com on 2007/06/20 23:46:26 UTC

Updating a Map of data

I am trying to write a page that views and updates values from MBeans.
My Action class has a method that exposes a Map of MBean client objects
which mostly contain properties from the MBean. I am using the
Preparable interface where the prepare() method populates the map. The
view portion is working fine. All values including the checkbox, labels
and text boxes are populating correctly. The problem is with the update
portion of the functionality. I am expecting the params interceptor to
make calls like getInboundBridges.get('key1').setMaxAttempts from the
OGNL expression in the textbox name field of
"inboundBridges['key1'].maxAttempts" when I submit my form. During the
update form submission, the map already exists from the prepare() method
but the setters are never called. I did have this working once using
List instead of Map and was using the index of the List for the update.
The problem with this approach is there is no guarantees that the List
created in the prepare() method would be the same one between view and
update, so the indexes may not match anymore. I tried to solve this by
using the KeyProperty feature in a type convertor but could not get it
working. I have then switched to the Map approach which is at least
working on the view side. Any ideas why this is happening? 

My action is defined like this:

	<package name="default" namespace="/" extends="struts-default">

		<action name="ServiceSummary"
class="serviceSummaryAction" method="execute">
			<result>/serviceSummary.jsp</result>
		</action>
		<action name="UpdateServiceAction"
class="serviceSummaryAction" method="update">
			<result>/serviceSummary.jsp</result>
		</action>
	</package>


The getter for the action class looks like this:

public Map<String, MqMessageBridgeClient> getInboundBridges() {
	return this.inboundBridges;
}


The snippet from the JSP that deals with populating the view with a
checkbox and a couple of textboxes looks like this:

<s:form theme="simple" action="UpdateServiceAction" method="post">
...
<s:iterator value="inboundBridges.keys" status="stat" id="key">
	<tr>
		<td align="center" nowrap="nowrap">
			<s:checkbox theme="simple"
name="inboundBridges['%{#key}'].active"/>
		</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].name"/>&nbsp;</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].location"/>&nbsp;</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].bridgeDescription"/>&nbsp;</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].initialState"/>&nbsp;</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].bridgeDestinationName"/>&nbsp;</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].connectionFactoryName"/>&nbsp;</td>
		<td nowrap="nowrap"><s:textfield
name="inboundBridges['%{#key}'].maxAttempts" size="4"/></td>
		<td nowrap="nowrap"><s:textfield
name="inboundBridges['%{#key}'].retryDelay" size="6"/></td>
	</tr>
</s:iterator>
...
<s:submit theme="simple" value="Update"/>
</s:form>

This is a snippet of the actual HTML source that is being rendered:

<form id="UpdateServiceAction" name="UpdateServiceAction"
onsubmit="return true;"
action="/struts2.demo/UpdateServiceAction.action" method="post">
...
<input type="checkbox" name="inboundBridges['key1'].active" value="true"
checked="checked"
id="UpdateServiceAction_inboundBridges_'key1'__active"/>
<input type="hidden" name="__checkbox_inboundBridges['key1'].active"
value="true"/>
</td>
<td nowrap="nowrap">TestBridge&nbsp;</td>
<td nowrap="nowrap">AdminServer&nbsp;</td>
<td nowrap="nowrap">Test Bridge&nbsp;</td>
<td nowrap="nowrap">MANAGED&nbsp;</td>
<td nowrap="nowrap">aid.test.jms.mq.TestInboundMq&nbsp;</td>
<td
nowrap="nowrap">aid.ail.jms.connectionfactory.TestMqConnectionFactory&nb
sp;</td>
<td nowrap="nowrap"><input type="text"
name="inboundBridges['key1'].maxAttempts" size="4" value="3"
id="UpdateServiceAction_inboundBridges_'key1'__maxAttempts"/>
</td>
<td nowrap="nowrap"><input type="text"
name="inboundBridges['key1'].retryDelay" size="6" value="5000"
id="UpdateServiceAction_inboundBridges_'key1'__retryDelay"/>
...
<input type="submit" id="UpdateServiceAction_1" value="Update"/>
</form>

Thanks for any help,

Jeff


RE: Updating a Map of data

Posted by jr...@ups.com.
I figured this one out. The key I was using was actually the canonical
name of the MBean which contains some punctuation. This must have been
causing some problems with the params interceptor being able to properly
process the request.

Jeff

-----Original Message-----
From: Talley Jeff (air2jrt) 
Sent: Wednesday, June 20, 2007 5:46 PM
To: user@struts.apache.org
Subject: Updating a Map of data

I am trying to write a page that views and updates values from MBeans.
My Action class has a method that exposes a Map of MBean client objects
which mostly contain properties from the MBean. I am using the
Preparable interface where the prepare() method populates the map. The
view portion is working fine. All values including the checkbox, labels
and text boxes are populating correctly. The problem is with the update
portion of the functionality. I am expecting the params interceptor to
make calls like getInboundBridges.get('key1').setMaxAttempts from the
OGNL expression in the textbox name field of
"inboundBridges['key1'].maxAttempts" when I submit my form. During the
update form submission, the map already exists from the prepare() method
but the setters are never called. I did have this working once using
List instead of Map and was using the index of the List for the update.
The problem with this approach is there is no guarantees that the List
created in the prepare() method would be the same one between view and
update, so the indexes may not match anymore. I tried to solve this by
using the KeyProperty feature in a type convertor but could not get it
working. I have then switched to the Map approach which is at least
working on the view side. Any ideas why this is happening? 

My action is defined like this:

	<package name="default" namespace="/" extends="struts-default">

		<action name="ServiceSummary"
class="serviceSummaryAction" method="execute">
			<result>/serviceSummary.jsp</result>
		</action>
		<action name="UpdateServiceAction"
class="serviceSummaryAction" method="update">
			<result>/serviceSummary.jsp</result>
		</action>
	</package>


The getter for the action class looks like this:

public Map<String, MqMessageBridgeClient> getInboundBridges() {
	return this.inboundBridges;
}


The snippet from the JSP that deals with populating the view with a
checkbox and a couple of textboxes looks like this:

<s:form theme="simple" action="UpdateServiceAction" method="post"> ...
<s:iterator value="inboundBridges.keys" status="stat" id="key">
	<tr>
		<td align="center" nowrap="nowrap">
			<s:checkbox theme="simple"
name="inboundBridges['%{#key}'].active"/>
		</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].name"/>&nbsp;</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].location"/>&nbsp;</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].bridgeDescription"/>&nbsp;</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].initialState"/>&nbsp;</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].bridgeDestinationName"/>&nbsp;</td>
		<td nowrap="nowrap"><s:property
value="inboundBridges[#key].connectionFactoryName"/>&nbsp;</td>
		<td nowrap="nowrap"><s:textfield
name="inboundBridges['%{#key}'].maxAttempts" size="4"/></td>
		<td nowrap="nowrap"><s:textfield
name="inboundBridges['%{#key}'].retryDelay" size="6"/></td>
	</tr>
</s:iterator>
...
<s:submit theme="simple" value="Update"/> </s:form>

This is a snippet of the actual HTML source that is being rendered:

<form id="UpdateServiceAction" name="UpdateServiceAction"
onsubmit="return true;"
action="/struts2.demo/UpdateServiceAction.action" method="post"> ...
<input type="checkbox" name="inboundBridges['key1'].active" value="true"
checked="checked"
id="UpdateServiceAction_inboundBridges_'key1'__active"/>
<input type="hidden" name="__checkbox_inboundBridges['key1'].active"
value="true"/>
</td>
<td nowrap="nowrap">TestBridge&nbsp;</td>
<td nowrap="nowrap">AdminServer&nbsp;</td>
<td nowrap="nowrap">Test Bridge&nbsp;</td> <td
nowrap="nowrap">MANAGED&nbsp;</td>
<td nowrap="nowrap">aid.test.jms.mq.TestInboundMq&nbsp;</td>
<td
nowrap="nowrap">aid.ail.jms.connectionfactory.TestMqConnectionFactory&nb
sp;</td>
<td nowrap="nowrap"><input type="text"
name="inboundBridges['key1'].maxAttempts" size="4" value="3"
id="UpdateServiceAction_inboundBridges_'key1'__maxAttempts"/>
</td>
<td nowrap="nowrap"><input type="text"
name="inboundBridges['key1'].retryDelay" size="6" value="5000"
id="UpdateServiceAction_inboundBridges_'key1'__retryDelay"/>
...
<input type="submit" id="UpdateServiceAction_1" value="Update"/> </form>

Thanks for any help,

Jeff


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org