Im using displaytable with tiles. Problem is in my crud application, when I search something its loading data into display table,
and when I click on 2nd page its load data to 2nd page as I give requestURI="searchorgs". All works fine upto that,
Then I call Edit template and after submitting edited data it should load data to table. Its also work fine but when I click 2nd page
Its goes to search page as I mention in requestURI="searchorgs". I need to keep in same page with out moving to search page. Same table is insert in to add,edit,search jsp pages in tiles.xml. I dont want to define 3 separate tables for this.
Application I struts2 tiles integration one.
action class search method :
public String search() {
organisationSearch = new OrganisationSearch();
organisationSearch.setAoName(aoName);
orglist = orgBo.searchOrg(organisationSearch);
return "search";
}
Struts xml :
<action name="*orgs" class="com.ast.action.admin.OraganisationAction"
method="{1}">
<result name="add" type="tiles">orgAddTemplate</result>
<result name="search" type="tiles">orgTemplate</result>
<result name="delete" type="tiles">orgTemplate</result>
<result name="edit" type="tiles">orgEditTemplate</result>
<r
</action>
table :
<s:form theme="simple" id="delete" action="deleteorgs">
<display:table id="studentTable" name="orglist" pagesize="5" cellpadding="5px;" id="row" cellspacing="5px;"
style="margin-left:50px;margin-top:20px;" requestURI="searchorgs">
<display:column style="width:5px;">
<s:checkbox name="chkBox" id="check%{#attr.row_rowNum - 1}" value="%{#attr.row.chkBox}" fieldValue="%{#attr.row.aoId}" />
</display:column>
<display:column title="Action" style="width:10px;" value="Edit" href="vieweditorgs" paramId="aoId" paramProperty="aoId" />
<display:column title="View" style="width:10px;" value="View" href="vieworgs" paramId="aoId" paramProperty="aoId" />
<display:column title="Dlt" style="width:10px;" value="Dlt" href="singledeleteorgs" paramId="aoId" paramProperty="aoId" />
<display:column property="aoId" title="ID" />
<display:column property="aoName" title="Name" />
</display:table>
You need to define action in requesturi programmatically.
Please see this
dispalay tag table pass value to requestURI
In action class
private String myActionName;
public String search() {
organisationSearch = new OrganisationSearch();
organisationSearch.setAoName(aoName);
orglist = orgBo.searchOrg(organisationSearch);
//set action name
myActionName="action1.action";
return "search";
}
//other methods
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 I misunderstood your question, Please let me know.
Related
I'm using Struts2 (version 2.5.14.1) with the Spring and Tiles plug-ins.
This is my (relevant) struts.xml configuration:
<package name="enrollment" namespace="/enrollment" extends="struts-bean-validation">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="start" class="io.shido.struts.action.enrollment.StartAction">
<result name="success" type="tiles">enrollment.start.tiles</result>
</action>
<action name="personal-info" class="io.shido.struts.action.enrollment.PersonalInfoAction">
<result name="input" type="tiles">enrollment.personal-info.tiles</result>
<result name="success" type="tiles">enrollment.billing-info.tiles</result>
</action>
<action name="billing-info" class="io.shido.struts.action.enrollment.BillingInfoAction">
<result name="input" type="tiles">enrollment.billing-info.tiles</result>
<result name="success" type="tiles">enrollment.finish.tiles</result>
</action>
<action name="finish" class="io.shido.struts.action.enrollment.FinishAction">
<result name="success" type="tiles">enrollment.finish.tiles</result>
</action>
</package>
...the JSP file that holds one of the forms:
<%# taglib prefix="s" uri="/struts-tags" %>
<link rel="stylesheet" href="<s:url value='/resources/styles/enrollment.styles.css' />">
<s:form cssClass="form-input-info" action="personal-info" method="post">
<legend><s:text name="legend.text" /></legend>
<hr>
<s:textfield cssClass="form-control" key="textfield.first-name" name="personalInfo.firstName" />
<s:textfield cssClass="form-control" key="textfield.last-name" name="personalInfo.lastName" />
<s:textfield cssClass="form-control" key="textfield.email" name="personalInfo.email" />
<s:textfield cssClass="form-control" key="textfield.phone-number" name="personalInfo.phoneNumber" />
<s:textfield cssClass="form-control" key="textfield.age" name="personalInfo.age" />
<s:submit class="btn btn-primary btn-lg btn-block" key="submit.continue" />
</s:form>
...and finally the (super simple) Action class:
package io.shido.struts.action.enrollment;
// imports
public final class PersonalInfoAction extends ActionSupport {
private static final long serialVersionUID = 3560814234131884357L;
private final Logger logger = LogManager.getLogger(this.getClass());
private PersonalInfoHandler handler;
#Valid
private PersonalInfo personalInfo;
#Override
public String execute() {
// If personalInfo is not null is guaranteed to be valid due to Bean Validation contraints
if (null != personalInfo) {
logger.debug("Processing personal info...");
handler.save(personalInfo);
return Action.SUCCESS;
}
logger.info("Collecting personal info...");
return Action.INPUT;
}
public PersonalInfoHandler getHandler() { return handler; }
public void setHandler(final PersonalInfoHandler handler) { this.handler = handler; }
public PersonalInfo getPersonalInfo() { return personalInfo; }
public void setPersonalInfo(final PersonalInfo personalInfo) {
this.personalInfo = personalInfo;
this.personalInfo.normalize();
}
}
The issue is, whenever I submit that form, I'm expecting the Bean Validation to kick out and check all the annotated fields (check, this is happening) and when everything is fine, send the flow to /WEB-INF/content/enrollment/billing-info.jsp (defined in Tiles by enrollment.billing-info.tiles)...but all I see is (almost) the "billing info" form with the wrong labels. See the below picture:
The URL should have changed, as well as the labels. To put the cherry on top, if I click the Continue button again, the form is displayed then correctly.
Any clues?
I have no direct answer but you could try to use a redirect action instead of using the tiles several times.
So you could try this here:
<action name="personal-info" class="io.shido.struts.action.enrollment.PersonalInfoAction">
<result name="input" type="tiles">enrollment.personal-info.tiles</result>
<result name="success" type="redirectAction">
<param name="actionName">billing-info</param>
</result>
</action>
And if you need to transfer some kind of id to show the data you can use additional params in the struts.xml like this:
<!-- rest as above -->
<result>
<param name="param1">${value1}</param>
</result>
The param1 must have valid getter/setter-methods in both actions to transfer the information.
I'm trying to set parameter value bulkID from form in ftl file to action class, but unable to set. Following is the code:
struts.xml file
<action name="bulk" class="com.action.BulkChangeMainAction">
<result name="input" type="freemarker">/resources/templates/bulk-changes.ftl</result>
</action>
BulkChangeMainAction.java
public class BulkChangeMainAction {
private int bulkID;
public int getBulkID() {
return bulkID;
}
public void setBulkID(int bulkID) {
this.bulkID = bulkID;
}
public String input() {
return INPUT;
}
}
bulk-changes.ftl
<form id='filter-form' action="<#s.url action='bulk' method='input'/>" method="post" name="filterForm">
<input type="text" id="bulkID" name="bulkID"/>
<input type="submit" value="Go"/>
</form>
Try using the struts2 form tag and sth like the following (I assume input is the action you want to call?):
<s:form action="bulk.input.action" method="post">
<s:textfield name="bulkId" label="Bulk Id" />
<s:submit value="Confirm" />
</s:form>
Here is a nice complete example too:
http://www.codejava.net/frameworks/struts/handling-form-data-in-struts2
if you need to keep the current format you have, please try changing int to String or Integer and see if it works.
I have a search box on my index page, it is supposed to return a message if no result was found or redirect to result page if it succeeded.
Currently, if results were found it redirects to the new page, and if not will stay on the same page (index) but it does not show the message, just add the mymessage parameter to the page address as following
www.address.com/index.jsp?mymessage=Sorry,No+results+were+found.
Index
.......
<s:property value="mymessage"/>
SearchBox
public String search(){
....
if(found)
return "success";
else
return "failed;
}
struts.xml
<package name="Search" extends="default" namespace="/Search">
<action name="*" method="{1}" class="com.myproject.myclasses.Search">
<result name="success" type="tiles">search</result>
<result name="failed" type="redirectAction">
<param name="actionName">index</param>
<param name="namespace">/</param>
<param name="mymessage">${mymessage}</param>
</result>
</action>
</package>
I think <s:property> expects a getter getMyMessage() on your action class to populate
values can you try <s:property value="#request.mymessage" />
OR
Why can't you use action errors?
public String search(){
....
if(found) {
return "success";
}
else {
addActionError("No results found");
return "failed;
}
}
Now in the index.jsp add the following,
<s:if test="hasActionErrors()">
<s:iterator value="actionErrors">
<s:property escape="false"/>
</s:iterator>
</s:if>
I created a jsp page which has a form , I am trying to populate the data members of the action classfrom this form, after submitting the form the control is being moved to the action class but the action class data members are not populated.
my jsp page looks like this.
<s:actionerror />
<s:form action = "retrieve" method="post">
<s:textfield name = "form1" value = "form1" />
<s:textfield name="cid"/>
<s:submit type = "submit" name = "sub" value="submit"/>
</s:form>
my action class looks like this.
public class CustomerUpdate extends ActionSupport {
private String form1 ;
private String cid ;
public String execute() {
System.out.println(form1) ;
System.out.println(cid) ;
}
Here after submission of form I expect form1 variable in action class should have the value as "form1" but it is still null.
can anyone help where am I going wrong?
Thanks in advance.....
I am not sure if you have configuration file that maps action class to your jsp file.
normally configuration file is an xml file in your src folder. example:
<struts>
<package name="default" extends="struts-default">
<action name="retrieve" class="CustomerUpdate">
<result>/xxx.jsp</result>
</action>
</package>
</struts>
Since your execute method is of return type string, return some string. Based on string returned from execute method you can redirect. otherwise change it to void.
If you already have properly configured action class with your jsp, then for using member variables, code in jsp might look like:
<form action = "retrieve" method="post">
<s:textfield name = "form1" value = "${form1}" />
<s:textfield name="${cid}"/>
<s:submit type = "submit" name = "sub" value="submit"/>
</form>
and also since member variable are private:
system.out.println(getForm1);
system.out.println(getCid);
Hope that helps
At first place, your code will not compile.
As i assume that struts.xml file contains below lines,
<action name="retrieve" class="CustomerUpdate" method="execute">
<result name="success">/success.jsp</result>
</action>
Update the CustomerUpdate as below and check the program.
public class CustomerUpdate extends ActionSupport {
private String form1 ;
private String cid ;
public String execute() {
System.out.println(form1) ;
System.out.println(cid) ;
return "success";
}
//getter & setter for form1 & cid
}
please try out the above code sample and i think it will work.
Hi i want to populate the select drop down list with some value. I use Struts 2, Tiles and JSP. I initialize my list in the Action class but i am still getting the following error :
Caused by: tag 'select', field 'list', name 'anneeResultat': The requested list key 'anneesResultatsList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
Here is my code in Action class:
private AnneeResultat anneeResultat;
private Map<String, String> anneesResultatsList = new HashMap<String, String>();
public Map<String,String> getAnneesResultatsList() {
this.anneesResultatsList.put("2005","2005");
this.anneesResultatsList.put("2006","2006");
this.anneesResultatsList.put("2007","2007");
this.anneesResultatsList.put("2008","2008");
this.anneesResultatsList.put("2009","2009");
this.anneesResultatsList.put("2010","2010");
this.anneesResultatsList.put("2011","2011");
return this.anneesResultatsList;
}
public void setAnneesResultatsList(Map<String,String> anneesResultatsList) {
this.anneesResultatsList = anneesResultatsList;
}
return SUCCESS;
}
My struts.xml file contains :
<action name="ChoixAxes" class="fr.si2m.occ.web.actions.ChoixAxesAction"
method="execute">
<result type="tiles">choixAxes.tiles</result>
</action>
My jsp is here:
<s:set name="theme" value="'xhtml'" scope="page" />
<s:form action="ChoisirAxes" name="choices" id="choices">
<s:select name="anneeResultat" label="Année de résultats" list="anneesResultatsList"></s:select>
<s:radio label="Listes nominatives" name="listesNominatives" list="#{'1':'Oui','2':'Non'}" value="2" />
<s:submit value="Calculer provisions" name="calculerProvisions"/>
<s:reset value="Annuler" />
<input type="button" value="Critères sauvegardés" id="criteresSauvegardes"/>
</s:form>
Some one could help me please ?
I have this problem since yersterday.
Prepare interceptor calls prepare() on actions which implement
Preparable. This interceptor is very useful for any situation where
you need to ensure some logic runs before the actual execute method
runs.
Your action should extend Preparable interceptor and override prepare() method, give the pre populated data.
Struts2 Prepare Interceptor
Put AnneesResultatsList in session
Map session=ActionContext.getScession();session.put("list",AnneesResultatsList );
<pre>
s:select name="anneeResultat" label="Année de résultats" list="%{#session.list}""></s:select>
</pre>
actually it is,
Map session = ActionContext.getcontext().getsession();
session.put("key",list);
<s:select list="%{#session.key}">