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

被刻印的时光 ゝ 提交于 2019-12-08 10:59:53

问题


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:div 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.


回答1:


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




回答2:


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!!



来源:https://stackoverflow.com/questions/7750679/cannot-find-a-way-to-pass-a-hidden-value-to-the-action-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!