dispalay tag table pass value to requestURI

假如想象 提交于 2019-12-08 12:06:12

问题


How do I set value to requestURI by action class in Struts2 or another form. I need to change value of requestURI according to tile.


回答1:


Option 1: Pass value from action (Better way)

In yourAction.java

  private String myActionName;
  public String execute() {
        myActionName="action1.action";
        return SUCCESS;
  }
  public void setMyActionName(String myActionName) {
        this.myActionName = myActionName;
  }

  public String getMyActionName() {
        return myActionName;
  }

In jsp file

  <display:table id="u" name="userlist"  pagesize="10"   requestURI="${myActionName}" >
  ...
  </display:table>

If you want to pass your own parameter in url

  <s:url action="%{myActionName}" var="requrl" >
        <s:param name="myparam">myvalue1</s:param>
  </s:url>
  <display:table id="u" name="userlist"  pagesize="10"   requestURI="${requrl}" >
  ...
  </display:table>

Option 2: Pass value from tile (Not Recommanded)

In tiles.xml

  <definition name="baseLayout" template="/BaseLayout.jsp">
        <put-attribute name="title" value="" type="string"  />
        <put-attribute name="header" value="/Header.jsp" />
        <put-attribute name="menu" value="/Menu.jsp" />
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/Footer.jsp" />
        <put-attribute name="myattribute" value="" type="string"  />
  </definition>

  <definition name="/welcome.tiles" extends="baseLayout">
        <put-attribute name="title" value="Welcome" type="string" />
        <put-attribute name="body" value="/Welcome.jsp" />
        <put-attribute name="myActionName" cascade="true" value="tileAction1.action"  />
  </definition>

Note: Use proper tiles version and tiles.xml dtd to use cascade="true".

In welcome.jsp

  <tiles:useAttribute name="myActionName" />
  <display:table id="u" name="userlist"  pagesize="10"   requestURI="${myActionName}" >
  ...
  </display:table>


来源:https://stackoverflow.com/questions/24203035/dispalay-tag-table-pass-value-to-requesturi

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