Radio Button issue while Iterating over a collection in Struts 2 - struts2

I have a list name companyList iterating to show list of user in table.Every row has company name and a radio button to select company id .
Here Problem is how I can bind a radio button for a row with respective company id show that user can choose only one company id from table as I do have list value to bind with radio.
=Company Name=|=Company ID====
ABC | radio with company ID 1
XYZ | radio with company ID 2
<display:table uid="companyConfig" name="dataExchangeCompanyList" htmlId="companyListTable" requestURI="ncrDatapackageExport!ajax" ajax="true">
<!-- Company Name -->
<display:column titleKey="tdp.export.company.name" class="company-column textLeft" sortable="true" sortProperty="company">
<s:property value="#attr.companyConfig.company"/>
</display:column>
<!-- Check Box -->
<display:column titleKey="tdp.export.select" class="textCentre" media="html">
<s:radio name="selectedCompanies" value="%{#attr.companyConfig.id}" />
</display:column>
</display:table>
Here I am using display table to iterate over list

Bind the control by name. You should specify the index for the property where selected values would be stored when you submit the form.
<display:column titleKey="tdp.export.select" class="textCentre" media="html">
<s:radio name="selectedCompanies[%{#attr.companyConfig_rowNum - 1}]" value="%{#attr.companyConfig.id}" />
</display:column>

Related

How to pass a value of a column as a parameter from another column in displaytag using struts2

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.

dynamic data reload to struts2 jquery grid on form submit

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"/>

show enum as radio button in gsp

In my domain class, i have one enum:-
class Product{
Type type
enum Type{
MEDICINE, NON_MEDICINE
}
}
By generating default view, this shows as a dropdown in create.gsp page. My requirement is to show it as a radio group in create page from where i can select any one of the two values by clicking on radio button. can anyone provide some help. thnks
This should work:
<g:radioGroup name="type"
values="${test.Product$Type?.values()}"
labels="${test.Product$Type.values()*.name()}"
value="${productInstance?.type?.name()}">
${it.radio} <g:message code="${it.label}" />
</g:radioGroup>
That should replace the current g:select in grails-app/views/product/_form.gsp
Try
<g:radioGroup name="type" values="${['MEDICINE', 'NON_MEDICINE']}" value="${currentInstance.type}" labels="${['Medicine', 'Non medicine']}">
<span>${it.label} - ${it.radio}</span>
</g:radioGroup>

List Box Multiple Selected values

how to pass multiple selected list box values which are in a session in one ascx page to another ascx page
Code is
NameObjectCollection eeSearchString=new NameObjectCollection();
for(i = 0;i <= LbStatus.Items.Count - 1){
if LbStatus.Items(i).Selected {
eeSearchString.Add(new NameObjectPair("status", LbStatus.SelectedItem(i).Text));
}
}
And in another page can i access the status like this?
_status=Convert.ToString(eeSearchString.ItemValue("status"));
Pls let me know?? or do i need to use loop again???
I don't know about aspx but in HTMl you can declare an array for some elements.
For example:
Group XPTO
In the server, in my case, in PHP I only receive the Value of the ones that are selected inside the array.
Image you have this:
<input type="checkbox" name="group[]" value="1" /> Group 1 <br />
<input type="checkbox" name="group[]" value="2" /> Group 2 <br />
<input type="checkbox" name="group[]" value="3" /> Group 3 <br />
Imagine you've selected the Group 1 and 3. In the server you'll receive the array with the values of the group1 and 3.
group(1, 3);
Hope this helps with you're question =)
Regards,
Elkas
make use of session variable or make use of properties of the control, i.e create property and assign value.

How to make items (columns) in <apex:pageBlockTable> hyperlink?

I successfully created tables with style that salesforce provided. (like the one that highlighted on mouseover etc)
But I want the value of column to be a link to display detail info of the object.
When I don't create my own visualforce page, the table looks nice and the column
values (records) are all hyperlinked but can't figure out how to do it from visualforce apex code.
pageBlockTable and column definition does not seem to have attributes or anything that
make it hyperlink.
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_pageBlockTable.htm
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_column.htm
<apex:pageBlock title="test">
<apex:pageBlockTable value="{!workObj}" var="item">
<!-- below needs to be hyperlink -->
<apex:column value="{!item.name}" />
</apex:pageBlockTable>
</apex:pageBlock>
I could achieve my goal by throwing the good design away like below but I would like to keep the code above.
This works but no salesforce style is applied.
<apex:pageBlock title="my test title" >
<apex:dataTable value="{!workObj}" var="wn" cellpadding="2" cellspacing="2">
<apex:column>
<apex:facet name="header">仕事名一覧</apex:facet>
<apex:form >
<apex:commandLink value="{!wn.name}" />
</apex:form>
</apex:column>
</apex:dataTable>
</apex:pageBlock>
Instead of <apex:column value="{!item.name}" />, try doing it like this in the column body:
<apex:pageBlock title="test">
<apex:pageBlockTable value="{!workObj}" var="item">
<apex:column>
<apex:outputLink value="{!item.name}">{!item.name}</apex:outputLink>
</apex:column>
<apex:pageBlock title="test">
<apex:pageBlockTable value="{!workObj}" var="item">

Resources