简体   繁体   English

将值从MenuItemTag传递到.jsp

[英]Passing a value from MenuItemTag to .jsp

Situation: 情况:

I have a .jsp with a Menu and MenuItems, which is being displayed on every other .jsp in the app. 我有一个带菜单和MenuItems的.jsp文件,它正在应用程序中的其他所有.jsp文件中显示。 Three of those MenuItems, at this point in time, each redirect the user to a different .jsp page. 此时,其中的三个MenuItem分别将用户重定向到不同的.jsp页面。 But that is silly because those .jsp's AND the Action classes are almost identical. 但这很愚蠢,因为那些.jsp的AND Action类几乎相同。 So what I want to do is: 所以我想做的是:

  • make these 3 different menuitems/links redirect to the same page 使这3个不同的菜单项/链接重定向到同一页面
  • send a parameter with when clicking on a link/MenuItem 单击链接/ MenuItem时发送参数
  • depending on the value of 'mode': 取决于'mode'的值:
    • change the .jsp's layout 更改.jsp的布局
    • change the values of variables in the onPostPrintx-actions in the Action class 更改Action类的onPostPrintx-actions中的变量值

Code: 码:

JSP-page with code for the Menu Widget : 带有菜单小部件代码的JSP页面:

...
<ui:submenu name="Chapter A">
    <ui:menuitem link="/ThisPage.do">Printoption A</ui:menuitem>
    <ui:menuitem link="/ThisPage.do">Printoption B</ui:menuitem>
    <ui:menuitem link="/ThisPage.do">Printoption C</ui:menuitem>
    ...
</ui:submenu> 
<ui:submenu name="Chapter B">
    ...
</ui:submenu>
...

JSP-page with the print-buttons ('ThisPage') : 带有打印按钮的JSP页面('ThisPage')

<html>
<div>
...
<c:set var="mode" value="${PageData.fields.mode}" />
<c:set var="title" value="${val:iif(mode=='1','Option1',val:iif(mode=='2','Option2','Option3'))}" />
...
<body>
    <html-el:form action="/Print" method="post" >
    <h1>Print ${title}</h1>
    <html-el:hidden property="field(mode)"/>
...
(assorted fields to filter output data)
...
        <html-el:submit property="event(printPdf)" styleClass="button" style="width=125">Print to .PDF</html-el:submit>
    <c:if test="${(mode=='3')}">
        <html-el:submit property="event(printWord)" styleClass="button" style="width=125">Print to .DOC</html-el:submit>
    </c:if>
...
</div>
</body>
</html>

Action class ('Print') : 动作类(“打印”)

...
public ActionForward onPostPrintPdf(ActionMapping mapping, ActionForm form, 
            HttpServletRequest request, HttpServletResponse response) 
            throws Exception 
{
    ...
    request.setCharacterEncoding("UTF-8");
    Connection connection = null;
    PageData inForm = ActionUtils.getInputForm(mapping, request, form);
    String mode = (String)inForm.getField("mode");
    ...
    (assorted variables, field/variable validation, export to Jasper Report, etc.)
    ...
    return ActionUtils.getInputRedirect(mapping, request, inForm);
}
...
(more actions for more printing options)
...

What I am struggling with: 我正在努力的是:

I am pretty new to Struts (and java) and I have set up everything (within my knowledge) to 'receive' the parameter value and put it in the 'mode' variable. 我对Struts(和Java)还很陌生,我已经设置了一切(据我所知)以“接收”参数值并将其放在“ mode”变量中。 But I'm struggling with 'sending' the value because I can't use things like 'onclick' in the MenuItems. 但是我一直在努力“发送”值,因为我不能在MenuItems中使用“ onclick”之类的东西。

At this point I really don't know how to pass a value to 'mode' when clicking on one of the MenuItems. 此时,我真的不知道如何在单击MenuItems之一时将值传递给“ mode”。

Thanks to Jimmy for leading me in the right direction! 感谢吉米带领我朝着正确的方向前进! Here is the solution that works with my code: 这是适用于我的代码的解决方案:

...
<ui:submenu name="Chapter A">
    <ui:menuitem link="/ThisPage.do?field(mode)=optionA">Printoption A</ui:menuitem>
    <ui:menuitem link="/ThisPage.do?field(mode)=optionB">Printoption B</ui:menuitem>
    <ui:menuitem link="/ThisPage.do?field(mode)=optionC">Printoption C</ui:menuitem>
    ...
</ui:submenu> 
<ui:submenu name="Chapter B">
    ...
</ui:submenu>
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM