Update struts2 action built into JSP

Well, I will try to make it as short and easy to follow as possible.

I use the full jQuery calendar and show events for the user. I have a “Filter” action on the page that allows me to filter events displayed based on different criteria. One of these criteria is the name of the event. The ultimate goal is to make the filter reload the selected "Event Name" options from full-screen viewing.

Everything works for me, but it is not synchronized.

My JSP to enable the filter is as follows:

<div id="popUpFilterInfo" class="filterPopUp"> <s:action name="ScheduleFilter" executeResult="true" id="scheduleFilter"></s:action> </div> 

This returns another JSP page that includes a filter form. Struts is executed during page rendering, so this filter is created before the view is created. This filter is then hidden / displayed using jQuery when the user selects a button.

The page action is different from the filter action, since this filter action must be included in several pages.

After loading the full calendar, it sends its dates back to the page action, which stores these dates in the filter object in the global context for the application.

The problem I am facing is that I cannot make the page reload only the filter when the view changes. If I reload the entire page, then the filter really contains data from the previous view, so I know that I just need to tell the page about the re-rendering of the ScheduleFilter form. I tried to do this using jQuery like this:

 var filter = "<s:action name=\"ScheduleFilter\" executeResult=\"true\" id=\"scheduleFilter\"></s:action>"; jQuery('#popUpFilterInfo').children().remove(); jQuery('#popUpFilterInfo').append(filter); 

This throws a JasperException, which refers to the "quote character" on the line where the Variable filter is instantiated. right in the middle of 'name', the pointing character 'm' is a problem.

Does anyone know how to reload an inline action like this without reloading the entire page?

ANSWER

As Dave said below, do not insert an action with the <s:action> . I switched this, and instead I call the action using Ajax, and after success, then I use jQuery to insert the returned data into my form div form. I set a check to see if the div is empty or not, and clear the div if it already has a filter. Example below

My filter div:

 <div id="popUpFilterInfo" class="filterPopUp"></div> 

Act:

 function loadFilter() { if(!jQuery('#popUpFilterInfo').is(':empty')){ jQuery('#popUpFilterInfo').children().remove(); } jQuery.ajax({ url:'Filter.action', data:"", dataType: "", type: "GET", success: function(filter) { jQuery('#popUpFilterInfo').append(filter); } }); } 
+4
source share
1 answer

On behalf of @ Nathan24, I am posting this answer.

As Dave said below, do not embed the action with the tag. I switched this, and instead I call the action using Ajax, and after success, then I use jQuery to insert the returned data into my form div form. I set a check to see if the div is empty or not, and clear the div if it already has a filter. Example below

My filter div:

 <div id="popUpFilterInfo" class="filterPopUp"></div> 

Act:

 function loadFilter() { if(!jQuery('#popUpFilterInfo').is(':empty')){ jQuery('#popUpFilterInfo').children().remove(); } jQuery.ajax({ url:'Filter.action', data:"", dataType: "", type: "GET", success: function(filter) { jQuery('#popUpFilterInfo').append(filter); } }); } 

I thought this might be useful for some other posts, such as an answer so people don’t miss this question. If I am wrong, let me know that I will delete this answer. Thanks.

+1
source

All Articles