dispalay tag table pass value to requestURI

2019-06-13 20:05发布

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条回答
啃猪蹄的小仙女
2楼-- · 2019-06-13 20:43

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>
查看更多
登录 后发表回答