开发者

Cannot find a way to pass a hidden value to the action file

开发者 https://www.devze.com 2023-04-12 21:54 出处:网络
Situation: I have two dojo autocompleters on a jsp. Both of them trigger the same action when their value is changed. Now I want that in the action file I should know which autocompleter was changed.

Situation:

I have two dojo autocompleters on a jsp. Both of them trigger the same action when their value is changed. Now I want that in the action file I should know which autocompleter was changed.

What I have done:

Normally, in such a situation I would call a javascript to change the value of a hidden field and then access the value of that hidden field in the action file to know which was changed. But I call the javascript using the "onChange" attribute which (unfortunately) does not work for "autocompleter". I had to use "valueNotifyTopics" for calling the action.

Here is the code:

<s:url id="scriptURL" action="viewContactInfo" />
<sd:di开发者_如何学Gov href="%{scriptURL}" listenTopics="viewContactInfo" formId="contactInfo" showLoadingText="false" preload="false">
<s:form id="contactInfo">
    <sd:autocompleter autoComplete="false" name="customer" list="customerList" valueNotifyTopics="viewContactInfo"/> 
    <sd:autocompleter autoComplete="false" name="contact"  list="contactList" valueNotifyTopics="viewContactInfo"/>
    <s:hidden id="chngd" value="initial"/>
</s:form>
</sd:div>

I was hoping to use something like this:

onchange="dojo.byId('chngd').value='some value'; dojo.event.topic.publish('viewContactInfo');"

instead of

valueNotifyTopics="viewContactInfo"

Please advise some way of getting around the situation I have mentioned.

Thanks!!

In case I missed out any required information please leave a comment.


Looks like you are missing the name-attribute for #chngd (only fields with a name-attribute will be submitted)


I had figured this out a while back, but am posting this answer now, for anyone still in trouble:

In the jsp do this:

<sd:autocompleter autoComplete="false" name="customer" list="customerList" valueNotifyTopics="topic"/> 

Then in javascript do this:

dojo.event.topic.subscribe("topic", function(){
    dojo.byId('chngd').value='some value';
    dojo.event.topic.publish('getLists');
});

This way, when the value of a dojo autocompleter is changed, you can set the value of a hidden field before your action is called. For that matter you can do a whole lot more, because this is like, you are doing this --> onclick="topic()" .

Hope this helps!!

0

精彩评论

暂无评论...
验证码 换一张
取 消