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"/>
Related
In the below code, I am trying to pass 2 parameters from <display:column> tag. I have to pass code and level properties to an action(as shown below). I am not able to pass value of another column as parameter from a column. Here I am not getting value of level property in code property.
<s:form action="levelHierarchy">
<display:table id="searchList" name="searchList" pagesize="8"
export="false" requestURI="/getComponentDetails" sort="list">
<display:column property="code" title="Code" sortable="true" paramId="levelId" href="levelHierarchy.action?level=${searchList.level}"></display:column>
<display:column property="description" title="Description" sortable="true" />
<display:column property="level" title="Level" sortable="true" />
<display:setProperty name="paging.banner.placement" value="bottom" />
</display:table>
</s:form>
Inside the form you don't have any fields to submit. You should define at least hidden fields to the columns that contains the values you want to pass to the action. You also need the use of uid attribute of the <display:table tag to access the row values.
<display:table uid="row" id="searchList" name="searchList" pagesize="8" export="false" requestURI="/getComponentDetails" sort="list" >
<display:column property="code" title="Code" sortable="true" paramId="levelId" href="levelHierarchy.action?level=${searchList.level}">
<s:hidden name="submitList[%{#attr.row_rowNum - 1}]" value="%{#attr.row.code}"/>
</display:column>
<%-- Other columns like that --%>
</display:table>
in the action you should create the property placeholder for the submitted values.
i have a jsp page where i am displaying my books detail in Struts2 jquery grid.
Now i want to call an action and pass rowid as a parameter to the the action class on the click of a row from my Jquery grid. And i also i want to specify the target of my div to refresh after calling my action.
These stuffs i know nicely through <sj:submit target="targetDivToRefresh" formId="form2" button="true"/> but i don't know how to do these task "when users click a row from my struts2 jquery grid".
Please help me to solve this issue.
my jsp page
<sjg:grid
id="bookgrid"
editurl="%{bookediturl}"
navigator="true"
editinline="true"
navigatorSearch="false"
autowidth="false"
width= "1550"
viewrecords="true"
navigatorRefresh="true"
navigatorDelete="true">
<sjg:gridColumn name="id" index="locationId" title="ID" formatter="integer" sortable="false" key="true"
search="false" editable="true" hidden="true" />
<sjg:gridColumn name="authLastname" index="authLastname" title="AuthorLastname" sortable="true" search="true" editrules="{required: true}"
editable="true" edittype="text" />
</sjg:grid>
try this:
$(function(){
$.subscribe('rowselect', function(event,data) {
alert(event.originalEvent.authLastname);
$("#targetDivToRefresh").load('your-struts2-action');
});
});
UPDATE
$("#targetDivToRefresh").load('your-struts2-action');
Reference Link: Struts2 jquery plugin showcase
Please make sure this event will be triggered, if you click on a row, i added test code alert() to make sure, it has been called during the event. there is still a thing, that i have to tell, you have to register your selectrow event in your <sj:grid> tag using onSelectRowTopics="rowselect"
UPDATE
$("#targetDivToRefresh").load("<s:url value="your-struts2-action"/>"+"?id="+event.originalEvent.id);
I have two forms in my page, in the first formulary are input fields with validation, and in the other a dataTable. The first formulary has a message area to show validation errors, and the second formulary has a message area to show problems with the retrieval of the data (this message area is updated from myController.search).:
<h:form id="form1">
<p:message id="messageForm1" for=":form1" />
<p:inputText id="text1" value="#{myBean.data}" required="true" />
....
<p:commandButton value="Search" actionListener"#{myController.search}"
update=":form2:dataTable :form2:messageForm2 :form1:messageForm1" process="text1, ..." />
</h:form>
<h:form id="form2">
<p:message id="messageForm2" for="messageForm2" />
<p:dataTable>
...
</p:dataTable>
</h:form>
The problem is that the messages in the form2 are working, but the validation messages in form1 are never shown
The description of the for attribute of the p:message tag says:
Id of the component whose messages to display.
So you can't specify the ID of the form. You have to specify the ID of a single form component. e.g. <p:message id="messageForm1" for="text1" />. But then you have to create one message element for every form component.
An alternative would be to use the p:messages tag. For examples see here: http://www.primefaces.org/showcase-labs/ui/messages.jsf
We are using Primefaces datatable component with sorting, pagination and a LazyDataModel in order to display search results. The backing bean of the search page is ViewScoped.
From the search result list a user can select a result item in order to view the details. This is implemented as a new page request, e.g. <h:link value="Show Details" outcome="showDetails?id=11234"/>. By clicking the browser back button the user will navigate back to the search result list.
The problem is that the datatable will be in initial state again, so it wont display the last selected sort order and page. This is the case in most browsers, only Firefox 11 seems to keep those DOM changes in cache. Neither IE nor Chrome.
Does anybody has a good approach how to handle this? We actually don't need "ajaxified" sorting and paging. We would prefer handling everything through ViewParams, but this seems not to be supported by primefaces.
I ran into this as well, and I developed a coding pattern that might help. It isn't really a PrimeFaces thing (which I am using as well) -- more of a technique for using book-markable links with JSF 2.
In the markup, I include all the parameters for the page as follows:
<f:metadata>
<f:viewParam name="orderID" value="#{bean.orderID}" />
<f:viewParam name="sortMode" value="#{bean.sortMode}" />
<f:viewParam name="firstRecord" value="#{bean.firstRecord}" />
<f:viewParam name="pageSize" value="#{bean.pageSize}" />
</f:metadata>
Each of those values is backed in the backing bean such that, if they are not set, they produce a suitable default value. For example:
public int getPageSize() {
if (pageSize < MIN_PAGE_SIZE) pageSize = DEF_PAGE_SIZE;
if (pageSize > MAX_PAGE_SIZE) pageSize = DEF_PAGE_SIZE;
return pageSize;
}
A link to this view can be generated as follows:
Now you implement user controls to change those values, and regenerate the table each time they are changed. You should still use AJAX for that -- for example:
<p:spinner value=#{bean.pageSize} >
<p:ajax update="tableID" />
</p:spinner>
In the setter methods, you have to trigger the re-generation of the table, but that's the gist of it. I hope this helps.
UPDATE:
To handle pagination, you simply need to add links for first page, prior page, next page, etc. The links will look something like this:
<h:link value="First Page" outcome="thisPage">
<f:param name="orderID" value="#{bean.orderID}" />
<f:param name="sortMode" value="#{bean.sortMode}" />
<f:param name="firstRecord" value="0" />
<f:param name="pageSize" value="#{bean.pageSize}" />
</h:link>
<h:link value="Next Page" outcome="thisPage">
<f:param name="orderID" value="#{bean.orderID}" />
<f:param name="sortMode" value="#{bean.sortMode}" />
<f:param name="firstRecord" value="#{bean.nextRecord}" />
<f:param name="pageSize" value="#{bean.pageSize}" />
</h:link>
etc. You need to implement properties in the backing bean to calculate what the firstRecord param ought to be.
I am developing one JSF page, in that i am having two forms. And I am using rich:messages in both the forms.
Suppose, in the first form, if I don't enter any required fields and I click Save, then error messages are displaying twice in the page(as i am using rich:messages in two forms).
Is there any way so that error messages display with respect to the form?
Thanks in advance.
If you are using RichFaces 3.3.3.Final you can do it like so:
<a4j:form id="tmpfrm1">
<rich:messages />
<h:inputText value="#{mybean.intmp1}" required="true"/>
<a4j:commandButton value="save" action="#{mybean.test1}" reRender="tmpfrm1" limitToList="true" />
</a4j:form>
<a4j:form id="tmpfrm2">
<rich:messages />
<h:inputText value="#{mybean.intmp2}" required="true"/>
<a4j:commandButton value="save" action="#{mybean.test2}" reRender="tmpfrm2" limitToList="true" />
</a4j:form>
If you are uisng RichFaces 4 you need to replace the limitToList with limitRender and the reRender with render