I have a form open in Struts2 jquery dialog box. When users submit this form, i want to show the Server Side error message (eg. Username exist,Please choose another) on this same open dialoguebox itself .
How can i do this? Any hint or suggestion! Please share.
index.jsp (on click of a button the below form will open)
`<s:actionerror/>
<s:form action="testError" id="form3" theme="simple"/>
<s:textfield name="quantity" value="1""/>
<s:form>
<sj:submit formId="form3" value="true"/>`
Action.java
public String execute()
{
addActionError("Error message is blah blah");
return ERROR;
}
Struts.xml
<action name="testError" class="com.Action">
<result name="error">index.jsp</result>
</action>
try this:
<s:if test="hasErrors()">
<sj:dialog title="error message">
<s:actionerror/>
</sj:dialog>
</s:if>
I have a grid which load data on page load.
I also have a form that on submit calls an action correctly, but it doesn't load new data on my grid.
List is correctly geting and also correctly setting in my grid model From my Action class but while on return SUCCESS it simply returns data in this form(see below output)...
{"authFirstname":null,"authLastname":null,"bookDetailsobj":null,"bookTitile":null,"get":{"authFirstname":null,"authLastname":null,"bookTitile":null,"coverId":null,"createdDate":null,"createrId":null,"description":null,"editionId":null,"editionYear":null,"id":null,"img1":null,"img2":null,"isbn":null,"languageId":null,"locationId":null,"price":null,"publisherName":null,"quantity":null,"remarks":null,"subjectId":null,"updateId":null,"updatedDate":null,"videoUrl":null},"gridModel":[{"authFirstname":"234234","authLastname":"2323423","bookTitile":"23324234234","coverId":"soft cover","description":"243234","editionId":"General Edition","editionYear":"234234","id":42,"img1":"","img2":"","isbn":"324234","languageId":"English","locationId":"as","price":2.34234E7,"publisherName":"234234","quantity":234234,"remarks":"","subjectId":"General Fiction","videoUrl":""},{"authFirstname":"2423","authLastname":"23423","bookTitile":"asdfsdaf","coverId":"soft cover","description":"","editionId":"General Edition","editionYear":"2","id":39,"img1":"","img2":"","isbn":"2","languageId":"English","locationId":"as","price":234.0,"publisherName":"2","quantity":2,"remarks":"","subjectId":"General Fiction","videoUrl":""},{"authFirstname":"3","authLastname":"3","bookTitile":"232","coverId":"soft cover","description":"","editionId":"General"}
My jsp code:
<sjg:grid
id="getLogs"
dataType="json"
href="%{getCurrentDateLogs}"
gridModel="listOfLogs"
onSelectRowTopics="rowselect"
loadonce="true"
reloadTopics="reloadGrid"
formIds="form2"
>
<sjg:gridColumn name="userid" index="userid" title="User ID" sortable="true" align="center"/>
<sjg:gridColumn name="username" index="username" title="Username" sortable="true"/>
<sjg:gridColumn name="logaction" index="logaction" width="600" title="Action" sortable="true"/>
<sjg:gridColumn name="date" index="date" title="Date" sortable="true" sorttype="date" align="center"/>
<sjg:gridColumn name="time" index="time" title="Time" sortable="true" sorttype="time" align="center"/>
</sjg:grid>
<s:form action="getLogsByDates" id="form2" theme="simple" cssClass="yform">
<table class="">
<tr><td>from:</td>
<td><sj:datepicker value="yesterday" id="from" name="startDate" displayFormat="dd/mm/yy" label="from" /></td>
</tr>
<tr><td>to:</td>
<td><sj:datepicker value="today" id="to" name="endDate" displayFormat="dd/mm/yy" label="to" /></td>
</tr>
<tr><td colspan="2">
<sj:submit
value="Search"
button="true"
onClickTopics="reloadGrid"
indicator="indicator"
/>
</td></tr>
</table>
</s:form>
struts.xml
<action name="getLogsByDates" class="v.esoft.actions.bookdetails.BookdetailsAction" >
<result name="success" type="json"/>
<result name="login" type="redirect"> /index.jsp </result>
</action>
**
I don't know why my output is not showing in my jquery grid. Please help me**
I guess this is what you require :
Instead of using a sj:submit tag, use a sj:a tag with onClickTopics pointing to GridReloadTopics.
Then when sj:a is clicked, the grid get's reloaded, submitting the form to action defined in href attribute of grid.
This action must result a JSON which will populate the grid.
You haven't shown the action "getCurrentDateLogs" in the question. So this is the action that must return the json result populating the grid.
Also you must be thinking that how the grid-data gets affected by the form fields, so it's easy
The grid submits all the form fields to the action mentioned in href, so you must be having a getter & setter for every form field on that action.
Along with other normal grid attributes, now you'll receive the additional form attributes, based on the value of which you'll fill up the gridModel.
Please let me know if you still didnt' understood.
It doesn't work this way. try do the following things:
make an action retuen a page, not json
<result name="success">page_with_the_grid.jsp</result>
on the page page_with_the_grid.jsp, use s:url tag to map your json result:
<s:url var="jsonUrl" action="jsonAction"/>
in your sj:grid, use href="%{jsonUrl}" to fill your data to the grid.
if you directly call the action, which returns JSON, you will sure get a json result, which is your "Strange" output.
I have find Two grid after submit the form one is old one and second one my search grid it also include whole page
<sj:a href="%{form}" targets="result" indicator="indicator" button="true" buttonIcon="ui-icon-refresh"/>
I've a test.jsp which includes an html.using the following tag
<s:form action="showTrainingPage">
<s:include value="%{objBarcodeCertificationTaskForm.strTrainingPage}"></include>
<s:submit type="image" src="../../images/next.png"/>
</s:form>
The value is developed dynamically in action.
<action name="showTrainingPage" method="getTrainingDetails" class="certificationTask">
<result name="input" >test.jsp</result>
</action>
But this does not help. When i click on Next, it says the requested source is not available. Please let me know how can this be solved.
I'm porting the servlet/jsp Netbeans' Affableben tutorial to JSF Framework, and want to use Facelets for the view.
I already have the JPA entities, the session beans and the managed beans. I'm starting with the View. However, I have not found the equivalent in Facelets to work around this line:
<a href="<c:url value='category?${category.id}'/>">
This is the full loop, both in jsp and facelets:
JSP code:
<c:forEach var="category" items="${categories}">
<div class="categoryBox">
<a href="<c:url value='category?${category.id}'/>">
<span class="categoryLabel"></span>
<span class="categoryLabelText"><fmt:message key='${category.name}'/></span>
<img src="${initParam.categoryImagePath}${category.name}.jpg"
alt="<fmt:message key='${category.name}'/>" class="categoryImage">
</a>
</div>
</c:forEach>
Equivalent Facelets code:
<ui:repeat var="category" value="${categoryController.items}">
<div class="categoryBox">
<h:link outcome="${category.id}"/>
<span class="categoryLabel"></span>
<span class="categoryLabelText">${category.name}</span>
<img src="./resources/img/categories/${category.name}.jpg"
alt="${category.name}" class="categoryImage"/>
</div>
</ui:repeat>
This line is not working in Facelets as expected:
<h:link outcome="${category.id}"/>
What would be a working equivalent in Facelets?
EDIT 1
public String getName() throws UnsupportedEncodingException {
return URLEncoder.encode(name, "UTF-8");
}
Warning message: Unable to find resource img/categories/fruit+%26+veg.jpg
The <h:link> utilizes JSF implicit navigation and requires a real (implicit) navigation outcome value. You need to specify the view ID in the outcome. You need to specify request parameters by <f:param>. You also need to nest the spans and the image in the link as you did in your initial example. Assuming that you have a category.xhtml file in the root, this should do:
<h:link outcome="category">
<f:param name="id" value="#{category.id}" />
<span class="categoryLabel"></span>
<span class="categoryLabelText">#{category.name}</span>
<img src="./resources/img/categories/#{category.name}.jpg"
alt="#{category.name}" class="categoryImage"/>
</h:link>
Unrelated to the concrete question, you should be using <h:graphicImage> instead of <img> as well. This way JSF will ensure that the src is properly set. In your particular case that would be
<h:graphicImage name="img/categories/#{category.name}.jpg"
alt="#{category.name}" class="categoryImage"/>
(note that I replaced ${} by #{}, just to adhere the standard and for the consistency)
You can change from this line:
<a href="<c:url value='category?${category.id}'/>">
to this:
<h:link outcome="category.xhtml?id=#{category.id}" />
<h:link outcome="category">
<f:param name="id" value="#{category.id}" />
</h:link>
<h:outputLink value="category.xhtml?id=#{category.id}" ></h:outputLink>
(Sorry for the length of the post!!)
edit:
By dynamically I mean--> when the selection of a drop down changes I want the contents of other drop downs to change as well. Thanks!!
I am trying to dynamically populate dropdown menu in jsp (I guess this is a very common question). I am using struts 2 framework.
I found some solutions by googling and from some books but most of them required a lot of scripting in the jsp page, which I dont want to do, cause I think it is not a good practice.
I was hoping to find a way where I could call an action from an onChange event where all the coding part could be done (ofcourse some scripting will be used :) ) .
One way I found was by using dojo. I implemented it and its working fine except for 2 problems:
The action gets called on loading of the page itself, even when the selection of any of the drop downs has not changed.
Following error message is displayed just above the form which has the drop down menus --> "Error loading '/GetLists.htm' (500 Internal Server Error)".
One more question I want to ask is that wether this is a good way to implement dynamically populated drop downs or not. And is my notion of avoiding scripts on jsp pages right or not.
Here are the codings:
The jsp page:
<s:form id="lists" action="viewDayReport">
<s:url id="scriptURL" action="GetLists"/>
<sd:div listenTopics="getLists" href="%{scriptURL}" formId="lists" showLoadingText="Working..."/>
<s:select label="Customer " name="customer" headerKey="0" headerValue="Select" list="customerList" onchange="dojo.event.topic.publish('getLists');return false;"/>
<s:select label="Contact " name="contact" headerKey="0" headerValue="Select" list="contactList" onchange="dojo.event.topic.publish('getLists');return false;"/>
<s:select label="Employee " name="employee" headerKey="0" headerValue="Select" list="employeeList" onchange="dojo.event.topic.publish('getLists');return false;"/>
<s:select label="Stage " name="stage" headerKey="0" headerValue="Select" list="stageList" onchange="dojo.event.topic.publish('getLists');return false;"/>
<s:select label="Type " name="type" headerKey="0" headerValue="Select" list="typeList" onchange="dojo.event.topic.publish('getLists');return false;"/>
<sd:datetimepicker label="Date" name="date" displayFormat="dd/MM/yyyy" />
<s:submit value="View Report(s)"/>
</s:form>
This is the struts config file:
<struts>
<package name="Deutek.admin" extends="struts-default" >
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
//this is the action that is executed when the page first loads. It populates the lists for drop downs
<action name="dayReportPage" class="admin.dayReportAction">
<result type="tiles">dayReport</result>
</action>
//this is the action that is executed when a drop down selection is changed. currently the action just prints some output.
<action name="GetLists" class="admin.GetListsAction">
<result type="tiles">dayReport</result>
</action>
</package>
</struts>
I would suggest ether 1. populating it from your struts action class or 2. via static method invocation at the jsp level.
If you want to set the lists up in your struts action, you can do it by implementing Preparable in the action:
public MyAction extends ActionSupport implements Preparable{
private List customerList;
public void prepare(){
customerList= CustomersDAO.getCustomerList();
}
// Getters and Setters
}
You can then get the list from the jsp like this:
<s:select label="Customer " name="customer" headerKey="0" headerValue="Select"
List="customerList"/>
To set up dynamic method invocation you can access the CustomersDAO object from the previous example directly something like this:
<s:select label="Customer " name="customer" headerKey="0" headerValue="Select"
List="#com.mypackage.CustomersDAO#getCustomerList()"/>
To enable static method access set the struts2 constant in the struts.properties file:
struts.ognl.allowStaticMethodAccess=true
All you need is a doubleselect tag.
Here's a good example.