I need to show two dropdown for Class-Section.
Description:
first select is appearing but second select is not showing the value in the dropdown.
My double select looks like:
<s:doubleselect label="Standard"
name="standard"
listValue="standard"
list="#session.standardList"
doubleList="#session.standardList.section"
doubleName="section"
doubleListValue="section"></s:doubleselect>
Standard class looks like:
public class Standard {
String standard;
ArrayList<String> section;
// getters and setters below
}
Exception:
freemarker.core.InvalidReferenceException: Expression parameters.formName is undefined on line 150, column 43 in template/simple/doubleselect.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
at freemarker.core.Expression.getStringValue(Expression.java:118)
I found the root cause of the issue, As the exception says formName was not found, i encapsulated double-select tag inside the form tag and all start working fine.
Now form tag looks like:
<s:form name="studentsubmit" action="add/submitstudent">
<s:doubleselect label="Standard" name="standard" listValue="standard"
listKey="standard" list="#session.standardList" doubleList="section"
doubleName="section" ></s:doubleselect>
</s:form>
Related
The main problem is that I use Struts 1.0.2. But I can't change it.
I have an issue using an attribute of an arraylist in my jsp. The display works fine but I don't get the data instanciated in the arraylist in my form. In debug mode I see that it never comes to the getter of my property. I've found 2 solutions in struts 1.0 but I can't make it works.
The arraylist in my ActionForm :
private ArrayList<AccountScreenBean> accountsScreen = new ArrayList<AccountScreenBean>();
The class declaration of the Account object in the Arraylist :
public class Account implements Serializable, Cloneable {
private String bic;
public String getBic() {
return bic;
}
public void setBic(final String newBic) {
bic = newBic;
}
}
The call in my jsp :
<logic:iterate name="BankAccountsActionForm" property="accountsScreen" id="accScreen" indexId="index">
<html:text name="accScreen" property="<%="accountsScreen["+index+"].bic"%>" size="18" maxlength="11" onkeyup="suivant(this,'partPays',11,'accScreen')"
styleClass="inscCB_SaisieTexte" />
</logic:iterate>
The console error :
weblogic.servlet.jsp.CompilationException: Failed to compile JSP
/jsp/Contents/bankAccountsContent.jsp bankAccountsContent.jsp:171:81:
This attribute is not recognized.
" size="18"
maxlength="11".
with accountsScreen underlined
I've also tried another way in my jsp :
<html:text name="accScreen" property="accountsScreen[${index}].bic" size="18" maxlength="11"
onkeyup="suivant(this,'partPays',11,'accScreen')"
styleClass="inscCB_SaisieTexte" />
This time the console error was :
java.lang.IllegalArgumentException: Invalid indexed property
'accountsScreen[${index}]'
Do you have a solution to one of these problems or another way to do this?
Aleksandr M help me to find the lead to the final solution. Indeed I needed to use simple quotes instead of double ones. Then there was an access problem to the accountsScreen property because it wasn't and indexed one. Finally I needed 2 different names for getter, even if the arguments wasn't the same. So I add the indexed prefix to the indexed getter.
In the jsp :
<html:text name="BankAccountsActionForm" property='<%="indexedAccountsScreen["+index+ "].partAccountNumber2"%>'
in the java form, I needed an indexed property to access to an element of accountsScreen ArrayList. So I had the getter to access to an element by Index :
public void setAccountsScreen(int index, AccountScreenBean accScreen) {
this.accountsScreen.add(index, accScreen);
}
public AccountScreenBean getIndexedAccountsScreen(int index) {
return accountsScreen.get(index);
}
Thanks every one.
I think the problem with your first "workaround" is the <% %> magic, because of the quotes. And it also seems unnecessary, as you should already have the indexed element in accScreen.
I would try
<logic:iterate name="BankAccountsActionForm" property="accountsScreen" id="accScreen" indexId="index">
<html:text name="accScreen" property="bic" etc="..." />
</logic:iterate>
instead.
I want to hide a table on load of a page and hide it on click of a button on that page.I have created a property of type String in Action class named as "displayTablle" and assigned it a value "none" by default.So that when this page is opened by calling action,this property will be none and following code used in table tag should hide the table:
<table border="true" id="dataTable" style="display:"<s:hidden id="disTable" name = "displayTable" value="%{displayTable}"/>;">
<s:submit value="Fetch Data" align="center" action="displayDataAction" />
Then on click of Fetch Data button, I am setting value of this property to blank string i.e " ", so that table will be displayed, But I am stuck with the syntax and <s:hidden> is not getting bound properly, as when I open the page, last part of the table tag's code i.e ;"> is getting printed as is.
Can anybody suggest, what should be the right syntax to bind s:hidden in html table tag? Can we do it like this?
The property tag is used to write text to the JSP page. It has also option for unescaping that text, but it's not required in your case.
<table border="true" id="dataTable" style="display:<s:property value='%{displayTable}'/>;">
Hello dear folks of stack overflow.
I encountered a problem recently in my Struts application.
I have a jsp which displays some bean value correctly (i paste only relevant part of the code, i simplified to the extreme):
<table>
<logic:iterate name="bean" property="list1" id="listItem">
<tr>
<td>
<html:checkbox name="listItem" property="selected">
</html:checkbox>
</td>
</logic:iterate>
</table>
My bean has a list1 property with its getter and setter
private List<RandomObject> list1;
public List getList1() {
return list1;
}
public void setList1(List list1) {
this.list1=list1;
}
and my sub-bean has a selected property:
private boolean selected;
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
Now, when enter this jsp, the values i get are correct, ie: if my mapped object in DB was at selected=true, the checkbox is checked. What i dont get is how do i save the changes i make in this form. When i submit, all the changes are lost. This is pure struts related, because in debug when i enter the StrutsAction linked to submit, the ActionForm i get has already lost all interesting values. Also i feel like it has to do with the fact that the value i want to retain isn't directly stored on the main bean, but rather is a property of a sub-bean, because on the same page there are a lot of other properties directly on the main bean that i have no trouble saving.
What did i miss ?
It's probably declaring incorrect name attributes in the rendered HTML. If you look at the generated source code for your page it probably looks like this:
<input type="checkbox" name="selected" ...>
which would look for a selected field in your form bean class.
If you're using a collection that's a field in your form bean you want to be using the <nested:form>, <nested:iterate> and <nested:checkbox Struts tags, not the <html:form>,and` ones. So it would then look like this:
<nested:form action="foo">
...
<nested:iterate property="list1" id="listItem">
<tr>
<td>
<nested:checkbox property="selected">
</nested:checkbox>
</td>
</tr>
</nested:iterate>
...
</nested:form>
Note that I've removed the name attributes from the Struts tags, because they're not needed (in my experience they actually cause all kinds of problems - if you use <nested:*> tags don't use a name attribute). In the case of the <nested:iterate> the level of nesting is the form bean itself, so it knows that it needs to look for the list1 property in the form bean.
That tag creates its own nesting level, so the <nested:checkbox knows that it needs to look for the selected property of the current element in the iteration.
The rendered HTML will look something like this (for the first element):
<input type="checkbox" name="list1[0].selected" ...>
which means the selected field of the first element (index 0) in the collection referenced by the list1 field of your form bean.
And, of course, you'll need to make sure that you're using a session-scoped form bean, rather than a request-scoped one.
in my case i had to put the name attribute into the iterate otherwise it gives me error(cannot find property into any bean...)
I resolved deleting the attribute name into the checkbox: it seems it create a new object at page scope that is not connected with the form.
This is my code:
<nested:iterate id="apertura" type="it.puglia.innova.view.actionform.AperturaForm" indexId="index" name="strutturaRuraleForm" property="listAperturaForm">
<nested:checkbox styleId="checkbox_${index}" property="flagContinuato" onchange="changeOrarioContinuato(${index})"/>
that's it :-) didn't need to change html:form to nested too.
Bye
I am new to struts2 and looking at the existing code and elsewhere in the net, I thought my below code should work. I am trying to select some user ids in s:select box in JSP and I want to use these ids in my action class. I am using modelDriven for it and users are in a list
JSP code snippet
<s:select id="selectedAgents"
name="selectedUserList"
multiple="true"
list="selectedUserList"
/>
the selected user ids in the page comes to this box. and when the form is submitted, I expect to see the selectUserList in action.
In the action I have
public class WorkLoadReportAction extends GenericAction implements ModelDriven<WorkloadReportDTO>
...
private WorkloadReportDTO userReportInputData = new WorkloadReportDTO();
...
#Override
public WorkloadReportDTO getModel() {
return userReportInputData;
}
the WorkloadReportDTO has List<String> selectedUserList and its getter and setter.
Now in the method of the action(called from submit), I dont see the selectedUserList populated.
What am I missing?
In your Jsp :
<s:select id="selectedAgents"
name="selectedUserList"
multiple="true"
list="selectedUserList"
/>
You have name attribute value and list attribute value as same . Try changing the value of either name attribute or list attribute .
Hope this Solves your problem
I have this value ${agact.ppr} that i want to show in my page jsp. It can be shown like this easly:
<c:out value="${agact.ppr}" />
but I want to use it into input form like this:
<form:input type="text" value="${agact.ppr}" path="ppr" />
but it's not working I don't know why. I displayed others attributes in input fields without problem and this one no.
My class is like this :
Class Agent{
int ppr;
/** setters and getters**/
}
Try removing the 'value' attribute, 'path' should be all you need there. Also make sure the getter and setter are valid.