I making a sort of action called ProfileSelector, that is loaded trought some ajax call (by using JQuery library).
我创建了一种名为ProfileSelector的操作,它被加载到一些ajax调用(通过使用JQuery库)。
This is the code :
这是代码:
// BEAN
public class ProfileSelector extends ActionSupport implements ParameterAware {
private String profilePage;
private Map<String, String[]> parameters;
@Override
public String execute() throws Exception {
profilePage=getParameterValue("profilePage");
return profilePage;
}
public String getParameterValue(String param) {
if (getParameters().get(param)==null) return "main";
return ((String[])getParameters().get(param))[0];
}
public Map<String, String[]> getParameters() { return parameters; }
public void setParameters(Map<String, String[]> maps) { this.parameters=maps; }
public String getProfilePage() { return profilePage; }
public void setProfilePage(String profilePage) { this.profilePage=profilePage; }
}
// STRUTS.XML
<action name="profile" class="model.ProfileSelector" >
<result name="main">/profile/profile_main.jsp</result>
<result name="edit">/profile/profile_edit.jsp</result>
<result name="editConfirm">/profile/profile_edit.jsp</result>
<result name="pm">/profile/profile_pm.jsp</result>
<result name="articles">/profile/profile_articles.jsp</result>
</action>
// PAGE.JSP
<c:choose>
<c:when test="${profilePage=='edit'}">
<s:div>
EDIT
<s:url id="edit" action="profile.action"><s:param name="profilePage">editConfirm</s:param></s:url>
<sj:submit href="%{edit}" targets="profileContent" value="Edit" />
</s:div>
</c:when>
<c:when test="${profilePage=='editConfirm'}">
// HERE I NEED TO LOAD A VALUE FROM ANOTHER BEAN-ACTION, not the profile one
</c:when>
</c:choose>
Looks (in the code) at HERE I NEED TO LOAD A VALUE FROM ANOTHER BEAN-ACTION, not the profile one : is here that i need to load (for example) a method from another Action-Bean. (example <s:property value="someMethod" />
在这里(在代码中),我需要从另一个BEAN-ACTION加载一个值,而不是配置文件1:是否需要从另一个action bean加载一个方法(例如)。(例如< s:属性值= " someMethod " / >
How can I do it? I think is impossible with Struts, because I can call only 1 action at time. So, Interceptors? I need to change my whole structure of the application?
我怎么做呢?我认为使用Struts是不可能的,因为我一次只能调用一个动作。所以,拦截器?我需要改变整个应用程序的结构?
Let me know. Cheers
让我知道。干杯
2 个解决方案
#1
2
// BEAN
/ /豆
public class ListBookAction extends ActionSupport {
BookService bookService;
List<Book> bookList;
public List<Book> getPostedBooks(){
List<Book> bookList = new ArrayList<Book>();
bookList = bookService.getUserPostedBooks();
return bookList;
}
public String show(){
bookList = getPostedBooks();
return "list";
}
public List<Book> getBookList() {
return bookList;
}
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
}
//STRUTS.XML
/ / STRUTS.XML
<action name="*ListBook" class="com.example.ListBookAction" method="{1}">
<result name="list" type="tiles-defs">listbook.listbook</result>
</action>
//From browser
/ /从浏览器
http://localhost:8888/showListBook.action
P.S: If you familiar with Struts 1, it work like DispatchAction.
P。S:如果你熟悉Struts 1,它的工作原理就像DispatchAction。
#2
1
There is something incorrect as you never want to goto 2 different actions for anything. There is no way to do so. However, you might be able to make an ajax call from the jsp and point to different action and load the value out.
有些事情是不正确的,因为你永远都不想为了任何事情去做两种不同的行为。没有办法这么做。但是,您可能可以从jsp发出ajax调用并指向不同的操作并将值加载出去。
#1
2
// BEAN
/ /豆
public class ListBookAction extends ActionSupport {
BookService bookService;
List<Book> bookList;
public List<Book> getPostedBooks(){
List<Book> bookList = new ArrayList<Book>();
bookList = bookService.getUserPostedBooks();
return bookList;
}
public String show(){
bookList = getPostedBooks();
return "list";
}
public List<Book> getBookList() {
return bookList;
}
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
}
//STRUTS.XML
/ / STRUTS.XML
<action name="*ListBook" class="com.example.ListBookAction" method="{1}">
<result name="list" type="tiles-defs">listbook.listbook</result>
</action>
//From browser
/ /从浏览器
http://localhost:8888/showListBook.action
P.S: If you familiar with Struts 1, it work like DispatchAction.
P。S:如果你熟悉Struts 1,它的工作原理就像DispatchAction。
#2
1
There is something incorrect as you never want to goto 2 different actions for anything. There is no way to do so. However, you might be able to make an ajax call from the jsp and point to different action and load the value out.
有些事情是不正确的,因为你永远都不想为了任何事情去做两种不同的行为。没有办法这么做。但是,您可能可以从jsp发出ajax调用并指向不同的操作并将值加载出去。